2 // typelist for the C++ library testsuite.
4 // Copyright (C) 2005-2016 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()
476 // 17.3.2.1.2 - Bitmask types [lib.bitmask.types]
478 template<typename _BitmTp
>
482 bitwise_operators
<_BitmTp
>();
483 bitwise_assignment_operators
<_BitmTp
>();
486 struct has_bitwise_operators
488 template<typename _Tp
>
504 void (_Concept::*__x
)() __attribute__((unused
))
505 = &_Concept::__constraint
;
509 #if __cplusplus >= 201103L
511 struct constexpr_comparison_eq_ne
513 template<typename _Tp1
, typename _Tp2
= _Tp1
>
517 static_assert(_Tp1() == _Tp2(), "eq");
518 static_assert(!(_Tp1() != _Tp2()), "ne");
522 struct constexpr_comparison_operators
524 template<typename _Tp
>
528 static_assert(!(_Tp() < _Tp()), "less");
529 static_assert(_Tp() <= _Tp(), "leq");
530 static_assert(!(_Tp() > _Tp()), "more");
531 static_assert(_Tp() >= _Tp(), "meq");
532 static_assert(_Tp() == _Tp(), "eq");
533 static_assert(!(_Tp() != _Tp()), "ne");
537 // Generator to test standard layout
538 struct has_trivial_cons_dtor
540 template<typename _Tp
>
548 typedef std::is_trivially_default_constructible
<_Tp
> ctor_p
;
549 static_assert(ctor_p::value
, "default constructor not trivial");
551 typedef std::is_trivially_destructible
<_Tp
> dtor_p
;
552 static_assert(dtor_p::value
, "destructor not trivial");
556 void (_Concept::*__x
)() __attribute__((unused
))
557 = &_Concept::__constraint
;
561 struct standard_layout
563 template<typename _Tp
>
571 typedef std::is_standard_layout
<_Tp
> standard_layout_p
;
572 static_assert(standard_layout_p::value
, "not standard_layout");
576 void (_Concept::*__x
)() __attribute__((unused
))
577 = &_Concept::__constraint
;
582 // Generator to test base class
583 struct has_required_base_class
585 template<typename _TBase
, typename _TDerived
>
593 const _TDerived
& obj
= __a
;
594 const _TBase
* base
__attribute__((unused
)) = &obj
;
600 void (_Concept::*__x
)() __attribute__((unused
))
601 = &_Concept::__constraint
;
605 // Generator to test assignment operator.
608 template<typename _Tp
>
621 void (_Concept::*__x
)() __attribute__((unused
))
622 = &_Concept::__constraint
;
626 // Generator to test default constructor.
627 struct default_constructible
629 template<typename _Tp
>
636 { _Tp __v
__attribute__((unused
)); }
639 void (_Concept::*__x
)() __attribute__((unused
))
640 = &_Concept::__constraint
;
644 // Generator to test copy constructor.
645 struct copy_constructible
647 template<typename _Tp
>
659 void (_Concept::*__x
)() __attribute__((unused
))
660 = &_Concept::__constraint
;
664 // Generator to test direct initialization, single value constructor.
665 struct single_value_constructible
667 template<typename _Ttype
, typename _Tvalue
>
679 void (_Concept::*__x
)() __attribute__((unused
))
680 = &_Concept::__constraint
;
684 #if __cplusplus >= 201103L
685 // Generator to test default constructor.
686 struct constexpr_default_constructible
688 template<typename _Tp
, bool _IsLitp
= std::is_literal_type
<_Tp
>::value
>
691 // NB: _Tp must be a literal type.
692 // Have to have user-defined default ctor for this to work,
693 // or implicit default ctor must initialize all members.
694 template<typename _Tp
>
695 struct _Concept
<_Tp
, true>
698 { constexpr _Tp __obj
; }
701 // Non-literal type, declare local static and verify no
702 // constructors generated for _Tp within the translation unit.
703 template<typename _Tp
>
704 struct _Concept
<_Tp
, false>
707 { static _Tp __obj
; }
710 template<typename _Tp
>
719 // Generator to test defaulted default constructor.
720 struct constexpr_defaulted_default_constructible
722 template<typename _Tp
>
729 { constexpr _Tp __v
__attribute__((unused
)) { }; }
732 void (_Concept::*__x
)() __attribute__((unused
))
733 = &_Concept::__constraint
;
737 struct constexpr_single_value_constructible
739 template<typename _Ttesttype
, typename _Tvaluetype
,
740 bool _IsLitp
= std::is_literal_type
<_Ttesttype
>::value
>
743 // NB: _Tvaluetype and _Ttesttype must be literal types.
744 // Additional constraint on _Tvaluetype needed. Either assume
745 // user-defined default ctor as per
746 // constexpr_default_constructible and provide no initializer,
747 // provide an initializer, or assume empty-list init-able. Choose
749 template<typename _Ttesttype
, typename _Tvaluetype
>
750 struct _Concept
<_Ttesttype
, _Tvaluetype
, true>
754 constexpr _Tvaluetype __v
{ };
755 constexpr _Ttesttype
__obj(__v
);
759 template<typename _Ttesttype
, typename _Tvaluetype
>
760 struct _Concept
<_Ttesttype
, _Tvaluetype
, false>
764 const _Tvaluetype __v
{ };
765 static _Ttesttype
__obj(__v
);
769 template<typename _Ttesttype
, typename _Tvaluetype
>
773 _Concept
<_Ttesttype
, _Tvaluetype
> c
;
779 // Generator to test direct list initialization
780 #if __cplusplus >= 201103L
781 struct direct_list_initializable
783 template<typename _Ttype
, typename _Tvalue
>
791 _Ttype __v1
{ }; // default ctor
792 _Ttype __v2
{ __a
}; // single-argument ctor
798 void (_Concept::*__x
)() __attribute__((unused
))
799 = &_Concept::__constraint
;
804 // Generator to test copy list initialization, aggregate initialization
805 struct copy_list_initializable
807 template<typename _Ttype
, typename _Tvalue
>
814 { _Ttype __v
__attribute__((unused
)) = {__a
}; }
819 void (_Concept::*__x
)() __attribute__((unused
))
820 = &_Concept::__constraint
;
824 // Generator to test integral conversion operator
825 struct integral_convertable
827 template<typename _Ttype
, typename _Tvalue
>
840 bool test
__attribute__((unused
)) = true;
841 VERIFY( __v1
== __v0
);
845 void (_Concept::*__x
)() __attribute__((unused
))
846 = &_Concept::__constraint
;
850 // Generator to test integral assignment operator
851 struct integral_assignable
853 template<typename _Ttype
, typename _Tvalue
>
867 bool test
__attribute__((unused
)) = true;
868 VERIFY( __v1
== __vr
);
872 void (_Concept::*__x
)() __attribute__((unused
))
873 = &_Concept::__constraint
;
877 #if __cplusplus >= 201103L
878 // Generator to test lowering requirements for compare-and-exchange.
879 template<std::memory_order _Torder
>
880 struct compare_exchange_order_lowering
882 template<typename _Tp
>
886 std::atomic
<_Tp
> __x
;
888 __x
.compare_exchange_strong(__expected
, 1, _Torder
);
889 __x
.compare_exchange_weak(__expected
, 1, _Torder
);
893 } // namespace __gnu_test