2 // typelist for the C++ library testsuite.
4 // Copyright (C) 2005-2020 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
22 #ifndef _TESTSUITE_COMMON_TYPES_H
23 #define _TESTSUITE_COMMON_TYPES_H 1
25 #include <ext/typelist.h>
27 #include <ext/new_allocator.h>
28 #include <ext/malloc_allocator.h>
29 #include <ext/mt_allocator.h>
30 #include <ext/bitmap_allocator.h>
31 #include <ext/pool_allocator.h>
43 #include <tr1/functional>
44 #include <tr1/unordered_map>
45 #include <tr1/unordered_set>
47 #if __cplusplus >= 201103L
49 #include <type_traits>
54 using __gnu_cxx::typelist::null_type
;
55 using __gnu_cxx::typelist::node
;
56 using __gnu_cxx::typelist::transform
;
57 using __gnu_cxx::typelist::append
;
59 // All the allocators to test.
60 template<typename Tp
, bool Thread
>
61 struct allocator_policies
63 typedef Tp value_type
;
64 typedef __gnu_cxx::new_allocator
<Tp
> a1
;
65 typedef __gnu_cxx::malloc_allocator
<Tp
> a2
;
66 typedef __gnu_cxx::__common_pool_policy
<__gnu_cxx::__pool
, Thread
> pool_policy
;
67 typedef __gnu_cxx::__mt_alloc
<Tp
, pool_policy
> a3
;
68 typedef __gnu_cxx::bitmap_allocator
<Tp
> a4
;
69 typedef __gnu_cxx::__pool_alloc
<Tp
> a5
;
70 typedef node
<_GLIBCXX_TYPELIST_CHAIN5(a1
, a2
, a3
, a4
, a5
)> type
;
73 // Typelists for vector, string, list, deque.
74 // XXX should just use template templates
75 template<typename Tp
, bool Thread
>
78 typedef Tp value_type
;
83 typedef Tl allocator_type
;
84 typedef std::vector
<value_type
, allocator_type
> type
;
87 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
88 typedef typename
allocator_types::type allocator_typelist
;
89 typedef typename transform
<allocator_typelist
, vector_shell
>::type type
;
92 template<typename Tp
, bool Thread
>
95 typedef Tp value_type
;
100 typedef Tl allocator_type
;
101 typedef std::list
<value_type
, allocator_type
> type
;
104 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
105 typedef typename
allocator_types::type allocator_typelist
;
106 typedef typename transform
<allocator_typelist
, list_shell
>::type type
;
109 template<typename Tp
, bool Thread
>
112 typedef Tp value_type
;
114 template<typename Tl
>
117 typedef Tl allocator_type
;
118 typedef std::deque
<value_type
, allocator_type
> type
;
121 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
122 typedef typename
allocator_types::type allocator_typelist
;
123 typedef typename transform
<allocator_typelist
, deque_shell
>::type type
;
126 template<typename Tp
, bool Thread
>
129 typedef Tp value_type
;
131 template<typename Tl
>
134 typedef Tl allocator_type
;
135 typedef std::char_traits
<value_type
> traits_type
;
136 typedef std::basic_string
<value_type
, traits_type
, allocator_type
> type
;
139 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
140 typedef typename
allocator_types::type allocator_typelist
;
141 typedef typename transform
<allocator_typelist
, string_shell
>::type type
;
144 // A typelist of vector, list, deque, and string all instantiated
145 // with each of the allocator policies.
146 template<typename Tp
, bool Thread
>
147 struct sequence_containers
149 typedef Tp value_type
;
151 typedef typename vectors
<value_type
, Thread
>::type vector_typelist
;
152 typedef typename lists
<value_type
, Thread
>::type list_typelist
;
153 typedef typename deques
<value_type
, Thread
>::type deque_typelist
;
154 typedef typename strings
<value_type
, Thread
>::type string_typelist
;
156 typedef typename append
<vector_typelist
, list_typelist
>::type a1
;
157 typedef typename append
<deque_typelist
, string_typelist
>::type a2
;
158 typedef typename append
<a1
, a2
>::type type
;
161 // Typelists for map, set, unordered_set, unordered_map.
162 template<typename Tp
, bool Thread
>
165 typedef Tp value_type
;
167 typedef std::pair
<const key_type
, value_type
> pair_type
;
168 typedef std::less
<key_type
> compare_function
;
170 template<typename Tl
>
173 typedef Tl allocator_type
;
174 typedef std::map
<key_type
, value_type
, compare_function
, allocator_type
> type
;
177 typedef allocator_policies
<pair_type
, Thread
> allocator_types
;
178 typedef typename
allocator_types::type allocator_typelist
;
179 typedef typename transform
<allocator_typelist
, container
>::type type
;
182 template<typename Tp
, bool Thread
>
183 struct unordered_maps
185 typedef Tp value_type
;
187 typedef std::pair
<const key_type
, value_type
> pair_type
;
188 typedef std::tr1::hash
<key_type
> hash_function
;
189 typedef std::equal_to
<key_type
> equality_function
;
191 template<typename Tl
>
194 typedef Tl allocator_type
;
195 typedef std::tr1::unordered_map
<key_type
, value_type
, hash_function
, equality_function
, allocator_type
> type
;
198 typedef allocator_policies
<pair_type
, Thread
> allocator_types
;
199 typedef typename
allocator_types::type allocator_typelist
;
200 typedef typename transform
<allocator_typelist
, container
>::type type
;
203 template<typename Tp
, bool Thread
>
206 typedef Tp value_type
;
208 typedef std::less
<key_type
> compare_function
;
210 template<typename Tl
>
213 typedef Tl allocator_type
;
214 typedef std::set
<key_type
, compare_function
, allocator_type
> type
;
217 typedef allocator_policies
<key_type
, Thread
> allocator_types
;
218 typedef typename
allocator_types::type allocator_typelist
;
219 typedef typename transform
<allocator_typelist
, container
>::type type
;
222 template<typename Tp
, bool Thread
>
223 struct unordered_sets
225 typedef Tp value_type
;
227 typedef std::tr1::hash
<key_type
> hash_function
;
228 typedef std::equal_to
<key_type
> equality_function
;
230 template<typename Tl
>
233 typedef Tl allocator_type
;
234 typedef std::tr1::unordered_set
<key_type
, hash_function
, equality_function
, allocator_type
> type
;
237 typedef allocator_policies
<key_type
, Thread
> allocator_types
;
238 typedef typename
allocator_types::type allocator_typelist
;
239 typedef typename transform
<allocator_typelist
, container
>::type type
;
243 // A typelist of all associated container types, with each of the
244 // allocator policies.
245 template<typename Tp
, bool Thread
>
246 struct associative_containers
248 typedef Tp value_type
;
250 typedef typename maps
<value_type
, Thread
>::type map_typelist
;
251 typedef typename sets
<value_type
, Thread
>::type set_typelist
;
252 typedef typename unordered_maps
<value_type
, Thread
>::type unordered_map_typelist
;
253 typedef typename unordered_sets
<value_type
, Thread
>::type unordered_set_typelist
;
255 typedef typename append
<map_typelist
, unordered_map_typelist
>::type a1
;
256 typedef typename append
<set_typelist
, unordered_set_typelist
>::type a2
;
257 typedef typename append
<a1
, a2
>::type type
;
260 // A typelist of all standard integral types.
261 struct integral_types
265 typedef signed char a3
;
266 typedef unsigned char a4
;
268 typedef unsigned short a6
;
270 typedef unsigned int a8
;
272 typedef unsigned long a10
;
273 typedef long long a11
;
274 typedef unsigned long long a12
;
276 typedef node
<_GLIBCXX_TYPELIST_CHAIN13(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
277 a10
, a11
, a12
, a13
)> basic_typelist
;
278 #if __cplusplus >= 201103L
279 typedef char16_t a14
;
280 typedef char32_t a15
;
281 typedef node
<_GLIBCXX_TYPELIST_CHAIN2(a14
, a15
)> cxx11_typelist
;
283 typedef node
<null_type
> cxx11_typelist
;
285 #ifdef _GLIBCXX_USE_CHAR8_T
287 typedef node
<_GLIBCXX_TYPELIST_CHAIN1(a16
)> char8_typelist
;
289 typedef node
<null_type
> char8_typelist
;
291 typedef typename append
<basic_typelist
, cxx11_typelist
>::type tl1
;
292 typedef typename append
<tl1
, char8_typelist
>::type type
;
295 // A typelist of all standard integral types + the GNU 128-bit types.
296 struct integral_types_gnu
300 typedef signed char a3
;
301 typedef unsigned char a4
;
303 typedef unsigned short a6
;
305 typedef unsigned int a8
;
307 typedef unsigned long a10
;
308 typedef long long a11
;
309 typedef unsigned long long a12
;
311 typedef node
<_GLIBCXX_TYPELIST_CHAIN13(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
312 a10
, a11
, a12
, a13
)> basic_typelist
;
313 #if __cplusplus >= 201103L
314 typedef char16_t a14
;
315 typedef char32_t a15
;
316 typedef node
<_GLIBCXX_TYPELIST_CHAIN2(a14
, a15
)> cxx11_typelist
;
318 typedef node
<null_type
> cxx11_typelist
;
320 #ifdef _GLIBCXX_USE_CHAR8_T
322 typedef node
<_GLIBCXX_TYPELIST_CHAIN1(a16
)> char8_typelist
;
324 typedef node
<null_type
> char8_typelist
;
326 # if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
327 __extension__
typedef __int128 a17
;
328 __extension__
typedef unsigned __int128 a18
;
329 typedef node
<_GLIBCXX_TYPELIST_CHAIN2(a17
, a18
)> int128_typelist
;
331 typedef node
<null_type
> int128_typelist
;
333 typedef typename append
<basic_typelist
, cxx11_typelist
>::type tl1
;
334 typedef typename append
<tl1
, char8_typelist
>::type tl2
;
335 typedef typename append
<tl2
, int128_typelist
>::type type
;
338 #if __cplusplus >= 201103L
339 struct atomic_integrals_no_bool
341 typedef std::atomic_char a2
;
342 typedef std::atomic_schar a3
;
343 typedef std::atomic_uchar a4
;
344 typedef std::atomic_short a5
;
345 typedef std::atomic_ushort a6
;
346 typedef std::atomic_int a7
;
347 typedef std::atomic_uint a8
;
348 typedef std::atomic_long a9
;
349 typedef std::atomic_ulong a10
;
350 typedef std::atomic_llong a11
;
351 typedef std::atomic_ullong a12
;
352 typedef std::atomic_wchar_t a13
;
353 typedef std::atomic_char16_t a14
;
354 typedef std::atomic_char32_t a15
;
355 typedef node
<_GLIBCXX_TYPELIST_CHAIN14(a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
,
356 a11
, a12
, a13
, a14
, a15
)> basic_typelist
;
357 #ifdef _GLIBCXX_USE_CHAR8_T
358 typedef std::atomic_char8_t a16
;
359 typedef node
<_GLIBCXX_TYPELIST_CHAIN1(a16
)> char8_typelist
;
361 typedef node
<null_type
> char8_typelist
;
363 typedef typename append
<basic_typelist
, char8_typelist
>::type type
;
366 struct atomic_integrals
368 typedef std::atomic_bool a1
;
369 typedef std::atomic_char a2
;
370 typedef std::atomic_schar a3
;
371 typedef std::atomic_uchar a4
;
372 typedef std::atomic_short a5
;
373 typedef std::atomic_ushort a6
;
374 typedef std::atomic_int a7
;
375 typedef std::atomic_uint a8
;
376 typedef std::atomic_long a9
;
377 typedef std::atomic_ulong a10
;
378 typedef std::atomic_llong a11
;
379 typedef std::atomic_ullong a12
;
380 typedef std::atomic_wchar_t a13
;
381 typedef std::atomic_char16_t a14
;
382 typedef std::atomic_char32_t a15
;
383 typedef node
<_GLIBCXX_TYPELIST_CHAIN15(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
384 a10
, a11
, a12
, a13
, a14
, a15
)> basic_typelist
;
385 #ifdef _GLIBCXX_USE_CHAR8_T
386 typedef std::atomic_char8_t a16
;
387 typedef node
<_GLIBCXX_TYPELIST_CHAIN1(a16
)> char8_typelist
;
389 typedef node
<null_type
> char8_typelist
;
391 typedef typename append
<basic_typelist
, char8_typelist
>::type type
;
395 template<typename Tp
>
398 typedef Tp value_type
;
399 typedef std::atomic
<value_type
> type
;
402 typedef transform
<integral_types::type
, atomics
>::type atomics_tl
;
405 template<typename Tp
>
406 struct numeric_limits
408 typedef Tp value_type
;
409 typedef std::numeric_limits
<value_type
> type
;
412 typedef transform
<integral_types_gnu::type
, numeric_limits
>::type limits_tl
;
414 struct has_increment_operators
416 template<typename _Tp
>
431 void (_Concept::*__x
)() __attribute__((unused
))
432 = &_Concept::__constraint
;
436 struct has_decrement_operators
438 template<typename _Tp
>
453 void (_Concept::*__x
)() __attribute__((unused
))
454 = &_Concept::__constraint
;
458 #if __cplusplus >= 201103L
459 template<typename _Tp
>
461 constexpr_bitwise_operators()
463 constexpr _Tp a
= _Tp();
464 constexpr _Tp b
= _Tp();
465 constexpr _Tp c1
__attribute__((unused
)) = a
| b
;
466 constexpr _Tp c2
__attribute__((unused
)) = a
& b
;
467 constexpr _Tp c3
__attribute__((unused
)) = a
^ b
;
468 constexpr _Tp c4
__attribute__((unused
)) = ~b
;
472 template<typename _Tp
>
484 template<typename _Tp
>
486 bitwise_assignment_operators()
488 #if __cplusplus >= 201103L
500 // 17.3.2.1.2 - Bitmask types [lib.bitmask.types]
502 template<typename _BitmTp
>
506 bitwise_operators
<_BitmTp
>();
507 bitwise_assignment_operators
<_BitmTp
>();
510 struct has_bitwise_operators
512 template<typename _Tp
>
528 void (_Concept::*__x
)() __attribute__((unused
))
529 = &_Concept::__constraint
;
533 #if __cplusplus >= 201103L
535 struct constexpr_comparison_eq_ne
537 template<typename _Tp1
, typename _Tp2
= _Tp1
>
541 static_assert(_Tp1() == _Tp2(), "eq");
542 static_assert(!(_Tp1() != _Tp2()), "ne");
546 struct constexpr_comparison_operators
548 template<typename _Tp
>
552 static_assert(!(_Tp() < _Tp()), "less");
553 static_assert(_Tp() <= _Tp(), "leq");
554 static_assert(!(_Tp() > _Tp()), "more");
555 static_assert(_Tp() >= _Tp(), "meq");
556 static_assert(_Tp() == _Tp(), "eq");
557 static_assert(!(_Tp() != _Tp()), "ne");
561 // Generator to test standard layout
562 struct has_trivial_cons_dtor
564 template<typename _Tp
>
572 typedef std::is_trivially_default_constructible
<_Tp
> ctor_p
;
573 static_assert(ctor_p::value
, "default constructor not trivial");
575 typedef std::is_trivially_destructible
<_Tp
> dtor_p
;
576 static_assert(dtor_p::value
, "destructor not trivial");
580 void (_Concept::*__x
)() __attribute__((unused
))
581 = &_Concept::__constraint
;
585 struct standard_layout
587 template<typename _Tp
>
595 typedef std::is_standard_layout
<_Tp
> standard_layout_p
;
596 static_assert(standard_layout_p::value
, "not standard_layout");
600 void (_Concept::*__x
)() __attribute__((unused
))
601 = &_Concept::__constraint
;
606 // Generator to test base class
607 struct has_required_base_class
609 template<typename _TBase
, typename _TDerived
>
617 const _TDerived
& obj
= __a
;
618 const _TBase
* base
__attribute__((unused
)) = &obj
;
624 void (_Concept::*__x
)() __attribute__((unused
))
625 = &_Concept::__constraint
;
629 // Generator to test assignment operator.
632 template<typename _Tp
>
645 void (_Concept::*__x
)() __attribute__((unused
))
646 = &_Concept::__constraint
;
650 // Generator to test default constructor.
651 struct default_constructible
653 template<typename _Tp
>
660 { _Tp __v
__attribute__((unused
)); }
663 void (_Concept::*__x
)() __attribute__((unused
))
664 = &_Concept::__constraint
;
668 // Generator to test copy constructor.
669 struct copy_constructible
671 template<typename _Tp
>
683 void (_Concept::*__x
)() __attribute__((unused
))
684 = &_Concept::__constraint
;
688 // Generator to test direct initialization, single value constructor.
689 struct single_value_constructible
691 template<typename _Ttype
, typename _Tvalue
>
703 void (_Concept::*__x
)() __attribute__((unused
))
704 = &_Concept::__constraint
;
708 #if __cplusplus >= 201103L
709 // Generator to test non-explicit default constructor.
710 struct implicitly_default_constructible
712 template<typename _Tp
>
718 struct Aggregate
{ _Tp v
; };
721 { Aggregate __v
__attribute__((unused
)) = { }; }
724 void (_Concept::*__x
)() __attribute__((unused
))
725 = &_Concept::__constraint
;
729 // Generator to test default constructor.
730 struct constexpr_default_constructible
732 template<typename _Tp
, bool _IsLitp
= std::is_literal_type
<_Tp
>::value
>
735 // NB: _Tp must be a literal type.
736 // Have to have user-defined default ctor for this to work,
737 // or implicit default ctor must initialize all members.
738 template<typename _Tp
>
739 struct _Concept
<_Tp
, true>
742 { constexpr _Tp __obj
; }
745 // Non-literal type, declare local static and verify no
746 // constructors generated for _Tp within the translation unit.
747 template<typename _Tp
>
748 struct _Concept
<_Tp
, false>
751 { static _Tp __obj
; }
754 template<typename _Tp
>
763 // Generator to test defaulted default constructor.
764 struct constexpr_defaulted_default_constructible
766 template<typename _Tp
>
773 { constexpr _Tp __v
__attribute__((unused
)) { }; }
776 void (_Concept::*__x
)() __attribute__((unused
))
777 = &_Concept::__constraint
;
781 struct constexpr_single_value_constructible
783 template<typename _Ttesttype
, typename _Tvaluetype
,
784 bool _IsLitp
= std::is_literal_type
<_Ttesttype
>::value
>
787 // NB: _Tvaluetype and _Ttesttype must be literal types.
788 // Additional constraint on _Tvaluetype needed. Either assume
789 // user-defined default ctor as per
790 // constexpr_default_constructible and provide no initializer,
791 // provide an initializer, or assume empty-list init-able. Choose
793 template<typename _Ttesttype
, typename _Tvaluetype
>
794 struct _Concept
<_Ttesttype
, _Tvaluetype
, true>
798 constexpr _Tvaluetype __v
{ };
799 constexpr _Ttesttype
__obj(__v
);
803 template<typename _Ttesttype
, typename _Tvaluetype
>
804 struct _Concept
<_Ttesttype
, _Tvaluetype
, false>
808 const _Tvaluetype __v
{ };
809 static _Ttesttype
__obj(__v
);
813 template<typename _Ttesttype
, typename _Tvaluetype
>
817 _Concept
<_Ttesttype
, _Tvaluetype
> c
;
823 // Generator to test direct list initialization
824 #if __cplusplus >= 201103L
825 struct direct_list_initializable
827 template<typename _Ttype
, typename _Tvalue
>
835 _Ttype __v1
{ }; // default ctor
836 _Ttype __v2
{ __a
}; // single-argument ctor
842 void (_Concept::*__x
)() __attribute__((unused
))
843 = &_Concept::__constraint
;
848 // Generator to test copy list initialization, aggregate initialization
849 struct copy_list_initializable
851 template<typename _Ttype
, typename _Tvalue
>
858 { _Ttype __v
__attribute__((unused
)) = {__a
}; }
863 void (_Concept::*__x
)() __attribute__((unused
))
864 = &_Concept::__constraint
;
868 // Generator to test integral conversion operator
869 struct integral_convertable
871 template<typename _Ttype
, typename _Tvalue
>
884 VERIFY( __v1
== __v0
);
888 void (_Concept::*__x
)() __attribute__((unused
))
889 = &_Concept::__constraint
;
893 // Generator to test integral assignment operator
894 struct integral_assignable
896 template<typename _Ttype
, typename _Tvalue
>
910 VERIFY( __v1
== __vr
);
914 void (_Concept::*__x
)() __attribute__((unused
))
915 = &_Concept::__constraint
;
919 #if __cplusplus >= 201103L
920 // Generator to test lowering requirements for compare-and-exchange.
921 template<std::memory_order _Torder
>
922 struct compare_exchange_order_lowering
924 template<typename _Tp
>
928 std::atomic
<_Tp
> __x
;
930 __x
.compare_exchange_strong(__expected
, 1, _Torder
);
931 __x
.compare_exchange_weak(__expected
, 1, _Torder
);
935 } // namespace __gnu_test