• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEST_SUPPORT_TYPE_ALGORITHMS_H
10 #define TEST_SUPPORT_TYPE_ALGORITHMS_H
11 
12 #include <type_traits>
13 
14 #include "test_macros.h"
15 
16 namespace types {
17 template <class... Types>
18 struct type_list {};
19 
20 // concatenates N type_lists to one (for N >= 1)
21 template <class...>
22 struct concatenate;
23 
24 template <class... Types>
25 using concatenate_t = typename concatenate<Types...>::type;
26 
27 // for_each takes a type_list calls f with each element as the first template argument
28 template <class... Types, class Functor>
29 TEST_CONSTEXPR_CXX14 void for_each(type_list<Types...>, Functor f);
30 
31 // impl
32 template <class... Types>
33 struct concatenate<type_list<Types...> > {
34   using type = type_list<Types...>;
35 };
36 
37 template <class... Types1, class... Types2>
38 struct concatenate<type_list<Types1...>, type_list<Types2...> > {
39   using type = type_list<Types1..., Types2...>;
40 };
41 
42 template <class... Types1, class... Types2, class... Rest>
43 struct concatenate<type_list<Types1...>, type_list<Types2...>, Rest...> {
44   using type = concatenate_t<type_list<Types1..., Types2...>, Rest...>;
45 };
46 
47 template <class... Types>
48 TEST_CONSTEXPR_CXX14 void swallow(Types...) {}
49 
50 template <class... Types, class Functor>
51 TEST_CONSTEXPR_CXX14 void for_each(type_list<Types...>, Functor f) {
52   swallow((f.template operator()<Types>(), 0)...);
53 }
54 
55 // type categories defined in [basic.fundamental] plus extensions (without CV-qualifiers)
56 
57 using character_types =
58     type_list<char
59 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
60               ,
61               wchar_t
62 #endif
63 #ifndef TEST_HAS_NO_CHAR8_T
64               ,
65               char8_t
66 #endif
67 #if TEST_STD_VER >= 11
68               ,
69               char16_t,
70               char32_t
71 #endif
72               >;
73 
74 using signed_integer_types =
75     type_list<signed char,
76               short,
77               int,
78               long,
79               long long
80 #ifndef TEST_HAS_NO_INT128
81               ,
82               __int128_t
83 #endif
84               >;
85 
86 using unsigned_integer_types =
87     type_list<unsigned char,
88               unsigned short,
89               unsigned int,
90               unsigned long,
91               unsigned long long
92 #ifndef TEST_HAS_NO_INT128
93               ,
94               __uint128_t
95 #endif
96               >;
97 
98 using integral_types = concatenate_t<character_types, signed_integer_types, unsigned_integer_types, type_list<bool> >;
99 
100 using floating_point_types = type_list<float, double, long double>;
101 
102 using arithmetic_types = concatenate_t<integral_types, floating_point_types>;
103 
104 template <class T>
105 using cv_qualified_versions = type_list<T, const T, volatile T, const volatile T>;
106 
107 template <class T>
108 struct type_list_as_pointers;
109 
110 template <class... Types>
111 struct type_list_as_pointers<type_list<Types...> > {
112   using type = type_list<Types*...>;
113 };
114 
115 template <class T>
116 using as_pointers = typename type_list_as_pointers<T>::type;
117 } // namespace types
118 
119 #endif // TEST_SUPPORT_TYPE_ALGORITHMS_H
120