2 // typelist for the C++ library testsuite.
4 // Copyright (C) 2005-2017 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::node
;
55 using __gnu_cxx::typelist::transform
;
56 using __gnu_cxx::typelist::append
;
58 // All the allocators to test.
59 template<typename Tp
, bool Thread
>
60 struct allocator_policies
62 typedef Tp value_type
;
63 typedef __gnu_cxx::new_allocator
<Tp
> a1
;
64 typedef __gnu_cxx::malloc_allocator
<Tp
> a2
;
65 typedef __gnu_cxx::__common_pool_policy
<__gnu_cxx::__pool
, Thread
> pool_policy
;
66 typedef __gnu_cxx::__mt_alloc
<Tp
, pool_policy
> a3
;
67 typedef __gnu_cxx::bitmap_allocator
<Tp
> a4
;
68 typedef __gnu_cxx::__pool_alloc
<Tp
> a5
;
69 typedef node
<_GLIBCXX_TYPELIST_CHAIN5(a1
, a2
, a3
, a4
, a5
)> type
;
72 // Typelists for vector, string, list, deque.
73 // XXX should just use template templates
74 template<typename Tp
, bool Thread
>
77 typedef Tp value_type
;
82 typedef Tl allocator_type
;
83 typedef std::vector
<value_type
, allocator_type
> type
;
86 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
87 typedef typename
allocator_types::type allocator_typelist
;
88 typedef typename transform
<allocator_typelist
, vector_shell
>::type type
;
91 template<typename Tp
, bool Thread
>
94 typedef Tp value_type
;
99 typedef Tl allocator_type
;
100 typedef std::list
<value_type
, allocator_type
> type
;
103 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
104 typedef typename
allocator_types::type allocator_typelist
;
105 typedef typename transform
<allocator_typelist
, list_shell
>::type type
;
108 template<typename Tp
, bool Thread
>
111 typedef Tp value_type
;
113 template<typename Tl
>
116 typedef Tl allocator_type
;
117 typedef std::deque
<value_type
, allocator_type
> type
;
120 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
121 typedef typename
allocator_types::type allocator_typelist
;
122 typedef typename transform
<allocator_typelist
, deque_shell
>::type type
;
125 template<typename Tp
, bool Thread
>
128 typedef Tp value_type
;
130 template<typename Tl
>
133 typedef Tl allocator_type
;
134 typedef std::char_traits
<value_type
> traits_type
;
135 typedef std::basic_string
<value_type
, traits_type
, allocator_type
> type
;
138 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
139 typedef typename
allocator_types::type allocator_typelist
;
140 typedef typename transform
<allocator_typelist
, string_shell
>::type type
;
143 // A typelist of vector, list, deque, and string all instantiated
144 // with each of the allocator policies.
145 template<typename Tp
, bool Thread
>
146 struct sequence_containers
148 typedef Tp value_type
;
150 typedef typename vectors
<value_type
, Thread
>::type vector_typelist
;
151 typedef typename lists
<value_type
, Thread
>::type list_typelist
;
152 typedef typename deques
<value_type
, Thread
>::type deque_typelist
;
153 typedef typename strings
<value_type
, Thread
>::type string_typelist
;
155 typedef typename append
<vector_typelist
, list_typelist
>::type a1
;
156 typedef typename append
<deque_typelist
, string_typelist
>::type a2
;
157 typedef typename append
<a1
, a2
>::type type
;
160 // Typelists for map, set, unordered_set, unordered_map.
161 template<typename Tp
, bool Thread
>
164 typedef Tp value_type
;
166 typedef std::pair
<const key_type
, value_type
> pair_type
;
167 typedef std::less
<key_type
> compare_function
;
169 template<typename Tl
>
172 typedef Tl allocator_type
;
173 typedef std::map
<key_type
, value_type
, compare_function
, allocator_type
> type
;
176 typedef allocator_policies
<pair_type
, Thread
> allocator_types
;
177 typedef typename
allocator_types::type allocator_typelist
;
178 typedef typename transform
<allocator_typelist
, container
>::type type
;
181 template<typename Tp
, bool Thread
>
182 struct unordered_maps
184 typedef Tp value_type
;
186 typedef std::pair
<const key_type
, value_type
> pair_type
;
187 typedef std::tr1::hash
<key_type
> hash_function
;
188 typedef std::equal_to
<key_type
> equality_function
;
190 template<typename Tl
>
193 typedef Tl allocator_type
;
194 typedef std::tr1::unordered_map
<key_type
, value_type
, hash_function
, equality_function
, allocator_type
> type
;
197 typedef allocator_policies
<pair_type
, Thread
> allocator_types
;
198 typedef typename
allocator_types::type allocator_typelist
;
199 typedef typename transform
<allocator_typelist
, container
>::type type
;
202 template<typename Tp
, bool Thread
>
205 typedef Tp value_type
;
207 typedef std::less
<key_type
> compare_function
;
209 template<typename Tl
>
212 typedef Tl allocator_type
;
213 typedef std::set
<key_type
, compare_function
, allocator_type
> type
;
216 typedef allocator_policies
<key_type
, Thread
> allocator_types
;
217 typedef typename
allocator_types::type allocator_typelist
;
218 typedef typename transform
<allocator_typelist
, container
>::type type
;
221 template<typename Tp
, bool Thread
>
222 struct unordered_sets
224 typedef Tp value_type
;
226 typedef std::tr1::hash
<key_type
> hash_function
;
227 typedef std::equal_to
<key_type
> equality_function
;
229 template<typename Tl
>
232 typedef Tl allocator_type
;
233 typedef std::tr1::unordered_set
<key_type
, hash_function
, equality_function
, allocator_type
> type
;
236 typedef allocator_policies
<key_type
, Thread
> allocator_types
;
237 typedef typename
allocator_types::type allocator_typelist
;
238 typedef typename transform
<allocator_typelist
, container
>::type type
;
242 // A typelist of all associated container types, with each of the
243 // allocator policies.
244 template<typename Tp
, bool Thread
>
245 struct associative_containers
247 typedef Tp value_type
;
249 typedef typename maps
<value_type
, Thread
>::type map_typelist
;
250 typedef typename sets
<value_type
, Thread
>::type set_typelist
;
251 typedef typename unordered_maps
<value_type
, Thread
>::type unordered_map_typelist
;
252 typedef typename unordered_sets
<value_type
, Thread
>::type unordered_set_typelist
;
254 typedef typename append
<map_typelist
, unordered_map_typelist
>::type a1
;
255 typedef typename append
<set_typelist
, unordered_set_typelist
>::type a2
;
256 typedef typename append
<a1
, a2
>::type type
;
259 // A typelist of all standard integral types.
260 struct integral_types
264 typedef signed char a3
;
265 typedef unsigned char a4
;
267 typedef unsigned short a6
;
269 typedef unsigned int a8
;
271 typedef unsigned long a10
;
272 typedef long long a11
;
273 typedef unsigned long long a12
;
275 #if __cplusplus >= 201103L
276 typedef char16_t a14
;
277 typedef char32_t a15
;
279 typedef node
<_GLIBCXX_TYPELIST_CHAIN15(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
280 a10
, a11
, a12
, a13
, a14
, a15
)> type
;
282 typedef node
<_GLIBCXX_TYPELIST_CHAIN13(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
283 a10
, a11
, a12
, a13
)> type
;
287 // A typelist of all standard integral types + the GNU 128-bit types.
288 struct integral_types_gnu
292 typedef signed char a3
;
293 typedef unsigned char a4
;
295 typedef unsigned short a6
;
297 typedef unsigned int a8
;
299 typedef unsigned long a10
;
300 typedef long long a11
;
301 typedef unsigned long long a12
;
303 #if __cplusplus >= 201103L
304 typedef char16_t a14
;
305 typedef char32_t a15
;
306 # if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
307 __extension__
typedef __int128 a16
;
308 __extension__
typedef unsigned __int128 a17
;
310 typedef node
<_GLIBCXX_TYPELIST_CHAIN17(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
311 a10
, a11
, a12
, a13
, a14
, a15
,
314 typedef node
<_GLIBCXX_TYPELIST_CHAIN15(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
315 a10
, a11
, a12
, a13
, a14
, a15
)> type
;
318 # if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
319 __extension__
typedef __int128 a14
;
320 __extension__
typedef unsigned __int128 a15
;
322 typedef node
<_GLIBCXX_TYPELIST_CHAIN15(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
323 a10
, a11
, a12
, a13
, a14
, a15
)> type
;
325 typedef node
<_GLIBCXX_TYPELIST_CHAIN13(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
326 a10
, a11
, a12
, a13
)> type
;
331 #if __cplusplus >= 201103L
332 struct atomic_integrals_no_bool
334 typedef std::atomic_char a2
;
335 typedef std::atomic_schar a3
;
336 typedef std::atomic_uchar a4
;
337 typedef std::atomic_short a5
;
338 typedef std::atomic_ushort a6
;
339 typedef std::atomic_int a7
;
340 typedef std::atomic_uint a8
;
341 typedef std::atomic_long a9
;
342 typedef std::atomic_ulong a10
;
343 typedef std::atomic_llong a11
;
344 typedef std::atomic_ullong a12
;
345 typedef std::atomic_wchar_t a13
;
346 typedef std::atomic_char16_t a14
;
347 typedef std::atomic_char32_t a15
;
349 typedef node
<_GLIBCXX_TYPELIST_CHAIN14(a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
350 a10
, a11
, a12
, a13
, a14
, a15
)> type
;
353 struct atomic_integrals
355 typedef std::atomic_bool a1
;
356 typedef std::atomic_char a2
;
357 typedef std::atomic_schar a3
;
358 typedef std::atomic_uchar a4
;
359 typedef std::atomic_short a5
;
360 typedef std::atomic_ushort a6
;
361 typedef std::atomic_int a7
;
362 typedef std::atomic_uint a8
;
363 typedef std::atomic_long a9
;
364 typedef std::atomic_ulong a10
;
365 typedef std::atomic_llong a11
;
366 typedef std::atomic_ullong a12
;
367 typedef std::atomic_wchar_t a13
;
368 typedef std::atomic_char16_t a14
;
369 typedef std::atomic_char32_t a15
;
371 typedef node
<_GLIBCXX_TYPELIST_CHAIN15(a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
,
372 a10
, a11
, a12
, a13
, a14
, a15
)> type
;
376 template<typename Tp
>
379 typedef Tp value_type
;
380 typedef std::atomic
<value_type
> type
;
383 typedef transform
<integral_types::type
, atomics
>::type atomics_tl
;
386 template<typename Tp
>
387 struct numeric_limits
389 typedef Tp value_type
;
390 typedef std::numeric_limits
<value_type
> type
;
393 typedef transform
<integral_types_gnu::type
, numeric_limits
>::type limits_tl
;
395 struct has_increment_operators
397 template<typename _Tp
>
412 void (_Concept::*__x
)() __attribute__((unused
))
413 = &_Concept::__constraint
;
417 struct has_decrement_operators
419 template<typename _Tp
>
434 void (_Concept::*__x
)() __attribute__((unused
))
435 = &_Concept::__constraint
;
439 #if __cplusplus >= 201103L
440 template<typename _Tp
>
442 constexpr_bitwise_operators()
444 constexpr _Tp a
= _Tp();
445 constexpr _Tp b
= _Tp();
446 constexpr _Tp c1
__attribute__((unused
)) = a
| b
;
447 constexpr _Tp c2
__attribute__((unused
)) = a
& b
;
448 constexpr _Tp c3
__attribute__((unused
)) = a
^ b
;
449 constexpr _Tp c4
__attribute__((unused
)) = ~b
;
453 template<typename _Tp
>
465 template<typename _Tp
>
467 bitwise_assignment_operators()
469 #if __cplusplus >= 201103L
481 // 17.3.2.1.2 - Bitmask types [lib.bitmask.types]
483 template<typename _BitmTp
>
487 bitwise_operators
<_BitmTp
>();
488 bitwise_assignment_operators
<_BitmTp
>();
491 struct has_bitwise_operators
493 template<typename _Tp
>
509 void (_Concept::*__x
)() __attribute__((unused
))
510 = &_Concept::__constraint
;
514 #if __cplusplus >= 201103L
516 struct constexpr_comparison_eq_ne
518 template<typename _Tp1
, typename _Tp2
= _Tp1
>
522 static_assert(_Tp1() == _Tp2(), "eq");
523 static_assert(!(_Tp1() != _Tp2()), "ne");
527 struct constexpr_comparison_operators
529 template<typename _Tp
>
533 static_assert(!(_Tp() < _Tp()), "less");
534 static_assert(_Tp() <= _Tp(), "leq");
535 static_assert(!(_Tp() > _Tp()), "more");
536 static_assert(_Tp() >= _Tp(), "meq");
537 static_assert(_Tp() == _Tp(), "eq");
538 static_assert(!(_Tp() != _Tp()), "ne");
542 // Generator to test standard layout
543 struct has_trivial_cons_dtor
545 template<typename _Tp
>
553 typedef std::is_trivially_default_constructible
<_Tp
> ctor_p
;
554 static_assert(ctor_p::value
, "default constructor not trivial");
556 typedef std::is_trivially_destructible
<_Tp
> dtor_p
;
557 static_assert(dtor_p::value
, "destructor not trivial");
561 void (_Concept::*__x
)() __attribute__((unused
))
562 = &_Concept::__constraint
;
566 struct standard_layout
568 template<typename _Tp
>
576 typedef std::is_standard_layout
<_Tp
> standard_layout_p
;
577 static_assert(standard_layout_p::value
, "not standard_layout");
581 void (_Concept::*__x
)() __attribute__((unused
))
582 = &_Concept::__constraint
;
587 // Generator to test base class
588 struct has_required_base_class
590 template<typename _TBase
, typename _TDerived
>
598 const _TDerived
& obj
= __a
;
599 const _TBase
* base
__attribute__((unused
)) = &obj
;
605 void (_Concept::*__x
)() __attribute__((unused
))
606 = &_Concept::__constraint
;
610 // Generator to test assignment operator.
613 template<typename _Tp
>
626 void (_Concept::*__x
)() __attribute__((unused
))
627 = &_Concept::__constraint
;
631 // Generator to test default constructor.
632 struct default_constructible
634 template<typename _Tp
>
641 { _Tp __v
__attribute__((unused
)); }
644 void (_Concept::*__x
)() __attribute__((unused
))
645 = &_Concept::__constraint
;
649 // Generator to test copy constructor.
650 struct copy_constructible
652 template<typename _Tp
>
664 void (_Concept::*__x
)() __attribute__((unused
))
665 = &_Concept::__constraint
;
669 // Generator to test direct initialization, single value constructor.
670 struct single_value_constructible
672 template<typename _Ttype
, typename _Tvalue
>
684 void (_Concept::*__x
)() __attribute__((unused
))
685 = &_Concept::__constraint
;
689 #if __cplusplus >= 201103L
690 // Generator to test default constructor.
691 struct constexpr_default_constructible
693 template<typename _Tp
, bool _IsLitp
= std::is_literal_type
<_Tp
>::value
>
696 // NB: _Tp must be a literal type.
697 // Have to have user-defined default ctor for this to work,
698 // or implicit default ctor must initialize all members.
699 template<typename _Tp
>
700 struct _Concept
<_Tp
, true>
703 { constexpr _Tp __obj
; }
706 // Non-literal type, declare local static and verify no
707 // constructors generated for _Tp within the translation unit.
708 template<typename _Tp
>
709 struct _Concept
<_Tp
, false>
712 { static _Tp __obj
; }
715 template<typename _Tp
>
724 // Generator to test defaulted default constructor.
725 struct constexpr_defaulted_default_constructible
727 template<typename _Tp
>
734 { constexpr _Tp __v
__attribute__((unused
)) { }; }
737 void (_Concept::*__x
)() __attribute__((unused
))
738 = &_Concept::__constraint
;
742 struct constexpr_single_value_constructible
744 template<typename _Ttesttype
, typename _Tvaluetype
,
745 bool _IsLitp
= std::is_literal_type
<_Ttesttype
>::value
>
748 // NB: _Tvaluetype and _Ttesttype must be literal types.
749 // Additional constraint on _Tvaluetype needed. Either assume
750 // user-defined default ctor as per
751 // constexpr_default_constructible and provide no initializer,
752 // provide an initializer, or assume empty-list init-able. Choose
754 template<typename _Ttesttype
, typename _Tvaluetype
>
755 struct _Concept
<_Ttesttype
, _Tvaluetype
, true>
759 constexpr _Tvaluetype __v
{ };
760 constexpr _Ttesttype
__obj(__v
);
764 template<typename _Ttesttype
, typename _Tvaluetype
>
765 struct _Concept
<_Ttesttype
, _Tvaluetype
, false>
769 const _Tvaluetype __v
{ };
770 static _Ttesttype
__obj(__v
);
774 template<typename _Ttesttype
, typename _Tvaluetype
>
778 _Concept
<_Ttesttype
, _Tvaluetype
> c
;
784 // Generator to test direct list initialization
785 #if __cplusplus >= 201103L
786 struct direct_list_initializable
788 template<typename _Ttype
, typename _Tvalue
>
796 _Ttype __v1
{ }; // default ctor
797 _Ttype __v2
{ __a
}; // single-argument ctor
803 void (_Concept::*__x
)() __attribute__((unused
))
804 = &_Concept::__constraint
;
809 // Generator to test copy list initialization, aggregate initialization
810 struct copy_list_initializable
812 template<typename _Ttype
, typename _Tvalue
>
819 { _Ttype __v
__attribute__((unused
)) = {__a
}; }
824 void (_Concept::*__x
)() __attribute__((unused
))
825 = &_Concept::__constraint
;
829 // Generator to test integral conversion operator
830 struct integral_convertable
832 template<typename _Ttype
, typename _Tvalue
>
845 VERIFY( __v1
== __v0
);
849 void (_Concept::*__x
)() __attribute__((unused
))
850 = &_Concept::__constraint
;
854 // Generator to test integral assignment operator
855 struct integral_assignable
857 template<typename _Ttype
, typename _Tvalue
>
871 VERIFY( __v1
== __vr
);
875 void (_Concept::*__x
)() __attribute__((unused
))
876 = &_Concept::__constraint
;
880 #if __cplusplus >= 201103L
881 // Generator to test lowering requirements for compare-and-exchange.
882 template<std::memory_order _Torder
>
883 struct compare_exchange_order_lowering
885 template<typename _Tp
>
889 std::atomic
<_Tp
> __x
;
891 __x
.compare_exchange_strong(__expected
, 1, _Torder
);
892 __x
.compare_exchange_weak(__expected
, 1, _Torder
);
896 } // namespace __gnu_test