2 // typelist for the C++ library testsuite.
4 // Copyright (C) 2005-2024 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>
44 #if __cplusplus >= 201103L
46 #include <type_traits>
47 #include <unordered_map>
48 #include <unordered_set>
49 namespace unord
= std
;
51 #include <tr1/unordered_map>
52 #include <tr1/unordered_set>
53 namespace unord
= std::tr1
;
58 using __gnu_cxx::typelist::null_type
;
59 using __gnu_cxx::typelist::node
;
60 using __gnu_cxx::typelist::transform
;
61 using __gnu_cxx::typelist::append
;
63 // All the allocators to test.
64 template<typename Tp
, bool Thread
>
65 struct allocator_policies
67 typedef Tp value_type
;
68 typedef __gnu_cxx::new_allocator
<Tp
> a1
;
69 typedef __gnu_cxx::malloc_allocator
<Tp
> a2
;
70 typedef __gnu_cxx::__common_pool_policy
<__gnu_cxx::__pool
, Thread
> pool_policy
;
71 typedef __gnu_cxx::__mt_alloc
<Tp
, pool_policy
> a3
;
72 typedef __gnu_cxx::bitmap_allocator
<Tp
> a4
;
73 typedef __gnu_cxx::__pool_alloc
<Tp
> a5
;
74 typedef node
<_GLIBCXX_TYPELIST_CHAIN5(a1
, a2
, a3
, a4
, a5
)> type
;
77 // Typelists for vector, string, list, deque.
78 // XXX should just use template templates
79 template<typename Tp
, bool Thread
>
82 typedef Tp value_type
;
87 typedef Tl allocator_type
;
88 typedef std::vector
<value_type
, allocator_type
> type
;
91 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
92 typedef typename
allocator_types::type allocator_typelist
;
93 typedef typename transform
<allocator_typelist
, vector_shell
>::type type
;
96 template<typename Tp
, bool Thread
>
99 typedef Tp value_type
;
101 template<typename Tl
>
104 typedef Tl allocator_type
;
105 typedef std::list
<value_type
, allocator_type
> type
;
108 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
109 typedef typename
allocator_types::type allocator_typelist
;
110 typedef typename transform
<allocator_typelist
, list_shell
>::type type
;
113 template<typename Tp
, bool Thread
>
116 typedef Tp value_type
;
118 template<typename Tl
>
121 typedef Tl allocator_type
;
122 typedef std::deque
<value_type
, allocator_type
> type
;
125 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
126 typedef typename
allocator_types::type allocator_typelist
;
127 typedef typename transform
<allocator_typelist
, deque_shell
>::type type
;
130 template<typename Tp
, bool Thread
>
133 typedef Tp value_type
;
135 template<typename Tl
>
138 typedef Tl allocator_type
;
139 typedef std::char_traits
<value_type
> traits_type
;
140 typedef std::basic_string
<value_type
, traits_type
, allocator_type
> type
;
143 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
144 typedef typename
allocator_types::type allocator_typelist
;
145 typedef typename transform
<allocator_typelist
, string_shell
>::type type
;
148 // A typelist of vector, list, deque, and string all instantiated
149 // with each of the allocator policies.
150 template<typename Tp
, bool Thread
>
151 struct sequence_containers
153 typedef Tp value_type
;
155 typedef typename vectors
<value_type
, Thread
>::type vector_typelist
;
156 typedef typename lists
<value_type
, Thread
>::type list_typelist
;
157 typedef typename deques
<value_type
, Thread
>::type deque_typelist
;
158 typedef typename strings
<value_type
, Thread
>::type string_typelist
;
160 typedef typename append
<vector_typelist
, list_typelist
>::type a1
;
161 typedef typename append
<deque_typelist
, string_typelist
>::type a2
;
162 typedef typename append
<a1
, a2
>::type type
;
165 // Typelists for map, set, unordered_set, unordered_map.
166 template<typename Tp
, bool Thread
>
169 typedef Tp value_type
;
171 typedef std::pair
<const key_type
, value_type
> pair_type
;
172 typedef std::less
<key_type
> compare_function
;
174 template<typename Tl
>
177 typedef Tl allocator_type
;
178 typedef std::map
<key_type
, value_type
, compare_function
, allocator_type
> type
;
181 typedef allocator_policies
<pair_type
, Thread
> allocator_types
;
182 typedef typename
allocator_types::type allocator_typelist
;
183 typedef typename transform
<allocator_typelist
, container
>::type type
;
186 template<typename Tp
, bool Thread
>
187 struct unordered_maps
189 typedef Tp value_type
;
191 typedef std::pair
<const key_type
, value_type
> pair_type
;
192 typedef unord::hash
<key_type
> hash_function
;
193 typedef std::equal_to
<key_type
> equality_function
;
195 template<typename Tl
>
198 typedef Tl allocator_type
;
199 typedef unord::unordered_map
<key_type
, value_type
, hash_function
, equality_function
, allocator_type
> type
;
202 typedef allocator_policies
<pair_type
, Thread
> allocator_types
;
203 typedef typename
allocator_types::type allocator_typelist
;
204 typedef typename transform
<allocator_typelist
, container
>::type type
;
207 template<typename Tp
, bool Thread
>
210 typedef Tp value_type
;
212 typedef std::less
<key_type
> compare_function
;
214 template<typename Tl
>
217 typedef Tl allocator_type
;
218 typedef std::set
<key_type
, compare_function
, allocator_type
> type
;
221 typedef allocator_policies
<key_type
, Thread
> allocator_types
;
222 typedef typename
allocator_types::type allocator_typelist
;
223 typedef typename transform
<allocator_typelist
, container
>::type type
;
226 template<typename Tp
, bool Thread
>
227 struct unordered_sets
229 typedef Tp value_type
;
231 typedef unord::hash
<key_type
> hash_function
;
232 typedef std::equal_to
<key_type
> equality_function
;
234 template<typename Tl
>
237 typedef Tl allocator_type
;
238 typedef unord::unordered_set
<key_type
, hash_function
, equality_function
, allocator_type
> type
;
241 typedef allocator_policies
<key_type
, Thread
> allocator_types
;
242 typedef typename
allocator_types::type allocator_typelist
;
243 typedef typename transform
<allocator_typelist
, container
>::type type
;
247 // A typelist of all associated container types, with each of the
248 // allocator policies.
249 template<typename Tp
, bool Thread
>
250 struct associative_containers
252 typedef Tp value_type
;
254 typedef typename maps
<value_type
, Thread
>::type map_typelist
;
255 typedef typename sets
<value_type
, Thread
>::type set_typelist
;
256 typedef typename unordered_maps
<value_type
, Thread
>::type unordered_map_typelist
;
257 typedef typename unordered_sets
<value_type
, Thread
>::type unordered_set_typelist
;
259 typedef typename append
<map_typelist
, unordered_map_typelist
>::type a1
;
260 typedef typename append
<set_typelist
, unordered_set_typelist
>::type a2
;
261 typedef typename append
<a1
, a2
>::type type
;
264 // A typelist of all standard integral types.
265 struct integral_types
269 typedef signed char a3
;
270 typedef unsigned char a4
;
272 typedef unsigned short a6
;
274 typedef unsigned int a8
;
276 typedef unsigned long a10
;
277 typedef long long a11
;
278 typedef unsigned long long a12
;
280 typedef node
<_GLIBCXX_TYPELIST_CHAIN13(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
281 a10
, a11
, a12
, a13
)> basic_typelist
;
282 #if __cplusplus >= 201103L
283 typedef char16_t a14
;
284 typedef char32_t a15
;
285 typedef node
<_GLIBCXX_TYPELIST_CHAIN2(a14
, a15
)> cxx11_typelist
;
287 typedef node
<null_type
> cxx11_typelist
;
289 #ifdef _GLIBCXX_USE_CHAR8_T
291 typedef node
<_GLIBCXX_TYPELIST_CHAIN1(a16
)> char8_typelist
;
293 typedef node
<null_type
> char8_typelist
;
295 typedef typename append
<basic_typelist
, cxx11_typelist
>::type tl1
;
296 typedef typename append
<tl1
, char8_typelist
>::type type
;
299 // A typelist of all standard integral types + the GNU 128-bit types.
300 struct integral_types_gnu
304 typedef signed char a3
;
305 typedef unsigned char a4
;
307 typedef unsigned short a6
;
309 typedef unsigned int a8
;
311 typedef unsigned long a10
;
312 typedef long long a11
;
313 typedef unsigned long long a12
;
315 typedef node
<_GLIBCXX_TYPELIST_CHAIN13(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
316 a10
, a11
, a12
, a13
)> basic_typelist
;
317 #if __cplusplus >= 201103L
318 typedef char16_t a14
;
319 typedef char32_t a15
;
320 typedef node
<_GLIBCXX_TYPELIST_CHAIN2(a14
, a15
)> cxx11_typelist
;
322 typedef node
<null_type
> cxx11_typelist
;
324 #ifdef _GLIBCXX_USE_CHAR8_T
326 typedef node
<_GLIBCXX_TYPELIST_CHAIN1(a16
)> char8_typelist
;
328 typedef node
<null_type
> char8_typelist
;
330 # if !defined(__STRICT_ANSI__) && defined(__SIZEOF_INT128__)
331 __extension__
typedef __int128 a17
;
332 __extension__
typedef unsigned __int128 a18
;
333 typedef node
<_GLIBCXX_TYPELIST_CHAIN2(a17
, a18
)> int128_typelist
;
335 typedef node
<null_type
> int128_typelist
;
337 typedef typename append
<basic_typelist
, cxx11_typelist
>::type tl1
;
338 typedef typename append
<tl1
, char8_typelist
>::type tl2
;
339 typedef typename append
<tl2
, int128_typelist
>::type type
;
342 #if __cplusplus >= 201103L
343 struct atomic_integrals_no_bool
345 typedef std::atomic_char a2
;
346 typedef std::atomic_schar a3
;
347 typedef std::atomic_uchar a4
;
348 typedef std::atomic_short a5
;
349 typedef std::atomic_ushort a6
;
350 typedef std::atomic_int a7
;
351 typedef std::atomic_uint a8
;
352 typedef std::atomic_long a9
;
353 typedef std::atomic_ulong a10
;
354 typedef std::atomic_llong a11
;
355 typedef std::atomic_ullong a12
;
356 typedef std::atomic_wchar_t a13
;
357 typedef std::atomic_char16_t a14
;
358 typedef std::atomic_char32_t a15
;
359 typedef node
<_GLIBCXX_TYPELIST_CHAIN14(a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
,
360 a11
, a12
, a13
, a14
, a15
)> basic_typelist
;
361 #ifdef _GLIBCXX_USE_CHAR8_T
362 typedef std::atomic_char8_t a16
;
363 typedef node
<_GLIBCXX_TYPELIST_CHAIN1(a16
)> char8_typelist
;
365 typedef node
<null_type
> char8_typelist
;
367 typedef typename append
<basic_typelist
, char8_typelist
>::type type
;
370 struct atomic_integrals
372 typedef std::atomic_bool a1
;
373 typedef std::atomic_char a2
;
374 typedef std::atomic_schar a3
;
375 typedef std::atomic_uchar a4
;
376 typedef std::atomic_short a5
;
377 typedef std::atomic_ushort a6
;
378 typedef std::atomic_int a7
;
379 typedef std::atomic_uint a8
;
380 typedef std::atomic_long a9
;
381 typedef std::atomic_ulong a10
;
382 typedef std::atomic_llong a11
;
383 typedef std::atomic_ullong a12
;
384 typedef std::atomic_wchar_t a13
;
385 typedef std::atomic_char16_t a14
;
386 typedef std::atomic_char32_t a15
;
387 typedef node
<_GLIBCXX_TYPELIST_CHAIN15(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
388 a10
, a11
, a12
, a13
, a14
, a15
)> basic_typelist
;
389 #ifdef _GLIBCXX_USE_CHAR8_T
390 typedef std::atomic_char8_t a16
;
391 typedef node
<_GLIBCXX_TYPELIST_CHAIN1(a16
)> char8_typelist
;
393 typedef node
<null_type
> char8_typelist
;
395 typedef typename append
<basic_typelist
, char8_typelist
>::type type
;
399 template<typename Tp
>
402 typedef Tp value_type
;
403 typedef std::atomic
<value_type
> type
;
406 typedef transform
<integral_types::type
, atomics
>::type atomics_tl
;
409 template<typename Tp
>
410 struct numeric_limits
412 typedef Tp value_type
;
413 typedef std::numeric_limits
<value_type
> type
;
416 typedef transform
<integral_types_gnu::type
, numeric_limits
>::type limits_tl
;
418 struct has_increment_operators
420 template<typename _Tp
>
435 void (_Concept::*__x
)() __attribute__((unused
))
436 = &_Concept::__constraint
;
440 struct has_decrement_operators
442 template<typename _Tp
>
457 void (_Concept::*__x
)() __attribute__((unused
))
458 = &_Concept::__constraint
;
462 #if __cplusplus >= 201103L
463 template<typename _Tp
>
465 constexpr_bitwise_operators()
467 constexpr _Tp a
= _Tp();
468 constexpr _Tp b
= _Tp();
469 constexpr _Tp c1
__attribute__((unused
)) = a
| b
;
470 constexpr _Tp c2
__attribute__((unused
)) = a
& b
;
471 constexpr _Tp c3
__attribute__((unused
)) = a
^ b
;
472 constexpr _Tp c4
__attribute__((unused
)) = ~b
;
476 template<typename _Tp
>
488 template<typename _Tp
>
490 bitwise_assignment_operators()
492 #if __cplusplus >= 201103L
504 // 17.3.2.1.2 - Bitmask types [lib.bitmask.types]
506 template<typename _BitmTp
>
510 bitwise_operators
<_BitmTp
>();
511 bitwise_assignment_operators
<_BitmTp
>();
514 struct has_bitwise_operators
516 template<typename _Tp
>
532 void (_Concept::*__x
)() __attribute__((unused
))
533 = &_Concept::__constraint
;
537 #if __cplusplus >= 201103L
539 struct constexpr_comparison_eq_ne
541 template<typename _Tp1
, typename _Tp2
= _Tp1
>
545 static_assert(_Tp1() == _Tp2(), "eq");
546 static_assert(!(_Tp1() != _Tp2()), "ne");
550 struct constexpr_comparison_operators
552 template<typename _Tp
>
556 static_assert(!(_Tp() < _Tp()), "less");
557 static_assert(_Tp() <= _Tp(), "leq");
558 static_assert(!(_Tp() > _Tp()), "more");
559 static_assert(_Tp() >= _Tp(), "meq");
560 static_assert(_Tp() == _Tp(), "eq");
561 static_assert(!(_Tp() != _Tp()), "ne");
565 struct has_trivial_cons_dtor
567 template<typename _Tp
>
575 typedef std::is_trivially_default_constructible
<_Tp
> ctor_p
;
576 static_assert(ctor_p::value
, "default constructor not trivial");
578 typedef std::is_trivially_destructible
<_Tp
> dtor_p
;
579 static_assert(dtor_p::value
, "destructor not trivial");
583 void (_Concept::*__x
)() __attribute__((unused
))
584 = &_Concept::__constraint
;
588 struct has_trivial_dtor
590 template<typename _Tp
>
598 typedef std::is_trivially_destructible
<_Tp
> dtor_p
;
599 static_assert(dtor_p::value
, "destructor not trivial");
603 void (_Concept::*__x
)() __attribute__((unused
))
604 = &_Concept::__constraint
;
608 // Generator to test standard layout
609 struct standard_layout
611 template<typename _Tp
>
619 typedef std::is_standard_layout
<_Tp
> standard_layout_p
;
620 static_assert(standard_layout_p::value
, "not standard_layout");
624 void (_Concept::*__x
)() __attribute__((unused
))
625 = &_Concept::__constraint
;
630 // Generator to test base class
631 struct has_required_base_class
633 template<typename _TBase
, typename _TDerived
>
641 const _TDerived
& obj
= __a
;
642 const _TBase
* base
__attribute__((unused
)) = &obj
;
648 void (_Concept::*__x
)() __attribute__((unused
))
649 = &_Concept::__constraint
;
653 // Generator to test assignment operator.
656 template<typename _Tp
>
669 void (_Concept::*__x
)() __attribute__((unused
))
670 = &_Concept::__constraint
;
674 // Generator to test default constructor.
675 struct default_constructible
677 template<typename _Tp
>
684 { _Tp __v
__attribute__((unused
)); }
687 void (_Concept::*__x
)() __attribute__((unused
))
688 = &_Concept::__constraint
;
692 // Generator to test copy constructor.
693 struct copy_constructible
695 template<typename _Tp
>
707 void (_Concept::*__x
)() __attribute__((unused
))
708 = &_Concept::__constraint
;
712 // Generator to test direct initialization, single value constructor.
713 struct single_value_constructible
715 template<typename _Ttype
, typename _Tvalue
>
727 void (_Concept::*__x
)() __attribute__((unused
))
728 = &_Concept::__constraint
;
732 #if __cplusplus >= 201103L
733 // Generator to test non-explicit default constructor.
734 struct implicitly_default_constructible
736 template<typename _Tp
>
742 struct Aggregate
{ _Tp v
; };
745 { Aggregate __v
__attribute__((unused
)) = { }; }
748 void (_Concept::*__x
)() __attribute__((unused
))
749 = &_Concept::__constraint
;
753 // Generator to test default constructor.
754 struct constexpr_default_constructible
756 template<typename _Tp
, bool _IsLitp
= __is_literal_type(_Tp
)>
759 // NB: _Tp must be a literal type.
760 // Have to have user-defined default ctor for this to work,
761 // or implicit default ctor must initialize all members.
762 template<typename _Tp
>
763 struct _Concept
<_Tp
, true>
766 { constexpr _Tp __obj
; }
769 // Non-literal type, declare local static and verify no
770 // constructors generated for _Tp within the translation unit.
771 template<typename _Tp
>
772 struct _Concept
<_Tp
, false>
775 { static _Tp __obj
; }
778 template<typename _Tp
>
787 // Generator to test defaulted default constructor.
788 struct constexpr_defaulted_default_constructible
790 template<typename _Tp
>
797 { constexpr _Tp __v
__attribute__((unused
)) { }; }
800 void (_Concept::*__x
)() __attribute__((unused
))
801 = &_Concept::__constraint
;
805 struct constexpr_single_value_constructible
807 template<typename _Ttesttype
, typename _Tvaluetype
,
808 bool _IsLitp
= __is_literal_type(_Ttesttype
)>
811 // NB: _Tvaluetype and _Ttesttype must be literal types.
812 // Additional constraint on _Tvaluetype needed. Either assume
813 // user-defined default ctor as per
814 // constexpr_default_constructible and provide no initializer,
815 // provide an initializer, or assume empty-list init-able. Choose
817 template<typename _Ttesttype
, typename _Tvaluetype
>
818 struct _Concept
<_Ttesttype
, _Tvaluetype
, true>
822 constexpr _Tvaluetype __v
{ };
823 constexpr _Ttesttype
__obj(__v
);
827 template<typename _Ttesttype
, typename _Tvaluetype
>
828 struct _Concept
<_Ttesttype
, _Tvaluetype
, false>
832 const _Tvaluetype __v
{ };
833 static _Ttesttype
__obj(__v
);
837 template<typename _Ttesttype
, typename _Tvaluetype
>
841 _Concept
<_Ttesttype
, _Tvaluetype
> c
;
847 // Generator to test direct list initialization
848 #if __cplusplus >= 201103L
849 struct direct_list_initializable
851 template<typename _Ttype
, typename _Tvalue
>
859 _Ttype __v1
{ }; // default ctor
860 _Ttype __v2
{ __a
}; // single-argument ctor
866 void (_Concept::*__x
)() __attribute__((unused
))
867 = &_Concept::__constraint
;
872 // Generator to test copy list initialization, aggregate initialization
873 struct copy_list_initializable
875 template<typename _Ttype
, typename _Tvalue
>
882 { _Ttype __v
__attribute__((unused
)) = {__a
}; }
887 void (_Concept::*__x
)() __attribute__((unused
))
888 = &_Concept::__constraint
;
892 // Generator to test integral conversion operator
893 struct integral_convertable
895 template<typename _Ttype
, typename _Tvalue
>
908 VERIFY( __v1
== __v0
);
912 void (_Concept::*__x
)() __attribute__((unused
))
913 = &_Concept::__constraint
;
917 // Generator to test integral assignment operator
918 struct integral_assignable
920 template<typename _Ttype
, typename _Tvalue
>
934 VERIFY( __v1
== __vr
);
938 void (_Concept::*__x
)() __attribute__((unused
))
939 = &_Concept::__constraint
;
943 #if __cplusplus >= 201103L
944 // Generator to test lowering requirements for compare-and-exchange.
945 template<std::memory_order _Torder
>
946 struct compare_exchange_order_lowering
948 template<typename _Tp
>
952 std::atomic
<_Tp
> __x
;
954 __x
.compare_exchange_strong(__expected
, 1, _Torder
);
955 __x
.compare_exchange_weak(__expected
, 1, _Torder
);
960 #if __cplusplus >= 201402L
961 // Check that bitmask type T supports all the required operators,
962 // with the required semantics. Check that each bitmask element
963 // has a distinct, nonzero value, and that each bitmask constant
964 // has no bits set which do not correspond to a bitmask element.
967 test_bitmask_values(std::initializer_list
<T
> elements
,
968 std::initializer_list
<T
> constants
= {})
986 for (auto t
: elements
)
988 // Each bitmask element has a distinct value.
992 // Each bitmask element has a nonzero value.
1030 if ((t1
&= t
) != (all
& t
))
1033 if ((t1
|= t
) != (all
| t
))
1036 if ((t1
^= t
) != (all
^ t
))
1044 for (auto t
: constants
)
1046 // Check that bitmask constants are composed of the bitmask elements.
1049 if ((t
| all
) != all
)
1058 } // namespace __gnu_test