]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/include/std/type_traits
Makefile.def (install-target-libgfortran): Depend on install-target-libquadmath,...
[gcc.git] / libstdc++-v3 / include / std / type_traits
CommitLineData
13901e4b 1// C++11 type_traits -*- C++ -*-
af13a7a6 2
83ddb39f 3// Copyright (C) 2007-2012 Free Software Foundation, Inc.
af13a7a6
BK
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
af13a7a6
BK
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
748086b7
JJ
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
af13a7a6
BK
24
25/** @file include/type_traits
26 * This is a Standard C++ Library header.
27 */
28
4514bed6
BK
29#ifndef _GLIBCXX_TYPE_TRAITS
30#define _GLIBCXX_TYPE_TRAITS 1
af13a7a6
BK
31
32#pragma GCC system_header
33
734f5023 34#if __cplusplus < 201103L
ab65a4c7 35# include <bits/c++0x_warning.h>
57317d2a 36#else
af13a7a6 37
8fc81078 38#include <bits/c++config.h>
e133ace8 39
12ffa228
BK
40namespace std _GLIBCXX_VISIBILITY(default)
41{
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
e133ace8 43
8e32aa11 44 /**
13901e4b
JW
45 * @defgroup metaprogramming Metaprogramming and type traits
46 * @ingroup utilities
47 *
48 * Template utilities for compile-time introspection and modification,
49 * including type classification traits, type property inspection traits
50 * and type transformation traits.
51 *
5b9daa7e
BK
52 * @{
53 */
ac65b7d2
DK
54
55 /// integral_constant
56 template<typename _Tp, _Tp __v>
57 struct integral_constant
58 {
59 static constexpr _Tp value = __v;
60 typedef _Tp value_type;
61 typedef integral_constant<_Tp, __v> type;
62 constexpr operator value_type() { return value; }
63 };
64
13901e4b 65 /// The type used as a compile-time boolean with true value.
ac65b7d2
DK
66 typedef integral_constant<bool, true> true_type;
67
13901e4b 68 /// The type used as a compile-time boolean with false value.
ac65b7d2
DK
69 typedef integral_constant<bool, false> false_type;
70
71 template<typename _Tp, _Tp __v>
72 constexpr _Tp integral_constant<_Tp, __v>::value;
53dc5044 73
123c516a 74 // Meta programming helper types.
53dc5044 75
123c516a
PC
76 template<bool, typename, typename>
77 struct conditional;
53dc5044 78
dd7b175e 79 template<typename...>
123c516a
PC
80 struct __or_;
81
ac65b7d2
DK
82 template<>
83 struct __or_<>
84 : public false_type
85 { };
86
dd7b175e
PC
87 template<typename _B1>
88 struct __or_<_B1>
89 : public _B1
90 { };
91
123c516a
PC
92 template<typename _B1, typename _B2>
93 struct __or_<_B1, _B2>
94 : public conditional<_B1::value, _B1, _B2>::type
95 { };
96
97 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
98 struct __or_<_B1, _B2, _B3, _Bn...>
99 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
100 { };
53dc5044 101
dd7b175e 102 template<typename...>
123c516a 103 struct __and_;
53dc5044 104
ac65b7d2
DK
105 template<>
106 struct __and_<>
107 : public true_type
108 { };
109
dd7b175e
PC
110 template<typename _B1>
111 struct __and_<_B1>
112 : public _B1
113 { };
114
123c516a
PC
115 template<typename _B1, typename _B2>
116 struct __and_<_B1, _B2>
117 : public conditional<_B1::value, _B2, _B1>::type
118 { };
119
120 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
121 struct __and_<_B1, _B2, _B3, _Bn...>
122 : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
123 { };
124
125 template<typename _Pp>
126 struct __not_
127 : public integral_constant<bool, !_Pp::value>
128 { };
129
ac65b7d2
DK
130 struct __sfinae_types
131 {
132 typedef char __one;
133 typedef struct { char __arr[2]; } __two;
134 };
53dc5044 135
b3618b71
DK
136 // For several sfinae-friendly trait implementations we transport both the
137 // result information (as the member type) and the failure information (no
138 // member type). This is very similar to std::enable_if, but we cannot use
139 // them, because we need to derive from them as an implementation detail.
140
141 template<typename _Tp>
142 struct __success_type
143 { typedef _Tp type; };
144
145 struct __failure_type
146 { };
147
123c516a
PC
148 // primary type categories.
149
53dc5044
PC
150 template<typename>
151 struct remove_cv;
152
153 template<typename>
154 struct __is_void_helper
155 : public false_type { };
53dc5044 156
123c516a
PC
157 template<>
158 struct __is_void_helper<void>
159 : public true_type { };
53dc5044
PC
160
161 /// is_void
162 template<typename _Tp>
163 struct is_void
164 : public integral_constant<bool, (__is_void_helper<typename
165 remove_cv<_Tp>::type>::value)>
166 { };
167
168 template<typename>
169 struct __is_integral_helper
170 : public false_type { };
123c516a
PC
171
172 template<>
173 struct __is_integral_helper<bool>
174 : public true_type { };
175
176 template<>
177 struct __is_integral_helper<char>
178 : public true_type { };
179
180 template<>
181 struct __is_integral_helper<signed char>
182 : public true_type { };
183
184 template<>
185 struct __is_integral_helper<unsigned char>
186 : public true_type { };
187
53dc5044 188#ifdef _GLIBCXX_USE_WCHAR_T
123c516a
PC
189 template<>
190 struct __is_integral_helper<wchar_t>
191 : public true_type { };
53dc5044 192#endif
123c516a
PC
193
194 template<>
195 struct __is_integral_helper<char16_t>
196 : public true_type { };
197
198 template<>
199 struct __is_integral_helper<char32_t>
200 : public true_type { };
201
202 template<>
203 struct __is_integral_helper<short>
204 : public true_type { };
205
206 template<>
207 struct __is_integral_helper<unsigned short>
208 : public true_type { };
209
210 template<>
211 struct __is_integral_helper<int>
212 : public true_type { };
213
214 template<>
215 struct __is_integral_helper<unsigned int>
216 : public true_type { };
217
218 template<>
219 struct __is_integral_helper<long>
220 : public true_type { };
221
222 template<>
223 struct __is_integral_helper<unsigned long>
224 : public true_type { };
225
226 template<>
227 struct __is_integral_helper<long long>
228 : public true_type { };
229
230 template<>
231 struct __is_integral_helper<unsigned long long>
232 : public true_type { };
53dc5044 233
6d585f01
PC
234#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
235 template<>
fd1e62c2 236 struct __is_integral_helper<__int128>
6d585f01
PC
237 : public true_type { };
238
239 template<>
fd1e62c2 240 struct __is_integral_helper<unsigned __int128>
6d585f01
PC
241 : public true_type { };
242#endif
243
53dc5044
PC
244 /// is_integral
245 template<typename _Tp>
246 struct is_integral
247 : public integral_constant<bool, (__is_integral_helper<typename
248 remove_cv<_Tp>::type>::value)>
249 { };
250
251 template<typename>
252 struct __is_floating_point_helper
253 : public false_type { };
123c516a
PC
254
255 template<>
256 struct __is_floating_point_helper<float>
257 : public true_type { };
258
259 template<>
260 struct __is_floating_point_helper<double>
261 : public true_type { };
262
263 template<>
264 struct __is_floating_point_helper<long double>
265 : public true_type { };
53dc5044 266
6d585f01
PC
267#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
268 template<>
269 struct __is_floating_point_helper<__float128>
270 : public true_type { };
271#endif
272
53dc5044
PC
273 /// is_floating_point
274 template<typename _Tp>
275 struct is_floating_point
276 : public integral_constant<bool, (__is_floating_point_helper<typename
277 remove_cv<_Tp>::type>::value)>
278 { };
279
280 /// is_array
281 template<typename>
282 struct is_array
283 : public false_type { };
284
285 template<typename _Tp, std::size_t _Size>
286 struct is_array<_Tp[_Size]>
287 : public true_type { };
288
289 template<typename _Tp>
290 struct is_array<_Tp[]>
291 : public true_type { };
292
293 template<typename>
294 struct __is_pointer_helper
295 : public false_type { };
123c516a
PC
296
297 template<typename _Tp>
298 struct __is_pointer_helper<_Tp*>
299 : public true_type { };
53dc5044
PC
300
301 /// is_pointer
302 template<typename _Tp>
303 struct is_pointer
304 : public integral_constant<bool, (__is_pointer_helper<typename
305 remove_cv<_Tp>::type>::value)>
306 { };
307
123c516a
PC
308 /// is_lvalue_reference
309 template<typename>
310 struct is_lvalue_reference
311 : public false_type { };
312
53dc5044 313 template<typename _Tp>
123c516a
PC
314 struct is_lvalue_reference<_Tp&>
315 : public true_type { };
316
317 /// is_rvalue_reference
318 template<typename>
319 struct is_rvalue_reference
320 : public false_type { };
53dc5044 321
53dc5044 322 template<typename _Tp>
123c516a
PC
323 struct is_rvalue_reference<_Tp&&>
324 : public true_type { };
325
326 template<typename>
53dc5044
PC
327 struct is_function;
328
329 template<typename>
330 struct __is_member_object_pointer_helper
331 : public false_type { };
123c516a
PC
332
333 template<typename _Tp, typename _Cp>
334 struct __is_member_object_pointer_helper<_Tp _Cp::*>
335 : public integral_constant<bool, !is_function<_Tp>::value> { };
53dc5044
PC
336
337 /// is_member_object_pointer
338 template<typename _Tp>
339 struct is_member_object_pointer
340 : public integral_constant<bool, (__is_member_object_pointer_helper<
341 typename remove_cv<_Tp>::type>::value)>
342 { };
343
344 template<typename>
345 struct __is_member_function_pointer_helper
346 : public false_type { };
123c516a
PC
347
348 template<typename _Tp, typename _Cp>
349 struct __is_member_function_pointer_helper<_Tp _Cp::*>
350 : public integral_constant<bool, is_function<_Tp>::value> { };
53dc5044
PC
351
352 /// is_member_function_pointer
353 template<typename _Tp>
354 struct is_member_function_pointer
355 : public integral_constant<bool, (__is_member_function_pointer_helper<
356 typename remove_cv<_Tp>::type>::value)>
357 { };
358
359 /// is_enum
360 template<typename _Tp>
361 struct is_enum
362 : public integral_constant<bool, __is_enum(_Tp)>
363 { };
364
365 /// is_union
366 template<typename _Tp>
367 struct is_union
368 : public integral_constant<bool, __is_union(_Tp)>
369 { };
370
371 /// is_class
372 template<typename _Tp>
373 struct is_class
374 : public integral_constant<bool, __is_class(_Tp)>
375 { };
376
377 /// is_function
378 template<typename>
379 struct is_function
380 : public false_type { };
123c516a 381
53dc5044
PC
382 template<typename _Res, typename... _ArgTypes>
383 struct is_function<_Res(_ArgTypes...)>
384 : public true_type { };
123c516a 385
53dc5044
PC
386 template<typename _Res, typename... _ArgTypes>
387 struct is_function<_Res(_ArgTypes......)>
388 : public true_type { };
123c516a 389
53dc5044
PC
390 template<typename _Res, typename... _ArgTypes>
391 struct is_function<_Res(_ArgTypes...) const>
392 : public true_type { };
123c516a 393
53dc5044
PC
394 template<typename _Res, typename... _ArgTypes>
395 struct is_function<_Res(_ArgTypes......) const>
396 : public true_type { };
123c516a 397
53dc5044
PC
398 template<typename _Res, typename... _ArgTypes>
399 struct is_function<_Res(_ArgTypes...) volatile>
400 : public true_type { };
123c516a 401
53dc5044
PC
402 template<typename _Res, typename... _ArgTypes>
403 struct is_function<_Res(_ArgTypes......) volatile>
404 : public true_type { };
123c516a 405
53dc5044
PC
406 template<typename _Res, typename... _ArgTypes>
407 struct is_function<_Res(_ArgTypes...) const volatile>
408 : public true_type { };
123c516a 409
53dc5044
PC
410 template<typename _Res, typename... _ArgTypes>
411 struct is_function<_Res(_ArgTypes......) const volatile>
412 : public true_type { };
413
1e673415
PC
414 template<typename>
415 struct __is_nullptr_t_helper
416 : public false_type { };
123c516a
PC
417
418 template<>
419 struct __is_nullptr_t_helper<std::nullptr_t>
420 : public true_type { };
1e673415
PC
421
422 // __is_nullptr_t (extension).
423 template<typename _Tp>
424 struct __is_nullptr_t
425 : public integral_constant<bool, (__is_nullptr_t_helper<typename
426 remove_cv<_Tp>::type>::value)>
427 { };
428
123c516a
PC
429 // composite type categories.
430
431 /// is_reference
432 template<typename _Tp>
433 struct is_reference
434 : public __or_<is_lvalue_reference<_Tp>,
435 is_rvalue_reference<_Tp>>::type
436 { };
437
53dc5044
PC
438 /// is_arithmetic
439 template<typename _Tp>
440 struct is_arithmetic
123c516a 441 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
53dc5044
PC
442 { };
443
444 /// is_fundamental
445 template<typename _Tp>
446 struct is_fundamental
123c516a 447 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>>::type
53dc5044
PC
448 { };
449
450 /// is_object
451 template<typename _Tp>
452 struct is_object
123c516a
PC
453 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
454 is_void<_Tp>>>::type
53dc5044
PC
455 { };
456
123c516a 457 template<typename>
53dc5044
PC
458 struct is_member_pointer;
459
460 /// is_scalar
461 template<typename _Tp>
462 struct is_scalar
123c516a
PC
463 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
464 is_member_pointer<_Tp>, __is_nullptr_t<_Tp>>::type
53dc5044
PC
465 { };
466
467 /// is_compound
468 template<typename _Tp>
469 struct is_compound
470 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
471
53dc5044
PC
472 template<typename _Tp>
473 struct __is_member_pointer_helper
474 : public false_type { };
123c516a
PC
475
476 template<typename _Tp, typename _Cp>
477 struct __is_member_pointer_helper<_Tp _Cp::*>
478 : public true_type { };
53dc5044 479
13901e4b 480 /// is_member_pointer
53dc5044 481 template<typename _Tp>
123c516a 482 struct is_member_pointer
53dc5044
PC
483 : public integral_constant<bool, (__is_member_pointer_helper<
484 typename remove_cv<_Tp>::type>::value)>
485 { };
486
487 // type properties.
123c516a 488
53dc5044
PC
489 /// is_const
490 template<typename>
491 struct is_const
492 : public false_type { };
493
494 template<typename _Tp>
495 struct is_const<_Tp const>
496 : public true_type { };
497
498 /// is_volatile
499 template<typename>
500 struct is_volatile
501 : public false_type { };
502
503 template<typename _Tp>
504 struct is_volatile<_Tp volatile>
505 : public true_type { };
506
123c516a
PC
507 /// is_trivial
508 template<typename _Tp>
509 struct is_trivial
510 : public integral_constant<bool, __is_trivial(_Tp)>
511 { };
512
13901e4b 513 // is_trivially_copyable (still unimplemented)
123c516a
PC
514
515 /// is_standard_layout
516 template<typename _Tp>
517 struct is_standard_layout
518 : public integral_constant<bool, __is_standard_layout(_Tp)>
519 { };
520
521 /// is_pod
522 // Could use is_standard_layout && is_trivial instead of the builtin.
523 template<typename _Tp>
524 struct is_pod
525 : public integral_constant<bool, __is_pod(_Tp)>
526 { };
527
528 /// is_literal_type
529 template<typename _Tp>
530 struct is_literal_type
531 : public integral_constant<bool, __is_literal_type(_Tp)>
532 { };
533
53dc5044
PC
534 /// is_empty
535 template<typename _Tp>
536 struct is_empty
537 : public integral_constant<bool, __is_empty(_Tp)>
538 { };
539
540 /// is_polymorphic
541 template<typename _Tp>
542 struct is_polymorphic
543 : public integral_constant<bool, __is_polymorphic(_Tp)>
544 { };
545
546 /// is_abstract
547 template<typename _Tp>
548 struct is_abstract
549 : public integral_constant<bool, __is_abstract(_Tp)>
550 { };
551
123c516a
PC
552 template<typename _Tp,
553 bool = is_integral<_Tp>::value,
554 bool = is_floating_point<_Tp>::value>
555 struct __is_signed_helper
556 : public false_type { };
557
53dc5044 558 template<typename _Tp>
123c516a
PC
559 struct __is_signed_helper<_Tp, false, true>
560 : public true_type { };
561
562 template<typename _Tp>
563 struct __is_signed_helper<_Tp, true, false>
564 : public integral_constant<bool, static_cast<bool>(_Tp(-1) < _Tp(0))>
53dc5044
PC
565 { };
566
123c516a 567 /// is_signed
53dc5044 568 template<typename _Tp>
123c516a
PC
569 struct is_signed
570 : public integral_constant<bool, __is_signed_helper<_Tp>::value>
571 { };
572
573 /// is_unsigned
574 template<typename _Tp>
575 struct is_unsigned
576 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
577 { };
578
579
580 // destructible and constructible type properties
581
53dc5044 582 template<typename>
123c516a 583 struct add_rvalue_reference;
53dc5044 584
13901e4b
JW
585 /**
586 * @brief Utility to simplify expressions used in unevaluated operands
587 * @ingroup utilities
588 */
53dc5044 589 template<typename _Tp>
123c516a 590 typename add_rvalue_reference<_Tp>::type declval() noexcept;
53dc5044 591
123c516a
PC
592 template<typename, unsigned = 0>
593 struct extent;
594
595 template<typename>
596 struct remove_all_extents;
597
598 template<typename _Tp>
599 struct __is_array_known_bounds
600 : public integral_constant<bool, (extent<_Tp>::value > 0)>
53dc5044
PC
601 { };
602
123c516a
PC
603 template<typename _Tp>
604 struct __is_array_unknown_bounds
605 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type
53dc5044 606 { };
2c7a09d7 607
62fa805f 608 // In N3290 is_destructible does not say anything about function
2c7a09d7 609 // types and abstract types, see LWG 2049. This implementation
62fa805f
DK
610 // describes function types as non-destructible and all complete
611 // object types as destructible, iff the explicit destructor
2c7a09d7 612 // call expression is wellformed.
62fa805f 613 struct __do_is_destructible_impl
123c516a 614 {
62fa805f 615 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
123c516a
PC
616 static true_type __test(int);
617
618 template<typename>
619 static false_type __test(...);
620 };
53dc5044
PC
621
622 template<typename _Tp>
62fa805f
DK
623 struct __is_destructible_impl
624 : public __do_is_destructible_impl
123c516a
PC
625 {
626 typedef decltype(__test<_Tp>(0)) type;
627 };
53dc5044 628
62fa805f
DK
629 template<typename _Tp,
630 bool = __or_<is_void<_Tp>,
631 __is_array_unknown_bounds<_Tp>,
632 is_function<_Tp>>::value,
633 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
634 struct __is_destructible_safe;
635
636 template<typename _Tp>
637 struct __is_destructible_safe<_Tp, false, false>
638 : public __is_destructible_impl<typename
639 remove_all_extents<_Tp>::type>::type
640 { };
641
642 template<typename _Tp>
643 struct __is_destructible_safe<_Tp, true, false>
644 : public false_type { };
645
646 template<typename _Tp>
647 struct __is_destructible_safe<_Tp, false, true>
648 : public true_type { };
649
650 /// is_destructible
651 template<typename _Tp>
652 struct is_destructible
653 : public integral_constant<bool, (__is_destructible_safe<_Tp>::value)>
654 { };
655
656 // is_nothrow_destructible requires that is_destructible is
657 // satisfied as well. We realize that by mimicing the
658 // implementation of is_destructible but refer to noexcept(expr)
659 // instead of decltype(expr).
660 struct __do_is_nt_destructible_impl
123c516a 661 {
62fa805f
DK
662 template<typename _Tp>
663 static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())>
664 __test(int);
123c516a
PC
665
666 template<typename>
667 static false_type __test(...);
668 };
53dc5044 669
53dc5044 670 template<typename _Tp>
62fa805f
DK
671 struct __is_nt_destructible_impl
672 : public __do_is_nt_destructible_impl
123c516a
PC
673 {
674 typedef decltype(__test<_Tp>(0)) type;
675 };
676
677 template<typename _Tp,
678 bool = __or_<is_void<_Tp>,
62fa805f
DK
679 __is_array_unknown_bounds<_Tp>,
680 is_function<_Tp>>::value,
681 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
682 struct __is_nt_destructible_safe;
53dc5044
PC
683
684 template<typename _Tp>
62fa805f
DK
685 struct __is_nt_destructible_safe<_Tp, false, false>
686 : public __is_nt_destructible_impl<typename
687 remove_all_extents<_Tp>::type>::type
123c516a
PC
688 { };
689
53dc5044 690 template<typename _Tp>
62fa805f 691 struct __is_nt_destructible_safe<_Tp, true, false>
123c516a 692 : public false_type { };
53dc5044
PC
693
694 template<typename _Tp>
62fa805f 695 struct __is_nt_destructible_safe<_Tp, false, true>
123c516a
PC
696 : public true_type { };
697
62fa805f 698 /// is_nothrow_destructible
53dc5044 699 template<typename _Tp>
62fa805f
DK
700 struct is_nothrow_destructible
701 : public integral_constant<bool, (__is_nt_destructible_safe<_Tp>::value)>
123c516a
PC
702 { };
703
704 struct __do_is_default_constructible_impl
705 {
706 template<typename _Tp, typename = decltype(_Tp())>
707 static true_type __test(int);
708
709 template<typename>
710 static false_type __test(...);
711 };
712
713 template<typename _Tp>
714 struct __is_default_constructible_impl
715 : public __do_is_default_constructible_impl
53dc5044 716 {
123c516a 717 typedef decltype(__test<_Tp>(0)) type;
53dc5044 718 };
53dc5044
PC
719
720 template<typename _Tp>
123c516a 721 struct __is_default_constructible_atom
2c7a09d7
PC
722 : public __and_<__not_<is_void<_Tp>>,
723 __is_default_constructible_impl<_Tp>>::type
123c516a 724 { };
53dc5044 725
123c516a
PC
726 template<typename _Tp, bool = is_array<_Tp>::value>
727 struct __is_default_constructible_safe;
53dc5044 728
2c7a09d7
PC
729 // The following technique is a workaround for a current core language
730 // restriction, which does not allow for array types to occur in
731 // functional casts of the form T(). Complete arrays can be default-
732 // constructed, if the element type is default-constructible, but
733 // arrays with unknown bounds are not.
53dc5044 734 template<typename _Tp>
123c516a
PC
735 struct __is_default_constructible_safe<_Tp, true>
736 : public __and_<__is_array_known_bounds<_Tp>,
737 __is_default_constructible_atom<typename
2c7a09d7 738 remove_all_extents<_Tp>::type>>::type
53dc5044
PC
739 { };
740
53dc5044 741 template<typename _Tp>
123c516a
PC
742 struct __is_default_constructible_safe<_Tp, false>
743 : public __is_default_constructible_atom<_Tp>::type
744 { };
4a27a739 745
123c516a 746 /// is_default_constructible
4a27a739 747 template<typename _Tp>
123c516a
PC
748 struct is_default_constructible
749 : public integral_constant<bool, (__is_default_constructible_safe<
750 _Tp>::value)>
751 { };
4a27a739 752
2c7a09d7
PC
753
754 // Implementation of is_constructible.
755
756 // The hardest part of this trait is the binary direct-initialization
757 // case, because we hit into a functional cast of the form T(arg).
758 // This implementation uses different strategies depending on the
759 // target type to reduce the test overhead as much as possible:
760 //
761 // a) For a reference target type, we use a static_cast expression
762 // modulo its extra cases.
763 //
764 // b) For a non-reference target type we use a ::new expression.
123c516a
PC
765 struct __do_is_static_castable_impl
766 {
767 template<typename _From, typename _To, typename
768 = decltype(static_cast<_To>(declval<_From>()))>
769 static true_type __test(int);
4a27a739 770
123c516a
PC
771 template<typename, typename>
772 static false_type __test(...);
773 };
4a27a739 774
123c516a
PC
775 template<typename _From, typename _To>
776 struct __is_static_castable_impl
777 : public __do_is_static_castable_impl
778 {
779 typedef decltype(__test<_From, _To>(0)) type;
780 };
939759fc 781
123c516a
PC
782 template<typename _From, typename _To>
783 struct __is_static_castable_safe
2c7a09d7 784 : public __is_static_castable_impl<_From, _To>::type
4a27a739
PC
785 { };
786
123c516a
PC
787 // __is_static_castable
788 template<typename _From, typename _To>
789 struct __is_static_castable
790 : public integral_constant<bool, (__is_static_castable_safe<
791 _From, _To>::value)>
792 { };
939759fc 793
2c7a09d7
PC
794 // Implementation for non-reference types. To meet the proper
795 // variable definition semantics, we also need to test for
796 // is_destructible in this case.
5db25ab1
DK
797 // This form should be simplified by a single expression:
798 // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
123c516a
PC
799 struct __do_is_direct_constructible_impl
800 {
801 template<typename _Tp, typename _Arg, typename
802 = decltype(::new _Tp(declval<_Arg>()))>
803 static true_type __test(int);
4a27a739 804
123c516a
PC
805 template<typename, typename>
806 static false_type __test(...);
807 };
4a27a739 808
123c516a
PC
809 template<typename _Tp, typename _Arg>
810 struct __is_direct_constructible_impl
811 : public __do_is_direct_constructible_impl
812 {
813 typedef decltype(__test<_Tp, _Arg>(0)) type;
814 };
4a27a739 815
123c516a
PC
816 template<typename _Tp, typename _Arg>
817 struct __is_direct_constructible_new_safe
818 : public __and_<is_destructible<_Tp>,
2c7a09d7 819 __is_direct_constructible_impl<_Tp, _Arg>>::type
123c516a 820 { };
4a27a739 821
123c516a
PC
822 template<typename, typename>
823 struct is_same;
4a27a739 824
123c516a
PC
825 template<typename, typename>
826 struct is_base_of;
4a27a739 827
123c516a
PC
828 template<typename>
829 struct remove_reference;
4a27a739 830
123c516a 831 template<typename _From, typename _To, bool
5db25ab1
DK
832 = __not_<__or_<is_void<_From>,
833 is_function<_From>>>::value>
123c516a 834 struct __is_base_to_derived_ref;
4a27a739 835
5db25ab1
DK
836 // Detect whether we have a downcast situation during
837 // reference binding.
123c516a
PC
838 template<typename _From, typename _To>
839 struct __is_base_to_derived_ref<_From, _To, true>
840 {
841 typedef typename remove_cv<typename remove_reference<_From
842 >::type>::type __src_t;
843 typedef typename remove_cv<typename remove_reference<_To
844 >::type>::type __dst_t;
2c7a09d7
PC
845 typedef __and_<__not_<is_same<__src_t, __dst_t>>,
846 is_base_of<__src_t, __dst_t>> type;
123c516a
PC
847 static constexpr bool value = type::value;
848 };
4a27a739 849
123c516a
PC
850 template<typename _From, typename _To>
851 struct __is_base_to_derived_ref<_From, _To, false>
852 : public false_type
4a27a739
PC
853 { };
854
123c516a
PC
855 template<typename _From, typename _To, bool
856 = __and_<is_lvalue_reference<_From>,
857 is_rvalue_reference<_To>>::value>
858 struct __is_lvalue_to_rvalue_ref;
e133ace8 859
5db25ab1
DK
860 // Detect whether we have an lvalue of non-function type
861 // bound to a reference-compatible rvalue-reference.
123c516a
PC
862 template<typename _From, typename _To>
863 struct __is_lvalue_to_rvalue_ref<_From, _To, true>
864 {
865 typedef typename remove_cv<typename remove_reference<
866 _From>::type>::type __src_t;
867 typedef typename remove_cv<typename remove_reference<
868 _To>::type>::type __dst_t;
5db25ab1
DK
869 typedef __and_<__not_<is_function<__src_t>>,
870 __or_<is_same<__src_t, __dst_t>,
871 is_base_of<__dst_t, __src_t>>> type;
123c516a
PC
872 static constexpr bool value = type::value;
873 };
e133ace8 874
123c516a
PC
875 template<typename _From, typename _To>
876 struct __is_lvalue_to_rvalue_ref<_From, _To, false>
877 : public false_type
e133ace8
PC
878 { };
879
2c7a09d7
PC
880 // Here we handle direct-initialization to a reference type as
881 // equivalent to a static_cast modulo overshooting conversions.
882 // These are restricted to the following conversions:
5db25ab1 883 // a) A base class value to a derived class reference
2c7a09d7 884 // b) An lvalue to an rvalue-reference of reference-compatible
5db25ab1 885 // types that are not functions
123c516a
PC
886 template<typename _Tp, typename _Arg>
887 struct __is_direct_constructible_ref_cast
888 : public __and_<__is_static_castable<_Arg, _Tp>,
889 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
890 __is_lvalue_to_rvalue_ref<_Arg, _Tp>
2c7a09d7 891 >>>::type
e133ace8
PC
892 { };
893
123c516a
PC
894 template<typename _Tp, typename _Arg>
895 struct __is_direct_constructible_new
896 : public conditional<is_reference<_Tp>::value,
897 __is_direct_constructible_ref_cast<_Tp, _Arg>,
898 __is_direct_constructible_new_safe<_Tp, _Arg>
899 >::type
b0302c68
PC
900 { };
901
123c516a
PC
902 template<typename _Tp, typename _Arg>
903 struct __is_direct_constructible
904 : public integral_constant<bool, (__is_direct_constructible_new<
2c7a09d7 905 _Tp, _Arg>::value)>
e133ace8
PC
906 { };
907
2c7a09d7
PC
908 // Since default-construction and binary direct-initialization have
909 // been handled separately, the implementation of the remaining
5db25ab1
DK
910 // n-ary construction cases is rather straightforward. We can use
911 // here a functional cast, because array types are excluded anyway
912 // and this form is never interpreted as a C cast.
123c516a
PC
913 struct __do_is_nary_constructible_impl
914 {
915 template<typename _Tp, typename... _Args, typename
916 = decltype(_Tp(declval<_Args>()...))>
917 static true_type __test(int);
2b08f2c5 918
123c516a
PC
919 template<typename, typename...>
920 static false_type __test(...);
921 };
b0302c68
PC
922
923 template<typename _Tp, typename... _Args>
123c516a
PC
924 struct __is_nary_constructible_impl
925 : public __do_is_nary_constructible_impl
b0302c68 926 {
123c516a 927 typedef decltype(__test<_Tp, _Args...>(0)) type;
b0302c68
PC
928 };
929
123c516a
PC
930 template<typename _Tp, typename... _Args>
931 struct __is_nary_constructible
2c7a09d7 932 : public __is_nary_constructible_impl<_Tp, _Args...>::type
b0302c68 933 {
123c516a
PC
934 static_assert(sizeof...(_Args) > 1,
935 "Only useful for > 1 arguments");
936 };
b0302c68 937
123c516a
PC
938 template<typename _Tp, typename... _Args>
939 struct __is_constructible_impl
940 : public __is_nary_constructible<_Tp, _Args...>
941 { };
b0302c68 942
123c516a
PC
943 template<typename _Tp, typename _Arg>
944 struct __is_constructible_impl<_Tp, _Arg>
945 : public __is_direct_constructible<_Tp, _Arg>
946 { };
947
948 template<typename _Tp>
949 struct __is_constructible_impl<_Tp>
950 : public is_default_constructible<_Tp>
951 { };
b0302c68
PC
952
953 /// is_constructible
b0302c68
PC
954 template<typename _Tp, typename... _Args>
955 struct is_constructible
123c516a
PC
956 : public integral_constant<bool, (__is_constructible_impl<_Tp,
957 _Args...>::value)>
c32097d8
JM
958 { };
959
65cee9bd
PC
960 template<typename _Tp, bool = is_void<_Tp>::value>
961 struct __is_copy_constructible_impl;
123c516a 962
65cee9bd
PC
963 template<typename _Tp>
964 struct __is_copy_constructible_impl<_Tp, true>
965 : public false_type { };
966
967 template<typename _Tp>
968 struct __is_copy_constructible_impl<_Tp, false>
969 : public is_constructible<_Tp, const _Tp&>
970 { };
971
972 /// is_copy_constructible
973 template<typename _Tp>
974 struct is_copy_constructible
975 : public __is_copy_constructible_impl<_Tp>
976 { };
977
978 template<typename _Tp, bool = is_void<_Tp>::value>
979 struct __is_move_constructible_impl;
980
981 template<typename _Tp>
982 struct __is_move_constructible_impl<_Tp, true>
983 : public false_type { };
984
985 template<typename _Tp>
986 struct __is_move_constructible_impl<_Tp, false>
987 : public is_constructible<_Tp, _Tp&&>
988 { };
989
990 /// is_move_constructible
991 template<typename _Tp>
992 struct is_move_constructible
993 : public __is_move_constructible_impl<_Tp>
994 { };
995
996 template<typename _Tp>
997 struct __is_nt_default_constructible_atom
998 : public integral_constant<bool, noexcept(_Tp())>
999 { };
1000
1001 template<typename _Tp, bool = is_array<_Tp>::value>
1002 struct __is_nt_default_constructible_impl;
1003
1004 template<typename _Tp>
1005 struct __is_nt_default_constructible_impl<_Tp, true>
1006 : public __and_<__is_array_known_bounds<_Tp>,
1007 __is_nt_default_constructible_atom<typename
1008 remove_all_extents<_Tp>::type>>::type
1009 { };
1010
1011 template<typename _Tp>
1012 struct __is_nt_default_constructible_impl<_Tp, false>
1013 : public __is_nt_default_constructible_atom<_Tp>
1014 { };
1015
1016 /// is_nothrow_default_constructible
1017 template<typename _Tp>
1018 struct is_nothrow_default_constructible
1019 : public __and_<is_default_constructible<_Tp>,
1020 __is_nt_default_constructible_impl<_Tp>>::type
1021 { };
e4f32cb0
PC
1022
1023 template<typename _Tp, typename... _Args>
65cee9bd
PC
1024 struct __is_nt_constructible_impl
1025 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1026 { };
e4f32cb0
PC
1027
1028 template<typename _Tp, typename _Arg>
65cee9bd
PC
1029 struct __is_nt_constructible_impl<_Tp, _Arg>
1030 : public integral_constant<bool,
1031 noexcept(static_cast<_Tp>(declval<_Arg>()))>
1032 { };
1033
1034 template<typename _Tp>
1035 struct __is_nt_constructible_impl<_Tp>
1036 : public is_nothrow_default_constructible<_Tp>
1037 { };
e4f32cb0
PC
1038
1039 /// is_nothrow_constructible
1040 template<typename _Tp, typename... _Args>
1041 struct is_nothrow_constructible
65cee9bd
PC
1042 : public __and_<is_constructible<_Tp, _Args...>,
1043 __is_nt_constructible_impl<_Tp, _Args...>>::type
1044 { };
1045
1046 template<typename _Tp, bool = is_void<_Tp>::value>
1047 struct __is_nothrow_copy_constructible_impl;
1048
1049 template<typename _Tp>
1050 struct __is_nothrow_copy_constructible_impl<_Tp, true>
1051 : public false_type { };
1052
1053 template<typename _Tp>
1054 struct __is_nothrow_copy_constructible_impl<_Tp, false>
1055 : public is_nothrow_constructible<_Tp, const _Tp&>
1056 { };
1057
1058 /// is_nothrow_copy_constructible
1059 template<typename _Tp>
1060 struct is_nothrow_copy_constructible
1061 : public __is_nothrow_copy_constructible_impl<_Tp>
1062 { };
1063
1064 template<typename _Tp, bool = is_void<_Tp>::value>
1065 struct __is_nothrow_move_constructible_impl;
1066
1067 template<typename _Tp>
1068 struct __is_nothrow_move_constructible_impl<_Tp, true>
1069 : public false_type { };
1070
1071 template<typename _Tp>
1072 struct __is_nothrow_move_constructible_impl<_Tp, false>
1073 : public is_nothrow_constructible<_Tp, _Tp&&>
1074 { };
1075
1076 /// is_nothrow_move_constructible
1077 template<typename _Tp>
1078 struct is_nothrow_move_constructible
1079 : public __is_nothrow_move_constructible_impl<_Tp>
1080 { };
1081
f263981a
PC
1082 template<typename _Tp, typename _Up>
1083 class __is_assignable_helper
1084 : public __sfinae_types
1085 {
1086 template<typename _Tp1, typename _Up1>
1087 static decltype(declval<_Tp1>() = declval<_Up1>(), __one())
1088 __test(int);
1089
1090 template<typename, typename>
1091 static __two __test(...);
1092
1093 public:
1094 static constexpr bool value = sizeof(__test<_Tp, _Up>(0)) == 1;
1095 };
1096
1097 /// is_assignable
1098 template<typename _Tp, typename _Up>
1099 struct is_assignable
1100 : public integral_constant<bool,
1101 __is_assignable_helper<_Tp, _Up>::value>
1102 { };
1103
1104 template<typename _Tp, bool = is_void<_Tp>::value>
1105 struct __is_copy_assignable_impl;
1106
1107 template<typename _Tp>
1108 struct __is_copy_assignable_impl<_Tp, true>
1109 : public false_type { };
1110
1111 template<typename _Tp>
1112 struct __is_copy_assignable_impl<_Tp, false>
9b3a81da 1113 : public is_assignable<_Tp&, const _Tp&>
f263981a
PC
1114 { };
1115
1116 /// is_copy_assignable
1117 template<typename _Tp>
1118 struct is_copy_assignable
1119 : public __is_copy_assignable_impl<_Tp>
1120 { };
1121
1122 template<typename _Tp, bool = is_void<_Tp>::value>
1123 struct __is_move_assignable_impl;
1124
1125 template<typename _Tp>
1126 struct __is_move_assignable_impl<_Tp, true>
1127 : public false_type { };
1128
1129 template<typename _Tp>
1130 struct __is_move_assignable_impl<_Tp, false>
1131 : public is_assignable<_Tp&, _Tp&&>
1132 { };
1133
1134 /// is_move_assignable
1135 template<typename _Tp>
1136 struct is_move_assignable
1137 : public __is_move_assignable_impl<_Tp>
1138 { };
1139
1140 template<typename _Tp, typename _Up>
1141 struct __is_nt_assignable_impl
1142 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1143 { };
1144
1145 /// is_nothrow_assignable
1146 template<typename _Tp, typename _Up>
1147 struct is_nothrow_assignable
1148 : public __and_<is_assignable<_Tp, _Up>,
1149 __is_nt_assignable_impl<_Tp, _Up>>::type
1150 { };
1151
1152 template<typename _Tp, bool = is_void<_Tp>::value>
1153 struct __is_nt_copy_assignable_impl;
1154
1155 template<typename _Tp>
1156 struct __is_nt_copy_assignable_impl<_Tp, true>
1157 : public false_type { };
1158
1159 template<typename _Tp>
1160 struct __is_nt_copy_assignable_impl<_Tp, false>
9b3a81da 1161 : public is_nothrow_assignable<_Tp&, const _Tp&>
f263981a
PC
1162 { };
1163
1164 /// is_nothrow_copy_assignable
1165 template<typename _Tp>
1166 struct is_nothrow_copy_assignable
1167 : public __is_nt_copy_assignable_impl<_Tp>
1168 { };
1169
1170 template<typename _Tp, bool = is_void<_Tp>::value>
1171 struct __is_nt_move_assignable_impl;
1172
1173 template<typename _Tp>
1174 struct __is_nt_move_assignable_impl<_Tp, true>
1175 : public false_type { };
1176
1177 template<typename _Tp>
1178 struct __is_nt_move_assignable_impl<_Tp, false>
1179 : public is_nothrow_assignable<_Tp&, _Tp&&>
1180 { };
1181
1182 /// is_nothrow_move_assignable
65cee9bd 1183 template<typename _Tp>
f263981a
PC
1184 struct is_nothrow_move_assignable
1185 : public __is_nt_move_assignable_impl<_Tp>
e4f32cb0
PC
1186 { };
1187
6a9ecd34
PC
1188 /// is_trivially_constructible (still unimplemented)
1189
1190 /// is_trivially_default_constructible (still unimplemented)
1191
1192 /// is_trivially_copy_constructible (still unimplemented)
1193
1194 /// is_trivially_move_constructible (still unimplemented)
1195
1196 /// is_trivially_assignable (still unimplemented)
1197
1198 /// is_trivially_copy_assignable (still unimplemented)
1199
1200 /// is_trivially_move_assignable (still unimplemented)
1201
1202 /// is_trivially_destructible
1203 template<typename _Tp>
1204 struct is_trivially_destructible
1205 : public __and_<is_destructible<_Tp>, integral_constant<bool,
1206 __has_trivial_destructor(_Tp)>>::type
1207 { };
1208
1209 /// has_trivial_default_constructor (temporary legacy)
e133ace8
PC
1210 template<typename _Tp>
1211 struct has_trivial_default_constructor
1212 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
1213 { };
1214
6a9ecd34 1215 /// has_trivial_copy_constructor (temporary legacy)
e133ace8
PC
1216 template<typename _Tp>
1217 struct has_trivial_copy_constructor
1218 : public integral_constant<bool, __has_trivial_copy(_Tp)>
1219 { };
1220
6a9ecd34 1221 /// has_trivial_copy_assign (temporary legacy)
e133ace8 1222 template<typename _Tp>
6f5e9b8d 1223 struct has_trivial_copy_assign
e133ace8
PC
1224 : public integral_constant<bool, __has_trivial_assign(_Tp)>
1225 { };
1226
123c516a
PC
1227 /// has_virtual_destructor
1228 template<typename _Tp>
1229 struct has_virtual_destructor
1230 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1231 { };
1232
1233
1234 // type property queries.
1235
1236 /// alignment_of
1237 template<typename _Tp>
1238 struct alignment_of
1239 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1240
1241 /// rank
1242 template<typename>
1243 struct rank
1244 : public integral_constant<std::size_t, 0> { };
1245
1246 template<typename _Tp, std::size_t _Size>
1247 struct rank<_Tp[_Size]>
1248 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1249
1250 template<typename _Tp>
1251 struct rank<_Tp[]>
1252 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1253
1254 /// extent
1255 template<typename, unsigned _Uint>
1256 struct extent
1257 : public integral_constant<std::size_t, 0> { };
1258
1259 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1260 struct extent<_Tp[_Size], _Uint>
1261 : public integral_constant<std::size_t,
1262 _Uint == 0 ? _Size : extent<_Tp,
1263 _Uint - 1>::value>
1264 { };
1265
1266 template<typename _Tp, unsigned _Uint>
1267 struct extent<_Tp[], _Uint>
1268 : public integral_constant<std::size_t,
1269 _Uint == 0 ? 0 : extent<_Tp,
1270 _Uint - 1>::value>
1271 { };
1272
1273
1274 // type relations.
1275
1276 /// is_same
1277 template<typename, typename>
1278 struct is_same
1279 : public false_type { };
1280
1281 template<typename _Tp>
1282 struct is_same<_Tp, _Tp>
1283 : public true_type { };
b0302c68 1284
939759fc 1285 /// is_base_of
e133ace8
PC
1286 template<typename _Base, typename _Derived>
1287 struct is_base_of
1288 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1289 { };
1290
297f34d7 1291 template<typename _From, typename _To,
123c516a
PC
1292 bool = __or_<is_void<_From>, is_function<_To>,
1293 is_array<_To>>::value>
297f34d7 1294 struct __is_convertible_helper
f263981a 1295 { static constexpr bool value = is_void<_To>::value; };
297f34d7 1296
e133ace8 1297 template<typename _From, typename _To>
b0302c68 1298 class __is_convertible_helper<_From, _To, false>
e133ace8
PC
1299 : public __sfinae_types
1300 {
8e7d962a
PC
1301 template<typename _To1>
1302 static void __test_aux(_To1);
1303
1304 template<typename _From1, typename _To1>
1305 static decltype(__test_aux<_To1>(std::declval<_From1>()), __one())
1306 __test(int);
1307
1308 template<typename, typename>
1309 static __two __test(...);
297f34d7 1310
e133ace8 1311 public:
f263981a 1312 static constexpr bool value = sizeof(__test<_From, _To>(0)) == 1;
e133ace8
PC
1313 };
1314
b0302c68 1315 /// is_convertible
e133ace8
PC
1316 template<typename _From, typename _To>
1317 struct is_convertible
1318 : public integral_constant<bool,
f263981a 1319 __is_convertible_helper<_From, _To>::value>
e133ace8
PC
1320 { };
1321
fd735b6a 1322
123c516a 1323 // const-volatile modifications.
7b50cdef 1324
123c516a 1325 /// remove_const
7b50cdef 1326 template<typename _Tp>
123c516a
PC
1327 struct remove_const
1328 { typedef _Tp type; };
7b50cdef 1329
123c516a
PC
1330 template<typename _Tp>
1331 struct remove_const<_Tp const>
1332 { typedef _Tp type; };
1333
1334 /// remove_volatile
1335 template<typename _Tp>
1336 struct remove_volatile
1337 { typedef _Tp type; };
7b50cdef 1338
123c516a
PC
1339 template<typename _Tp>
1340 struct remove_volatile<_Tp volatile>
1341 { typedef _Tp type; };
1342
1343 /// remove_cv
1344 template<typename _Tp>
1345 struct remove_cv
1346 {
1347 typedef typename
1348 remove_const<typename remove_volatile<_Tp>::type>::type type;
1349 };
1350
1351 /// add_const
1352 template<typename _Tp>
1353 struct add_const
1354 { typedef _Tp const type; };
1355
1356 /// add_volatile
1357 template<typename _Tp>
1358 struct add_volatile
1359 { typedef _Tp volatile type; };
1360
1361 /// add_cv
1362 template<typename _Tp>
1363 struct add_cv
1364 {
1365 typedef typename
1366 add_const<typename add_volatile<_Tp>::type>::type type;
1367 };
7b50cdef 1368
7b50cdef 1369
123c516a 1370 // Reference transformations.
7b50cdef 1371
123c516a
PC
1372 /// remove_reference
1373 template<typename _Tp>
1374 struct remove_reference
1375 { typedef _Tp type; };
7b50cdef 1376
123c516a
PC
1377 template<typename _Tp>
1378 struct remove_reference<_Tp&>
1379 { typedef _Tp type; };
7b50cdef 1380
123c516a
PC
1381 template<typename _Tp>
1382 struct remove_reference<_Tp&&>
1383 { typedef _Tp type; };
1384
1385 template<typename _Tp,
1386 bool = __and_<__not_<is_reference<_Tp>>,
1387 __not_<is_void<_Tp>>>::value,
1388 bool = is_rvalue_reference<_Tp>::value>
1389 struct __add_lvalue_reference_helper
1390 { typedef _Tp type; };
7b50cdef 1391
5e108459 1392 template<typename _Tp>
123c516a
PC
1393 struct __add_lvalue_reference_helper<_Tp, true, false>
1394 { typedef _Tp& type; };
5e108459 1395
5e108459 1396 template<typename _Tp>
123c516a
PC
1397 struct __add_lvalue_reference_helper<_Tp, false, true>
1398 { typedef typename remove_reference<_Tp>::type& type; };
5e108459 1399
123c516a 1400 /// add_lvalue_reference
5e108459 1401 template<typename _Tp>
123c516a
PC
1402 struct add_lvalue_reference
1403 : public __add_lvalue_reference_helper<_Tp>
1404 { };
1405
1406 template<typename _Tp,
1407 bool = __and_<__not_<is_reference<_Tp>>,
1408 __not_<is_void<_Tp>>>::value>
1409 struct __add_rvalue_reference_helper
1410 { typedef _Tp type; };
5e108459
PC
1411
1412 template<typename _Tp>
123c516a
PC
1413 struct __add_rvalue_reference_helper<_Tp, true>
1414 { typedef _Tp&& type; };
5e108459 1415
123c516a 1416 /// add_rvalue_reference
5e108459 1417 template<typename _Tp>
123c516a
PC
1418 struct add_rvalue_reference
1419 : public __add_rvalue_reference_helper<_Tp>
1420 { };
5e108459 1421
7b50cdef 1422
123c516a
PC
1423 // sign modifications.
1424
7b50cdef
BK
1425 // Utility for constructing identically cv-qualified types.
1426 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1427 struct __cv_selector;
1428
1429 template<typename _Unqualified>
1430 struct __cv_selector<_Unqualified, false, false>
1431 { typedef _Unqualified __type; };
1432
1433 template<typename _Unqualified>
1434 struct __cv_selector<_Unqualified, false, true>
1435 { typedef volatile _Unqualified __type; };
1436
1437 template<typename _Unqualified>
1438 struct __cv_selector<_Unqualified, true, false>
1439 { typedef const _Unqualified __type; };
1440
1441 template<typename _Unqualified>
1442 struct __cv_selector<_Unqualified, true, true>
1443 { typedef const volatile _Unqualified __type; };
1444
1445 template<typename _Qualified, typename _Unqualified,
1446 bool _IsConst = is_const<_Qualified>::value,
1447 bool _IsVol = is_volatile<_Qualified>::value>
b0302c68 1448 class __match_cv_qualifiers
7b50cdef 1449 {
7b50cdef
BK
1450 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1451
1452 public:
1453 typedef typename __match::__type __type;
1454 };
1455
7b50cdef
BK
1456 // Utility for finding the unsigned versions of signed integral types.
1457 template<typename _Tp>
e133ace8
PC
1458 struct __make_unsigned
1459 { typedef _Tp __type; };
7b50cdef
BK
1460
1461 template<>
1462 struct __make_unsigned<char>
1463 { typedef unsigned char __type; };
1464
1465 template<>
1466 struct __make_unsigned<signed char>
1467 { typedef unsigned char __type; };
1468
7b50cdef
BK
1469 template<>
1470 struct __make_unsigned<short>
1471 { typedef unsigned short __type; };
1472
1473 template<>
1474 struct __make_unsigned<int>
1475 { typedef unsigned int __type; };
1476
1477 template<>
1478 struct __make_unsigned<long>
1479 { typedef unsigned long __type; };
1480
1481 template<>
1482 struct __make_unsigned<long long>
1483 { typedef unsigned long long __type; };
1484
6d585f01
PC
1485#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1486 template<>
fd1e62c2
PC
1487 struct __make_unsigned<__int128>
1488 { typedef unsigned __int128 __type; };
6d585f01
PC
1489#endif
1490
7b50cdef
BK
1491 // Select between integral and enum: not possible to be both.
1492 template<typename _Tp,
1493 bool _IsInt = is_integral<_Tp>::value,
7b50cdef 1494 bool _IsEnum = is_enum<_Tp>::value>
b0302c68
PC
1495 class __make_unsigned_selector;
1496
7b50cdef 1497 template<typename _Tp>
b0302c68 1498 class __make_unsigned_selector<_Tp, true, false>
7b50cdef 1499 {
7b50cdef
BK
1500 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1501 typedef typename __unsignedt::__type __unsigned_type;
1502 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1503
1504 public:
1505 typedef typename __cv_unsigned::__type __type;
1506 };
1507
7b50cdef 1508 template<typename _Tp>
b0302c68 1509 class __make_unsigned_selector<_Tp, false, true>
7b50cdef 1510 {
a0230468
MM
1511 // With -fshort-enums, an enum may be as small as a char.
1512 typedef unsigned char __smallest;
1513 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1514 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
ce2e6349 1515 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
a0230468
MM
1516 typedef conditional<__b2, unsigned int, unsigned long> __cond2;
1517 typedef typename __cond2::type __cond2_type;
1518 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1519 typedef typename __cond1::type __cond1_type;
7b50cdef
BK
1520
1521 public:
a0230468 1522 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
7b50cdef
BK
1523 };
1524
7b50cdef
BK
1525 // Given an integral/enum type, return the corresponding unsigned
1526 // integer type.
5b9daa7e
BK
1527 // Primary template.
1528 /// make_unsigned
7b50cdef
BK
1529 template<typename _Tp>
1530 struct make_unsigned
1531 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1532
1533 // Integral, but don't define.
1534 template<>
1535 struct make_unsigned<bool>;
1536
1537
1538 // Utility for finding the signed versions of unsigned integral types.
1539 template<typename _Tp>
e133ace8
PC
1540 struct __make_signed
1541 { typedef _Tp __type; };
7b50cdef
BK
1542
1543 template<>
1544 struct __make_signed<char>
1545 { typedef signed char __type; };
1546
1547 template<>
1548 struct __make_signed<unsigned char>
1549 { typedef signed char __type; };
1550
7b50cdef
BK
1551 template<>
1552 struct __make_signed<unsigned short>
1553 { typedef signed short __type; };
1554
1555 template<>
1556 struct __make_signed<unsigned int>
1557 { typedef signed int __type; };
1558
1559 template<>
1560 struct __make_signed<unsigned long>
1561 { typedef signed long __type; };
1562
1563 template<>
1564 struct __make_signed<unsigned long long>
1565 { typedef signed long long __type; };
1566
6d585f01
PC
1567#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
1568 template<>
fd1e62c2
PC
1569 struct __make_signed<unsigned __int128>
1570 { typedef __int128 __type; };
6d585f01
PC
1571#endif
1572
fb8ffd10 1573 // Select between integral and enum: not possible to be both.
7b50cdef
BK
1574 template<typename _Tp,
1575 bool _IsInt = is_integral<_Tp>::value,
7b50cdef 1576 bool _IsEnum = is_enum<_Tp>::value>
b0302c68
PC
1577 class __make_signed_selector;
1578
7b50cdef 1579 template<typename _Tp>
b0302c68 1580 class __make_signed_selector<_Tp, true, false>
7b50cdef 1581 {
7b50cdef
BK
1582 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1583 typedef typename __signedt::__type __signed_type;
1584 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1585
1586 public:
1587 typedef typename __cv_signed::__type __type;
1588 };
1589
7b50cdef 1590 template<typename _Tp>
b0302c68 1591 class __make_signed_selector<_Tp, false, true>
7b50cdef 1592 {
a0230468
MM
1593 // With -fshort-enums, an enum may be as small as a char.
1594 typedef signed char __smallest;
1595 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1596 static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
ce2e6349 1597 static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
a0230468
MM
1598 typedef conditional<__b2, signed int, signed long> __cond2;
1599 typedef typename __cond2::type __cond2_type;
1600 typedef conditional<__b1, signed short, __cond2_type> __cond1;
1601 typedef typename __cond1::type __cond1_type;
7b50cdef
BK
1602
1603 public:
a0230468 1604 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
7b50cdef
BK
1605 };
1606
7b50cdef
BK
1607 // Given an integral/enum type, return the corresponding signed
1608 // integer type.
5b9daa7e
BK
1609 // Primary template.
1610 /// make_signed
7b50cdef
BK
1611 template<typename _Tp>
1612 struct make_signed
1613 { typedef typename __make_signed_selector<_Tp>::__type type; };
1614
1615 // Integral, but don't define.
1616 template<>
1617 struct make_signed<bool>;
cfa9a96b 1618
123c516a
PC
1619
1620 // array modifications.
1621
1622 /// remove_extent
1623 template<typename _Tp>
1624 struct remove_extent
1625 { typedef _Tp type; };
1626
1627 template<typename _Tp, std::size_t _Size>
1628 struct remove_extent<_Tp[_Size]>
1629 { typedef _Tp type; };
1630
1631 template<typename _Tp>
1632 struct remove_extent<_Tp[]>
1633 { typedef _Tp type; };
1634
1635 /// remove_all_extents
1636 template<typename _Tp>
1637 struct remove_all_extents
1638 { typedef _Tp type; };
1639
1640 template<typename _Tp, std::size_t _Size>
1641 struct remove_all_extents<_Tp[_Size]>
1642 { typedef typename remove_all_extents<_Tp>::type type; };
1643
1644 template<typename _Tp>
1645 struct remove_all_extents<_Tp[]>
1646 { typedef typename remove_all_extents<_Tp>::type type; };
1647
1648
1649 // pointer modifications.
1650
1651 template<typename _Tp, typename>
1652 struct __remove_pointer_helper
1653 { typedef _Tp type; };
1654
1655 template<typename _Tp, typename _Up>
1656 struct __remove_pointer_helper<_Tp, _Up*>
1657 { typedef _Up type; };
1658
1659 /// remove_pointer
1660 template<typename _Tp>
1661 struct remove_pointer
1662 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1663 { };
1664
1665 /// add_pointer
1666 template<typename _Tp>
1667 struct add_pointer
1668 { typedef typename remove_reference<_Tp>::type* type; };
1669
1670
1671 template<std::size_t _Len>
1672 struct __aligned_storage_msa
1673 {
1674 union __type
1675 {
1676 unsigned char __data[_Len];
1677 struct __attribute__((__aligned__)) { } __align;
1678 };
1679 };
1680
1681 /**
1682 * @brief Alignment type.
1683 *
1684 * The value of _Align is a default-alignment which shall be the
1685 * most stringent alignment requirement for any C++ object type
1686 * whose size is no greater than _Len (3.9). The member typedef
1687 * type shall be a POD type suitable for use as uninitialized
1688 * storage for any object whose size is at most _Len and whose
1689 * alignment is a divisor of _Align.
1690 */
1691 template<std::size_t _Len, std::size_t _Align =
1692 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
1693 struct aligned_storage
1694 {
1695 union type
1696 {
1697 unsigned char __data[_Len];
1698 struct __attribute__((__aligned__((_Align)))) { } __align;
1699 };
1700 };
1701
1702
1703 // Decay trait for arrays and functions, used for perfect forwarding
1704 // in make_pair, make_tuple, etc.
1705 template<typename _Up,
1706 bool _IsArray = is_array<_Up>::value,
1707 bool _IsFunction = is_function<_Up>::value>
1708 struct __decay_selector;
1709
1710 // NB: DR 705.
1711 template<typename _Up>
1712 struct __decay_selector<_Up, false, false>
1713 { typedef typename remove_cv<_Up>::type __type; };
1714
1715 template<typename _Up>
1716 struct __decay_selector<_Up, true, false>
1717 { typedef typename remove_extent<_Up>::type* __type; };
1718
1719 template<typename _Up>
1720 struct __decay_selector<_Up, false, true>
1721 { typedef typename add_pointer<_Up>::type __type; };
1722
1723 /// decay
1724 template<typename _Tp>
1725 class decay
1726 {
1727 typedef typename remove_reference<_Tp>::type __remove_type;
1728
1729 public:
1730 typedef typename __decay_selector<__remove_type>::__type type;
1731 };
1732
1733 template<typename _Tp>
1734 class reference_wrapper;
1735
1736 // Helper which adds a reference to a type when given a reference_wrapper
1737 template<typename _Tp>
1738 struct __strip_reference_wrapper
1739 {
1740 typedef _Tp __type;
1741 };
1742
1743 template<typename _Tp>
1744 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
1745 {
1746 typedef _Tp& __type;
1747 };
1748
1749 template<typename _Tp>
1750 struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
1751 {
1752 typedef _Tp& __type;
1753 };
1754
1755 template<typename _Tp>
1756 struct __decay_and_strip
1757 {
1758 typedef typename __strip_reference_wrapper<
1759 typename decay<_Tp>::type>::__type __type;
1760 };
1761
1762
123c516a 1763 // Primary template.
13901e4b 1764 /// Define a member typedef @c type only if a boolean constant is true.
123c516a
PC
1765 template<bool, typename _Tp = void>
1766 struct enable_if
1767 { };
1768
1769 // Partial specialization for true.
1770 template<typename _Tp>
1771 struct enable_if<true, _Tp>
1772 { typedef _Tp type; };
1773
1774
123c516a 1775 // Primary template.
13901e4b 1776 /// Define a member typedef @c type to one of two argument types.
123c516a
PC
1777 template<bool _Cond, typename _Iftrue, typename _Iffalse>
1778 struct conditional
1779 { typedef _Iftrue type; };
1780
1781 // Partial specialization for false.
1782 template<typename _Iftrue, typename _Iffalse>
1783 struct conditional<false, _Iftrue, _Iffalse>
1784 { typedef _Iffalse type; };
1785
5b9daa7e 1786 /// common_type
cfa9a96b
CF
1787 template<typename... _Tp>
1788 struct common_type;
1789
b3618b71
DK
1790 // sfinae-friendly common_type implementation:
1791
1792 struct __do_common_type_impl
1793 {
1794 template<typename _Tp, typename _Up>
6c5173c0 1795 static __success_type<typename decay<decltype
fe4e4e3b 1796 (true ? std::declval<_Tp>()
6c5173c0 1797 : std::declval<_Up>())>::type> _S_test(int);
b3618b71
DK
1798
1799 template<typename, typename>
1800 static __failure_type _S_test(...);
1801 };
1802
1803 template<typename _Tp, typename _Up>
1804 struct __common_type_impl
1805 : private __do_common_type_impl
1806 {
1807 typedef decltype(_S_test<_Tp, _Up>(0)) type;
1808 };
1809
1810 struct __do_member_type_wrapper
1811 {
1812 template<typename _Tp>
1813 static __success_type<typename _Tp::type> _S_test(int);
1814
1815 template<typename>
1816 static __failure_type _S_test(...);
1817 };
1818
1819 template<typename _Tp>
1820 struct __member_type_wrapper
1821 : private __do_member_type_wrapper
1822 {
1823 typedef decltype(_S_test<_Tp>(0)) type;
1824 };
1825
1826 template<typename _CTp, typename... _Args>
1827 struct __expanded_common_type_wrapper
1828 {
1829 typedef common_type<typename _CTp::type, _Args...> type;
1830 };
1831
1832 template<typename... _Args>
1833 struct __expanded_common_type_wrapper<__failure_type, _Args...>
1834 { typedef __failure_type type; };
1835
cfa9a96b
CF
1836 template<typename _Tp>
1837 struct common_type<_Tp>
6c5173c0 1838 { typedef typename decay<_Tp>::type type; };
cfa9a96b
CF
1839
1840 template<typename _Tp, typename _Up>
7274deff 1841 struct common_type<_Tp, _Up>
b3618b71
DK
1842 : public __common_type_impl<_Tp, _Up>::type
1843 { };
cfa9a96b
CF
1844
1845 template<typename _Tp, typename _Up, typename... _Vp>
1846 struct common_type<_Tp, _Up, _Vp...>
b3618b71
DK
1847 : public __expanded_common_type_wrapper<typename __member_type_wrapper<
1848 common_type<_Tp, _Up>>::type, _Vp...>::type
1849 { };
7274deff 1850
13901e4b 1851 /// The underlying type of an enum.
a47407f6
PC
1852 template<typename _Tp>
1853 struct underlying_type
1854 {
1855 typedef __underlying_type(_Tp) type;
1856 };
123c516a 1857
7274deff
PC
1858 template<typename _Tp>
1859 struct __declval_protector
1860 {
1861 static const bool __stop = false;
1862 static typename add_rvalue_reference<_Tp>::type __delegate();
1863 };
1864
1865 template<typename _Tp>
1866 inline typename add_rvalue_reference<_Tp>::type
e4f32cb0 1867 declval() noexcept
7274deff
PC
1868 {
1869 static_assert(__declval_protector<_Tp>::__stop,
1870 "declval() must not be used!");
1871 return __declval_protector<_Tp>::__delegate();
1872 }
1041daba 1873
be7f7822
JW
1874 /// result_of
1875 template<typename _Signature>
1876 class result_of;
1877
b3618b71 1878 // sfinae-friendly result_of implementation:
83ddb39f
DK
1879
1880 // [func.require] paragraph 1 bullet 1:
1881 struct __result_of_memfun_ref_impl
1882 {
1883 template<typename _Fp, typename _Tp1, typename... _Args>
1884 static __success_type<decltype(
1885 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
1886 )> _S_test(int);
1887
1888 template<typename...>
1889 static __failure_type _S_test(...);
1890 };
1891
1892 template<typename _MemPtr, typename _Arg, typename... _Args>
1893 struct __result_of_memfun_ref
1894 : private __result_of_memfun_ref_impl
1895 {
1896 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
1897 };
1898
1899 // [func.require] paragraph 1 bullet 2:
1900 struct __result_of_memfun_deref_impl
1901 {
1902 template<typename _Fp, typename _Tp1, typename... _Args>
1903 static __success_type<decltype(
1904 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
1905 )> _S_test(int);
1906
1907 template<typename...>
1908 static __failure_type _S_test(...);
1909 };
1910
1911 template<typename _MemPtr, typename _Arg, typename... _Args>
1912 struct __result_of_memfun_deref
1913 : private __result_of_memfun_deref_impl
1914 {
1915 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
1916 };
1917
1918 // [func.require] paragraph 1 bullet 3:
1919 struct __result_of_memobj_ref_impl
1920 {
1921 template<typename _Fp, typename _Tp1>
1922 static __success_type<decltype(
1923 std::declval<_Tp1>().*std::declval<_Fp>()
1924 )> _S_test(int);
1925
1926 template<typename, typename>
1927 static __failure_type _S_test(...);
1928 };
1929
1930 template<typename _MemPtr, typename _Arg>
1931 struct __result_of_memobj_ref
1932 : private __result_of_memobj_ref_impl
1933 {
1934 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
1935 };
1936
1937 // [func.require] paragraph 1 bullet 4:
1938 struct __result_of_memobj_deref_impl
1939 {
1940 template<typename _Fp, typename _Tp1>
1941 static __success_type<decltype(
1942 (*std::declval<_Tp1>()).*std::declval<_Fp>()
1943 )> _S_test(int);
1944
1945 template<typename, typename>
1946 static __failure_type _S_test(...);
1947 };
1948
be7f7822 1949 template<typename _MemPtr, typename _Arg>
83ddb39f
DK
1950 struct __result_of_memobj_deref
1951 : private __result_of_memobj_deref_impl
1952 {
1953 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
1954 };
1955
1956 template<typename _MemPtr, typename _Arg>
1957 struct __result_of_memobj;
be7f7822
JW
1958
1959 template<typename _Res, typename _Class, typename _Arg>
83ddb39f 1960 struct __result_of_memobj<_Res _Class::*, _Arg>
be7f7822 1961 {
83ddb39f
DK
1962 typedef typename remove_cv<typename remove_reference<
1963 _Arg>::type>::type _Argval;
1964 typedef _Res _Class::* _MemPtr;
1965 typedef typename conditional<__or_<is_same<_Argval, _Class>,
1966 is_base_of<_Class, _Argval>>::value,
1967 __result_of_memobj_ref<_MemPtr, _Arg>,
1968 __result_of_memobj_deref<_MemPtr, _Arg>
1969 >::type::type type;
be7f7822
JW
1970 };
1971
83ddb39f
DK
1972 template<typename _MemPtr, typename _Arg, typename... _Args>
1973 struct __result_of_memfun;
be7f7822
JW
1974
1975 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
83ddb39f 1976 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
be7f7822 1977 {
83ddb39f
DK
1978 typedef typename remove_cv<typename remove_reference<
1979 _Arg>::type>::type _Argval;
1980 typedef _Res _Class::* _MemPtr;
1981 typedef typename conditional<__or_<is_same<_Argval, _Class>,
1982 is_base_of<_Class, _Argval>>::value,
1983 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
1984 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
1985 >::type::type type;
be7f7822
JW
1986 };
1987
1988 template<bool, bool, typename _Functor, typename... _ArgTypes>
83ddb39f 1989 struct __result_of_impl
be7f7822 1990 {
83ddb39f 1991 typedef __failure_type type;
be7f7822
JW
1992 };
1993
1994 template<typename _MemPtr, typename _Arg>
83ddb39f
DK
1995 struct __result_of_impl<true, false, _MemPtr, _Arg>
1996 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg>
c4db9a77 1997 { };
be7f7822 1998
83ddb39f
DK
1999 template<typename _MemPtr, typename _Arg, typename... _Args>
2000 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2001 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...>
c4db9a77 2002 { };
be7f7822 2003
83ddb39f
DK
2004 // [func.require] paragraph 1 bullet 5:
2005 struct __result_of_other_impl
2006 {
2007 template<typename _Fn, typename... _Args>
2008 static __success_type<decltype(
2009 std::declval<_Fn>()(std::declval<_Args>()...)
2010 )> _S_test(int);
2011
2012 template<typename...>
2013 static __failure_type _S_test(...);
2014 };
2015
be7f7822 2016 template<typename _Functor, typename... _ArgTypes>
83ddb39f
DK
2017 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2018 : private __result_of_other_impl
be7f7822 2019 {
83ddb39f 2020 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
be7f7822
JW
2021 };
2022
83ddb39f
DK
2023 template<typename _Functor, typename... _ArgTypes>
2024 struct result_of<_Functor(_ArgTypes...)>
2025 : public __result_of_impl<
2026 is_member_object_pointer<
2027 typename remove_reference<_Functor>::type
2028 >::value,
2029 is_member_function_pointer<
2030 typename remove_reference<_Functor>::type
2031 >::value,
2032 _Functor, _ArgTypes...
2033 >::type
2034 { };
2035
033b71ce
PC
2036 /**
2037 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2038 * member type _NTYPE.
2039 */
2040#define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
2041 template<typename _Tp> \
2042 class __has_##_NTYPE##_helper \
2043 : __sfinae_types \
2044 { \
2045 template<typename _Up> \
2046 struct _Wrap_type \
2047 { }; \
2048 \
2049 template<typename _Up> \
2050 static __one __test(_Wrap_type<typename _Up::_NTYPE>*); \
2051 \
2052 template<typename _Up> \
2053 static __two __test(...); \
2054 \
2055 public: \
f263981a 2056 static constexpr bool value = sizeof(__test<_Tp>(0)) == 1; \
033b71ce
PC
2057 }; \
2058 \
2059 template<typename _Tp> \
2060 struct __has_##_NTYPE \
2061 : integral_constant<bool, __has_##_NTYPE##_helper \
2062 <typename remove_cv<_Tp>::type>::value> \
2063 { };
2064
13901e4b 2065 /// @} group metaprogramming
12ffa228
BK
2066_GLIBCXX_END_NAMESPACE_VERSION
2067} // namespace
7b50cdef 2068
734f5023 2069#endif // C++11
57317d2a 2070
7274deff 2071#endif // _GLIBCXX_TYPE_TRAITS
This page took 0.728554 seconds and 5 git commands to generate.