]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/std/type_traits
Extend std::function test for PR 68995
[thirdparty/gcc.git] / libstdc++-v3 / include / std / type_traits
CommitLineData
c0ffa2ba 1// C++11 <type_traits> -*- C++ -*-
af13a7a6 2
818ab71a 3// Copyright (C) 2007-2016 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
c0eef1c8
JW
40#ifdef _GLIBCXX_USE_C99_STDINT_TR1
41# if defined (__UINT_LEAST16_TYPE__) && defined(__UINT_LEAST32_TYPE__)
21e2806a
JW
42namespace std
43{
c0eef1c8
JW
44 typedef __UINT_LEAST16_TYPE__ uint_least16_t;
45 typedef __UINT_LEAST32_TYPE__ uint_least32_t;
21e2806a 46}
c0eef1c8
JW
47# else
48# include <cstdint>
49# endif
50#endif
51
21e2806a
JW
52namespace std _GLIBCXX_VISIBILITY(default)
53{
54_GLIBCXX_BEGIN_NAMESPACE_VERSION
55
8e32aa11 56 /**
c0ffa2ba 57 * @defgroup metaprogramming Metaprogramming
13901e4b
JW
58 * @ingroup utilities
59 *
60 * Template utilities for compile-time introspection and modification,
61 * including type classification traits, type property inspection traits
62 * and type transformation traits.
63 *
5b9daa7e
BK
64 * @{
65 */
ac65b7d2
DK
66
67 /// integral_constant
68 template<typename _Tp, _Tp __v>
69 struct integral_constant
70 {
71 static constexpr _Tp value = __v;
72 typedef _Tp value_type;
73 typedef integral_constant<_Tp, __v> type;
9191d7a8 74 constexpr operator value_type() const { return value; }
db113eda 75#if __cplusplus > 201103L
a15f7cb8
ESR
76
77#define __cpp_lib_integral_constant_callable 201304
78
db113eda
JW
79 constexpr value_type operator()() const { return value; }
80#endif
ac65b7d2
DK
81 };
82
c0ffa2ba
BK
83 template<typename _Tp, _Tp __v>
84 constexpr _Tp integral_constant<_Tp, __v>::value;
85
13901e4b 86 /// The type used as a compile-time boolean with true value.
ac65b7d2
DK
87 typedef integral_constant<bool, true> true_type;
88
13901e4b 89 /// The type used as a compile-time boolean with false value.
ac65b7d2
DK
90 typedef integral_constant<bool, false> false_type;
91
f6b640be
JW
92 template<bool __v>
93 using __bool_constant = integral_constant<bool, __v>;
94
46ba1281 95#if __cplusplus > 201402L
f9badf71 96# define __cpp_lib_bool_constant 201505
46ba1281
JW
97 template<bool __v>
98 using bool_constant = integral_constant<bool, __v>;
99#endif
100
123c516a 101 // Meta programming helper types.
53dc5044 102
123c516a
PC
103 template<bool, typename, typename>
104 struct conditional;
53dc5044 105
dd7b175e 106 template<typename...>
123c516a
PC
107 struct __or_;
108
ac65b7d2
DK
109 template<>
110 struct __or_<>
111 : public false_type
112 { };
113
dd7b175e
PC
114 template<typename _B1>
115 struct __or_<_B1>
116 : public _B1
117 { };
118
123c516a
PC
119 template<typename _B1, typename _B2>
120 struct __or_<_B1, _B2>
121 : public conditional<_B1::value, _B1, _B2>::type
122 { };
123
124 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
125 struct __or_<_B1, _B2, _B3, _Bn...>
126 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
127 { };
53dc5044 128
dd7b175e 129 template<typename...>
123c516a 130 struct __and_;
53dc5044 131
ac65b7d2
DK
132 template<>
133 struct __and_<>
134 : public true_type
135 { };
136
dd7b175e
PC
137 template<typename _B1>
138 struct __and_<_B1>
139 : public _B1
140 { };
141
123c516a
PC
142 template<typename _B1, typename _B2>
143 struct __and_<_B1, _B2>
144 : public conditional<_B1::value, _B2, _B1>::type
145 { };
146
147 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
148 struct __and_<_B1, _B2, _B3, _Bn...>
149 : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
150 { };
151
152 template<typename _Pp>
153 struct __not_
154 : public integral_constant<bool, !_Pp::value>
155 { };
156
c3a6648b
VV
157#if __cplusplus > 201402L
158
159#define __cpp_lib_logical_traits 201511
160
161 template<typename... _Bn>
162 struct conjunction
163 : __and_<_Bn...>
164 { };
165
166 template<typename... _Bn>
167 struct disjunction
168 : __or_<_Bn...>
169 { };
170
171 template<typename _Pp>
172 struct negation
173 : __not_<_Pp>
174 { };
175#endif
176
b3618b71
DK
177 // For several sfinae-friendly trait implementations we transport both the
178 // result information (as the member type) and the failure information (no
179 // member type). This is very similar to std::enable_if, but we cannot use
180 // them, because we need to derive from them as an implementation detail.
181
182 template<typename _Tp>
183 struct __success_type
184 { typedef _Tp type; };
185
186 struct __failure_type
187 { };
188
c0ffa2ba 189 // Primary type categories.
123c516a 190
53dc5044
PC
191 template<typename>
192 struct remove_cv;
193
194 template<typename>
195 struct __is_void_helper
196 : public false_type { };
53dc5044 197
123c516a
PC
198 template<>
199 struct __is_void_helper<void>
200 : public true_type { };
53dc5044
PC
201
202 /// is_void
203 template<typename _Tp>
204 struct is_void
82b12c4b 205 : public __is_void_helper<typename remove_cv<_Tp>::type>::type
53dc5044
PC
206 { };
207
208 template<typename>
209 struct __is_integral_helper
210 : public false_type { };
123c516a
PC
211
212 template<>
213 struct __is_integral_helper<bool>
214 : public true_type { };
215
216 template<>
217 struct __is_integral_helper<char>
218 : public true_type { };
219
220 template<>
221 struct __is_integral_helper<signed char>
222 : public true_type { };
223
224 template<>
225 struct __is_integral_helper<unsigned char>
226 : public true_type { };
227
53dc5044 228#ifdef _GLIBCXX_USE_WCHAR_T
123c516a
PC
229 template<>
230 struct __is_integral_helper<wchar_t>
231 : public true_type { };
53dc5044 232#endif
123c516a
PC
233
234 template<>
235 struct __is_integral_helper<char16_t>
236 : public true_type { };
237
238 template<>
239 struct __is_integral_helper<char32_t>
240 : public true_type { };
241
242 template<>
243 struct __is_integral_helper<short>
244 : public true_type { };
245
246 template<>
247 struct __is_integral_helper<unsigned short>
248 : public true_type { };
249
250 template<>
251 struct __is_integral_helper<int>
252 : public true_type { };
253
254 template<>
255 struct __is_integral_helper<unsigned int>
256 : public true_type { };
257
258 template<>
259 struct __is_integral_helper<long>
260 : public true_type { };
261
262 template<>
263 struct __is_integral_helper<unsigned long>
264 : public true_type { };
265
266 template<>
267 struct __is_integral_helper<long long>
268 : public true_type { };
269
270 template<>
271 struct __is_integral_helper<unsigned long long>
272 : public true_type { };
53dc5044 273
78a7c317
DD
274 // Conditionalizing on __STRICT_ANSI__ here will break any port that
275 // uses one of these types for size_t.
276#if defined(__GLIBCXX_TYPE_INT_N_0)
6d585f01 277 template<>
78a7c317 278 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0>
6d585f01
PC
279 : public true_type { };
280
281 template<>
78a7c317
DD
282 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0>
283 : public true_type { };
284#endif
285#if defined(__GLIBCXX_TYPE_INT_N_1)
286 template<>
287 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1>
288 : public true_type { };
289
290 template<>
291 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1>
292 : public true_type { };
293#endif
294#if defined(__GLIBCXX_TYPE_INT_N_2)
295 template<>
296 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2>
297 : public true_type { };
298
299 template<>
300 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2>
301 : public true_type { };
302#endif
303#if defined(__GLIBCXX_TYPE_INT_N_3)
304 template<>
305 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3>
306 : public true_type { };
307
308 template<>
309 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3>
6d585f01
PC
310 : public true_type { };
311#endif
312
53dc5044
PC
313 /// is_integral
314 template<typename _Tp>
315 struct is_integral
82b12c4b 316 : public __is_integral_helper<typename remove_cv<_Tp>::type>::type
53dc5044
PC
317 { };
318
319 template<typename>
320 struct __is_floating_point_helper
321 : public false_type { };
123c516a
PC
322
323 template<>
324 struct __is_floating_point_helper<float>
325 : public true_type { };
326
327 template<>
328 struct __is_floating_point_helper<double>
329 : public true_type { };
330
331 template<>
332 struct __is_floating_point_helper<long double>
333 : public true_type { };
53dc5044 334
6d585f01
PC
335#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
336 template<>
337 struct __is_floating_point_helper<__float128>
338 : public true_type { };
339#endif
340
53dc5044
PC
341 /// is_floating_point
342 template<typename _Tp>
343 struct is_floating_point
82b12c4b 344 : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type
53dc5044
PC
345 { };
346
347 /// is_array
348 template<typename>
349 struct is_array
350 : public false_type { };
351
352 template<typename _Tp, std::size_t _Size>
353 struct is_array<_Tp[_Size]>
354 : public true_type { };
355
356 template<typename _Tp>
357 struct is_array<_Tp[]>
358 : public true_type { };
359
360 template<typename>
361 struct __is_pointer_helper
362 : public false_type { };
123c516a
PC
363
364 template<typename _Tp>
365 struct __is_pointer_helper<_Tp*>
366 : public true_type { };
53dc5044
PC
367
368 /// is_pointer
369 template<typename _Tp>
370 struct is_pointer
82b12c4b 371 : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type
53dc5044
PC
372 { };
373
123c516a
PC
374 /// is_lvalue_reference
375 template<typename>
376 struct is_lvalue_reference
377 : public false_type { };
378
53dc5044 379 template<typename _Tp>
123c516a
PC
380 struct is_lvalue_reference<_Tp&>
381 : public true_type { };
382
383 /// is_rvalue_reference
384 template<typename>
385 struct is_rvalue_reference
386 : public false_type { };
53dc5044 387
53dc5044 388 template<typename _Tp>
123c516a
PC
389 struct is_rvalue_reference<_Tp&&>
390 : public true_type { };
391
392 template<typename>
53dc5044
PC
393 struct is_function;
394
395 template<typename>
396 struct __is_member_object_pointer_helper
397 : public false_type { };
123c516a
PC
398
399 template<typename _Tp, typename _Cp>
400 struct __is_member_object_pointer_helper<_Tp _Cp::*>
401 : public integral_constant<bool, !is_function<_Tp>::value> { };
53dc5044
PC
402
403 /// is_member_object_pointer
404 template<typename _Tp>
405 struct is_member_object_pointer
82b12c4b
FD
406 : public __is_member_object_pointer_helper<
407 typename remove_cv<_Tp>::type>::type
53dc5044
PC
408 { };
409
410 template<typename>
411 struct __is_member_function_pointer_helper
412 : public false_type { };
123c516a
PC
413
414 template<typename _Tp, typename _Cp>
415 struct __is_member_function_pointer_helper<_Tp _Cp::*>
416 : public integral_constant<bool, is_function<_Tp>::value> { };
53dc5044
PC
417
418 /// is_member_function_pointer
419 template<typename _Tp>
420 struct is_member_function_pointer
82b12c4b
FD
421 : public __is_member_function_pointer_helper<
422 typename remove_cv<_Tp>::type>::type
53dc5044
PC
423 { };
424
425 /// is_enum
426 template<typename _Tp>
427 struct is_enum
428 : public integral_constant<bool, __is_enum(_Tp)>
429 { };
430
431 /// is_union
432 template<typename _Tp>
433 struct is_union
434 : public integral_constant<bool, __is_union(_Tp)>
435 { };
436
437 /// is_class
438 template<typename _Tp>
439 struct is_class
440 : public integral_constant<bool, __is_class(_Tp)>
441 { };
442
443 /// is_function
444 template<typename>
445 struct is_function
446 : public false_type { };
123c516a 447
53dc5044
PC
448 template<typename _Res, typename... _ArgTypes>
449 struct is_function<_Res(_ArgTypes...)>
450 : public true_type { };
123c516a 451
89898034
DK
452 template<typename _Res, typename... _ArgTypes>
453 struct is_function<_Res(_ArgTypes...) &>
454 : public true_type { };
455
456 template<typename _Res, typename... _ArgTypes>
457 struct is_function<_Res(_ArgTypes...) &&>
458 : public true_type { };
459
53dc5044
PC
460 template<typename _Res, typename... _ArgTypes>
461 struct is_function<_Res(_ArgTypes......)>
462 : public true_type { };
123c516a 463
89898034
DK
464 template<typename _Res, typename... _ArgTypes>
465 struct is_function<_Res(_ArgTypes......) &>
466 : public true_type { };
467
468 template<typename _Res, typename... _ArgTypes>
469 struct is_function<_Res(_ArgTypes......) &&>
470 : public true_type { };
471
53dc5044
PC
472 template<typename _Res, typename... _ArgTypes>
473 struct is_function<_Res(_ArgTypes...) const>
474 : public true_type { };
123c516a 475
89898034
DK
476 template<typename _Res, typename... _ArgTypes>
477 struct is_function<_Res(_ArgTypes...) const &>
478 : public true_type { };
479
480 template<typename _Res, typename... _ArgTypes>
481 struct is_function<_Res(_ArgTypes...) const &&>
482 : public true_type { };
483
53dc5044
PC
484 template<typename _Res, typename... _ArgTypes>
485 struct is_function<_Res(_ArgTypes......) const>
486 : public true_type { };
123c516a 487
89898034
DK
488 template<typename _Res, typename... _ArgTypes>
489 struct is_function<_Res(_ArgTypes......) const &>
490 : public true_type { };
491
492 template<typename _Res, typename... _ArgTypes>
493 struct is_function<_Res(_ArgTypes......) const &&>
494 : public true_type { };
495
53dc5044
PC
496 template<typename _Res, typename... _ArgTypes>
497 struct is_function<_Res(_ArgTypes...) volatile>
498 : public true_type { };
123c516a 499
89898034
DK
500 template<typename _Res, typename... _ArgTypes>
501 struct is_function<_Res(_ArgTypes...) volatile &>
502 : public true_type { };
503
504 template<typename _Res, typename... _ArgTypes>
505 struct is_function<_Res(_ArgTypes...) volatile &&>
506 : public true_type { };
507
53dc5044
PC
508 template<typename _Res, typename... _ArgTypes>
509 struct is_function<_Res(_ArgTypes......) volatile>
510 : public true_type { };
123c516a 511
89898034
DK
512 template<typename _Res, typename... _ArgTypes>
513 struct is_function<_Res(_ArgTypes......) volatile &>
514 : public true_type { };
515
516 template<typename _Res, typename... _ArgTypes>
517 struct is_function<_Res(_ArgTypes......) volatile &&>
518 : public true_type { };
519
53dc5044
PC
520 template<typename _Res, typename... _ArgTypes>
521 struct is_function<_Res(_ArgTypes...) const volatile>
522 : public true_type { };
123c516a 523
89898034
DK
524 template<typename _Res, typename... _ArgTypes>
525 struct is_function<_Res(_ArgTypes...) const volatile &>
526 : public true_type { };
527
528 template<typename _Res, typename... _ArgTypes>
529 struct is_function<_Res(_ArgTypes...) const volatile &&>
530 : public true_type { };
531
53dc5044
PC
532 template<typename _Res, typename... _ArgTypes>
533 struct is_function<_Res(_ArgTypes......) const volatile>
534 : public true_type { };
535
89898034
DK
536 template<typename _Res, typename... _ArgTypes>
537 struct is_function<_Res(_ArgTypes......) const volatile &>
538 : public true_type { };
539
540 template<typename _Res, typename... _ArgTypes>
541 struct is_function<_Res(_ArgTypes......) const volatile &&>
542 : public true_type { };
543
a15f7cb8
ESR
544#define __cpp_lib_is_null_pointer 201309
545
1e673415 546 template<typename>
aa940ab5 547 struct __is_null_pointer_helper
1e673415 548 : public false_type { };
123c516a
PC
549
550 template<>
aa940ab5 551 struct __is_null_pointer_helper<std::nullptr_t>
123c516a 552 : public true_type { };
1e673415 553
aa940ab5
PC
554 /// is_null_pointer (LWG 2247).
555 template<typename _Tp>
556 struct is_null_pointer
557 : public __is_null_pointer_helper<typename remove_cv<_Tp>::type>::type
558 { };
559
560 /// __is_nullptr_t (extension).
1e673415
PC
561 template<typename _Tp>
562 struct __is_nullptr_t
aa940ab5 563 : public is_null_pointer<_Tp>
1e673415
PC
564 { };
565
c0ffa2ba 566 // Composite type categories.
123c516a
PC
567
568 /// is_reference
569 template<typename _Tp>
570 struct is_reference
571 : public __or_<is_lvalue_reference<_Tp>,
572 is_rvalue_reference<_Tp>>::type
573 { };
574
53dc5044
PC
575 /// is_arithmetic
576 template<typename _Tp>
577 struct is_arithmetic
123c516a 578 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
53dc5044
PC
579 { };
580
581 /// is_fundamental
582 template<typename _Tp>
583 struct is_fundamental
aa940ab5
PC
584 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>,
585 is_null_pointer<_Tp>>::type
53dc5044
PC
586 { };
587
588 /// is_object
589 template<typename _Tp>
590 struct is_object
123c516a
PC
591 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
592 is_void<_Tp>>>::type
53dc5044
PC
593 { };
594
123c516a 595 template<typename>
53dc5044
PC
596 struct is_member_pointer;
597
598 /// is_scalar
599 template<typename _Tp>
600 struct is_scalar
123c516a 601 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
aa940ab5 602 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
53dc5044
PC
603 { };
604
605 /// is_compound
606 template<typename _Tp>
607 struct is_compound
608 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
609
53dc5044
PC
610 template<typename _Tp>
611 struct __is_member_pointer_helper
612 : public false_type { };
123c516a
PC
613
614 template<typename _Tp, typename _Cp>
615 struct __is_member_pointer_helper<_Tp _Cp::*>
616 : public true_type { };
53dc5044 617
13901e4b 618 /// is_member_pointer
53dc5044 619 template<typename _Tp>
123c516a 620 struct is_member_pointer
82b12c4b 621 : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type
53dc5044
PC
622 { };
623
89898034
DK
624 // Utility to detect referenceable types ([defns.referenceable]).
625
626 template<typename _Tp>
627 struct __is_referenceable
628 : public __or_<is_object<_Tp>, is_reference<_Tp>>::type
629 { };
630
631 template<typename _Res, typename... _Args>
632 struct __is_referenceable<_Res(_Args...)>
633 : public true_type
634 { };
635
636 template<typename _Res, typename... _Args>
637 struct __is_referenceable<_Res(_Args......)>
638 : public true_type
639 { };
640
c0ffa2ba 641 // Type properties.
123c516a 642
53dc5044
PC
643 /// is_const
644 template<typename>
645 struct is_const
646 : public false_type { };
647
648 template<typename _Tp>
649 struct is_const<_Tp const>
650 : public true_type { };
651
652 /// is_volatile
653 template<typename>
654 struct is_volatile
655 : public false_type { };
656
657 template<typename _Tp>
658 struct is_volatile<_Tp volatile>
659 : public true_type { };
660
123c516a
PC
661 /// is_trivial
662 template<typename _Tp>
663 struct is_trivial
664 : public integral_constant<bool, __is_trivial(_Tp)>
665 { };
666
f5e523b7
VV
667 // is_trivially_copyable
668 template<typename _Tp>
669 struct is_trivially_copyable
670 : public integral_constant<bool, __is_trivially_copyable(_Tp)>
671 { };
123c516a
PC
672
673 /// is_standard_layout
674 template<typename _Tp>
675 struct is_standard_layout
676 : public integral_constant<bool, __is_standard_layout(_Tp)>
677 { };
678
679 /// is_pod
680 // Could use is_standard_layout && is_trivial instead of the builtin.
681 template<typename _Tp>
682 struct is_pod
683 : public integral_constant<bool, __is_pod(_Tp)>
684 { };
685
686 /// is_literal_type
687 template<typename _Tp>
688 struct is_literal_type
689 : public integral_constant<bool, __is_literal_type(_Tp)>
690 { };
691
53dc5044
PC
692 /// is_empty
693 template<typename _Tp>
694 struct is_empty
695 : public integral_constant<bool, __is_empty(_Tp)>
696 { };
697
698 /// is_polymorphic
699 template<typename _Tp>
700 struct is_polymorphic
701 : public integral_constant<bool, __is_polymorphic(_Tp)>
702 { };
703
4db7fcb9
ESR
704#if __cplusplus >= 201402L
705#define __cpp_lib_is_final 201402L
706 /// is_final
707 template<typename _Tp>
708 struct is_final
709 : public integral_constant<bool, __is_final(_Tp)>
710 { };
711#endif
712
53dc5044
PC
713 /// is_abstract
714 template<typename _Tp>
715 struct is_abstract
716 : public integral_constant<bool, __is_abstract(_Tp)>
717 { };
718
123c516a 719 template<typename _Tp,
6a4b1a00 720 bool = is_arithmetic<_Tp>::value>
123c516a
PC
721 struct __is_signed_helper
722 : public false_type { };
723
53dc5044 724 template<typename _Tp>
6a4b1a00
PC
725 struct __is_signed_helper<_Tp, true>
726 : public integral_constant<bool, _Tp(-1) < _Tp(0)>
53dc5044
PC
727 { };
728
123c516a 729 /// is_signed
53dc5044 730 template<typename _Tp>
123c516a 731 struct is_signed
82b12c4b 732 : public __is_signed_helper<_Tp>::type
123c516a
PC
733 { };
734
735 /// is_unsigned
736 template<typename _Tp>
737 struct is_unsigned
f7632193 738 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>
123c516a
PC
739 { };
740
741
c0ffa2ba 742 // Destructible and constructible type properties.
123c516a 743
53dc5044 744 template<typename>
123c516a 745 struct add_rvalue_reference;
53dc5044 746
13901e4b
JW
747 /**
748 * @brief Utility to simplify expressions used in unevaluated operands
749 * @ingroup utilities
750 */
53dc5044 751 template<typename _Tp>
123c516a 752 typename add_rvalue_reference<_Tp>::type declval() noexcept;
53dc5044 753
123c516a
PC
754 template<typename, unsigned = 0>
755 struct extent;
756
757 template<typename>
758 struct remove_all_extents;
759
760 template<typename _Tp>
761 struct __is_array_known_bounds
762 : public integral_constant<bool, (extent<_Tp>::value > 0)>
53dc5044
PC
763 { };
764
123c516a
PC
765 template<typename _Tp>
766 struct __is_array_unknown_bounds
f7632193 767 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>
53dc5044 768 { };
2c7a09d7 769
62fa805f 770 // In N3290 is_destructible does not say anything about function
2c7a09d7 771 // types and abstract types, see LWG 2049. This implementation
62fa805f
DK
772 // describes function types as non-destructible and all complete
773 // object types as destructible, iff the explicit destructor
2c7a09d7 774 // call expression is wellformed.
62fa805f 775 struct __do_is_destructible_impl
123c516a 776 {
62fa805f 777 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
123c516a
PC
778 static true_type __test(int);
779
780 template<typename>
781 static false_type __test(...);
782 };
53dc5044
PC
783
784 template<typename _Tp>
62fa805f
DK
785 struct __is_destructible_impl
786 : public __do_is_destructible_impl
123c516a
PC
787 {
788 typedef decltype(__test<_Tp>(0)) type;
789 };
53dc5044 790
62fa805f
DK
791 template<typename _Tp,
792 bool = __or_<is_void<_Tp>,
793 __is_array_unknown_bounds<_Tp>,
794 is_function<_Tp>>::value,
795 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
796 struct __is_destructible_safe;
797
798 template<typename _Tp>
799 struct __is_destructible_safe<_Tp, false, false>
800 : public __is_destructible_impl<typename
801 remove_all_extents<_Tp>::type>::type
802 { };
803
804 template<typename _Tp>
805 struct __is_destructible_safe<_Tp, true, false>
806 : public false_type { };
807
808 template<typename _Tp>
809 struct __is_destructible_safe<_Tp, false, true>
810 : public true_type { };
811
812 /// is_destructible
813 template<typename _Tp>
814 struct is_destructible
82b12c4b 815 : public __is_destructible_safe<_Tp>::type
62fa805f
DK
816 { };
817
818 // is_nothrow_destructible requires that is_destructible is
819 // satisfied as well. We realize that by mimicing the
820 // implementation of is_destructible but refer to noexcept(expr)
821 // instead of decltype(expr).
822 struct __do_is_nt_destructible_impl
123c516a 823 {
62fa805f
DK
824 template<typename _Tp>
825 static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())>
826 __test(int);
123c516a
PC
827
828 template<typename>
829 static false_type __test(...);
830 };
53dc5044 831
53dc5044 832 template<typename _Tp>
62fa805f
DK
833 struct __is_nt_destructible_impl
834 : public __do_is_nt_destructible_impl
123c516a
PC
835 {
836 typedef decltype(__test<_Tp>(0)) type;
837 };
838
839 template<typename _Tp,
840 bool = __or_<is_void<_Tp>,
62fa805f
DK
841 __is_array_unknown_bounds<_Tp>,
842 is_function<_Tp>>::value,
843 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value>
844 struct __is_nt_destructible_safe;
53dc5044
PC
845
846 template<typename _Tp>
62fa805f
DK
847 struct __is_nt_destructible_safe<_Tp, false, false>
848 : public __is_nt_destructible_impl<typename
849 remove_all_extents<_Tp>::type>::type
123c516a
PC
850 { };
851
53dc5044 852 template<typename _Tp>
62fa805f 853 struct __is_nt_destructible_safe<_Tp, true, false>
123c516a 854 : public false_type { };
53dc5044
PC
855
856 template<typename _Tp>
62fa805f 857 struct __is_nt_destructible_safe<_Tp, false, true>
123c516a
PC
858 : public true_type { };
859
62fa805f 860 /// is_nothrow_destructible
53dc5044 861 template<typename _Tp>
62fa805f 862 struct is_nothrow_destructible
82b12c4b 863 : public __is_nt_destructible_safe<_Tp>::type
123c516a
PC
864 { };
865
866 struct __do_is_default_constructible_impl
867 {
868 template<typename _Tp, typename = decltype(_Tp())>
869 static true_type __test(int);
870
871 template<typename>
872 static false_type __test(...);
873 };
874
875 template<typename _Tp>
876 struct __is_default_constructible_impl
877 : public __do_is_default_constructible_impl
53dc5044 878 {
123c516a 879 typedef decltype(__test<_Tp>(0)) type;
53dc5044 880 };
53dc5044
PC
881
882 template<typename _Tp>
123c516a 883 struct __is_default_constructible_atom
2c7a09d7 884 : public __and_<__not_<is_void<_Tp>>,
f7632193 885 __is_default_constructible_impl<_Tp>>
123c516a 886 { };
53dc5044 887
123c516a
PC
888 template<typename _Tp, bool = is_array<_Tp>::value>
889 struct __is_default_constructible_safe;
53dc5044 890
2c7a09d7
PC
891 // The following technique is a workaround for a current core language
892 // restriction, which does not allow for array types to occur in
893 // functional casts of the form T(). Complete arrays can be default-
894 // constructed, if the element type is default-constructible, but
895 // arrays with unknown bounds are not.
53dc5044 896 template<typename _Tp>
123c516a
PC
897 struct __is_default_constructible_safe<_Tp, true>
898 : public __and_<__is_array_known_bounds<_Tp>,
899 __is_default_constructible_atom<typename
f7632193 900 remove_all_extents<_Tp>::type>>
53dc5044
PC
901 { };
902
53dc5044 903 template<typename _Tp>
123c516a
PC
904 struct __is_default_constructible_safe<_Tp, false>
905 : public __is_default_constructible_atom<_Tp>::type
906 { };
4a27a739 907
123c516a 908 /// is_default_constructible
4a27a739 909 template<typename _Tp>
123c516a 910 struct is_default_constructible
82b12c4b 911 : public __is_default_constructible_safe<_Tp>::type
123c516a 912 { };
4a27a739 913
2c7a09d7
PC
914
915 // Implementation of is_constructible.
916
917 // The hardest part of this trait is the binary direct-initialization
918 // case, because we hit into a functional cast of the form T(arg).
919 // This implementation uses different strategies depending on the
920 // target type to reduce the test overhead as much as possible:
921 //
922 // a) For a reference target type, we use a static_cast expression
923 // modulo its extra cases.
924 //
925 // b) For a non-reference target type we use a ::new expression.
123c516a
PC
926 struct __do_is_static_castable_impl
927 {
928 template<typename _From, typename _To, typename
929 = decltype(static_cast<_To>(declval<_From>()))>
930 static true_type __test(int);
4a27a739 931
123c516a
PC
932 template<typename, typename>
933 static false_type __test(...);
934 };
4a27a739 935
123c516a
PC
936 template<typename _From, typename _To>
937 struct __is_static_castable_impl
938 : public __do_is_static_castable_impl
939 {
940 typedef decltype(__test<_From, _To>(0)) type;
941 };
939759fc 942
123c516a
PC
943 template<typename _From, typename _To>
944 struct __is_static_castable_safe
2c7a09d7 945 : public __is_static_castable_impl<_From, _To>::type
4a27a739
PC
946 { };
947
123c516a
PC
948 // __is_static_castable
949 template<typename _From, typename _To>
950 struct __is_static_castable
951 : public integral_constant<bool, (__is_static_castable_safe<
952 _From, _To>::value)>
953 { };
939759fc 954
2c7a09d7
PC
955 // Implementation for non-reference types. To meet the proper
956 // variable definition semantics, we also need to test for
957 // is_destructible in this case.
5db25ab1
DK
958 // This form should be simplified by a single expression:
959 // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
123c516a
PC
960 struct __do_is_direct_constructible_impl
961 {
962 template<typename _Tp, typename _Arg, typename
963 = decltype(::new _Tp(declval<_Arg>()))>
964 static true_type __test(int);
4a27a739 965
123c516a
PC
966 template<typename, typename>
967 static false_type __test(...);
968 };
4a27a739 969
123c516a
PC
970 template<typename _Tp, typename _Arg>
971 struct __is_direct_constructible_impl
972 : public __do_is_direct_constructible_impl
973 {
974 typedef decltype(__test<_Tp, _Arg>(0)) type;
975 };
4a27a739 976
123c516a
PC
977 template<typename _Tp, typename _Arg>
978 struct __is_direct_constructible_new_safe
979 : public __and_<is_destructible<_Tp>,
f7632193 980 __is_direct_constructible_impl<_Tp, _Arg>>
123c516a 981 { };
4a27a739 982
123c516a
PC
983 template<typename, typename>
984 struct is_same;
4a27a739 985
123c516a
PC
986 template<typename, typename>
987 struct is_base_of;
4a27a739 988
123c516a
PC
989 template<typename>
990 struct remove_reference;
4a27a739 991
123c516a 992 template<typename _From, typename _To, bool
5db25ab1
DK
993 = __not_<__or_<is_void<_From>,
994 is_function<_From>>>::value>
123c516a 995 struct __is_base_to_derived_ref;
4a27a739 996
5db25ab1
DK
997 // Detect whether we have a downcast situation during
998 // reference binding.
123c516a
PC
999 template<typename _From, typename _To>
1000 struct __is_base_to_derived_ref<_From, _To, true>
1001 {
1002 typedef typename remove_cv<typename remove_reference<_From
1003 >::type>::type __src_t;
1004 typedef typename remove_cv<typename remove_reference<_To
1005 >::type>::type __dst_t;
2c7a09d7
PC
1006 typedef __and_<__not_<is_same<__src_t, __dst_t>>,
1007 is_base_of<__src_t, __dst_t>> type;
123c516a
PC
1008 static constexpr bool value = type::value;
1009 };
4a27a739 1010
123c516a
PC
1011 template<typename _From, typename _To>
1012 struct __is_base_to_derived_ref<_From, _To, false>
1013 : public false_type
4a27a739
PC
1014 { };
1015
123c516a
PC
1016 template<typename _From, typename _To, bool
1017 = __and_<is_lvalue_reference<_From>,
1018 is_rvalue_reference<_To>>::value>
1019 struct __is_lvalue_to_rvalue_ref;
e133ace8 1020
5db25ab1
DK
1021 // Detect whether we have an lvalue of non-function type
1022 // bound to a reference-compatible rvalue-reference.
123c516a
PC
1023 template<typename _From, typename _To>
1024 struct __is_lvalue_to_rvalue_ref<_From, _To, true>
1025 {
1026 typedef typename remove_cv<typename remove_reference<
1027 _From>::type>::type __src_t;
1028 typedef typename remove_cv<typename remove_reference<
1029 _To>::type>::type __dst_t;
5db25ab1
DK
1030 typedef __and_<__not_<is_function<__src_t>>,
1031 __or_<is_same<__src_t, __dst_t>,
1032 is_base_of<__dst_t, __src_t>>> type;
123c516a
PC
1033 static constexpr bool value = type::value;
1034 };
e133ace8 1035
123c516a
PC
1036 template<typename _From, typename _To>
1037 struct __is_lvalue_to_rvalue_ref<_From, _To, false>
1038 : public false_type
e133ace8
PC
1039 { };
1040
2c7a09d7
PC
1041 // Here we handle direct-initialization to a reference type as
1042 // equivalent to a static_cast modulo overshooting conversions.
1043 // These are restricted to the following conversions:
5db25ab1 1044 // a) A base class value to a derived class reference
2c7a09d7 1045 // b) An lvalue to an rvalue-reference of reference-compatible
5db25ab1 1046 // types that are not functions
123c516a
PC
1047 template<typename _Tp, typename _Arg>
1048 struct __is_direct_constructible_ref_cast
1049 : public __and_<__is_static_castable<_Arg, _Tp>,
1050 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
1051 __is_lvalue_to_rvalue_ref<_Arg, _Tp>
f7632193 1052 >>>
e133ace8
PC
1053 { };
1054
123c516a
PC
1055 template<typename _Tp, typename _Arg>
1056 struct __is_direct_constructible_new
1057 : public conditional<is_reference<_Tp>::value,
1058 __is_direct_constructible_ref_cast<_Tp, _Arg>,
1059 __is_direct_constructible_new_safe<_Tp, _Arg>
1060 >::type
b0302c68
PC
1061 { };
1062
123c516a
PC
1063 template<typename _Tp, typename _Arg>
1064 struct __is_direct_constructible
82b12c4b 1065 : public __is_direct_constructible_new<_Tp, _Arg>::type
e133ace8
PC
1066 { };
1067
2c7a09d7
PC
1068 // Since default-construction and binary direct-initialization have
1069 // been handled separately, the implementation of the remaining
5db25ab1
DK
1070 // n-ary construction cases is rather straightforward. We can use
1071 // here a functional cast, because array types are excluded anyway
1072 // and this form is never interpreted as a C cast.
123c516a
PC
1073 struct __do_is_nary_constructible_impl
1074 {
1075 template<typename _Tp, typename... _Args, typename
1076 = decltype(_Tp(declval<_Args>()...))>
1077 static true_type __test(int);
2b08f2c5 1078
123c516a
PC
1079 template<typename, typename...>
1080 static false_type __test(...);
1081 };
b0302c68
PC
1082
1083 template<typename _Tp, typename... _Args>
123c516a
PC
1084 struct __is_nary_constructible_impl
1085 : public __do_is_nary_constructible_impl
b0302c68 1086 {
123c516a 1087 typedef decltype(__test<_Tp, _Args...>(0)) type;
b0302c68
PC
1088 };
1089
123c516a
PC
1090 template<typename _Tp, typename... _Args>
1091 struct __is_nary_constructible
2c7a09d7 1092 : public __is_nary_constructible_impl<_Tp, _Args...>::type
b0302c68 1093 {
123c516a
PC
1094 static_assert(sizeof...(_Args) > 1,
1095 "Only useful for > 1 arguments");
1096 };
b0302c68 1097
123c516a
PC
1098 template<typename _Tp, typename... _Args>
1099 struct __is_constructible_impl
1100 : public __is_nary_constructible<_Tp, _Args...>
1101 { };
b0302c68 1102
123c516a
PC
1103 template<typename _Tp, typename _Arg>
1104 struct __is_constructible_impl<_Tp, _Arg>
1105 : public __is_direct_constructible<_Tp, _Arg>
1106 { };
1107
1108 template<typename _Tp>
1109 struct __is_constructible_impl<_Tp>
1110 : public is_default_constructible<_Tp>
1111 { };
b0302c68
PC
1112
1113 /// is_constructible
b0302c68
PC
1114 template<typename _Tp, typename... _Args>
1115 struct is_constructible
82b12c4b 1116 : public __is_constructible_impl<_Tp, _Args...>::type
c32097d8
JM
1117 { };
1118
89898034 1119 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
65cee9bd 1120 struct __is_copy_constructible_impl;
123c516a 1121
65cee9bd 1122 template<typename _Tp>
89898034 1123 struct __is_copy_constructible_impl<_Tp, false>
65cee9bd
PC
1124 : public false_type { };
1125
1126 template<typename _Tp>
89898034 1127 struct __is_copy_constructible_impl<_Tp, true>
65cee9bd
PC
1128 : public is_constructible<_Tp, const _Tp&>
1129 { };
1130
1131 /// is_copy_constructible
1132 template<typename _Tp>
1133 struct is_copy_constructible
1134 : public __is_copy_constructible_impl<_Tp>
1135 { };
1136
89898034 1137 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
65cee9bd
PC
1138 struct __is_move_constructible_impl;
1139
1140 template<typename _Tp>
89898034 1141 struct __is_move_constructible_impl<_Tp, false>
65cee9bd
PC
1142 : public false_type { };
1143
1144 template<typename _Tp>
89898034 1145 struct __is_move_constructible_impl<_Tp, true>
65cee9bd
PC
1146 : public is_constructible<_Tp, _Tp&&>
1147 { };
1148
1149 /// is_move_constructible
1150 template<typename _Tp>
1151 struct is_move_constructible
1152 : public __is_move_constructible_impl<_Tp>
1153 { };
1154
1155 template<typename _Tp>
1156 struct __is_nt_default_constructible_atom
1157 : public integral_constant<bool, noexcept(_Tp())>
1158 { };
1159
1160 template<typename _Tp, bool = is_array<_Tp>::value>
1161 struct __is_nt_default_constructible_impl;
1162
1163 template<typename _Tp>
1164 struct __is_nt_default_constructible_impl<_Tp, true>
1165 : public __and_<__is_array_known_bounds<_Tp>,
1166 __is_nt_default_constructible_atom<typename
f7632193 1167 remove_all_extents<_Tp>::type>>
65cee9bd
PC
1168 { };
1169
1170 template<typename _Tp>
1171 struct __is_nt_default_constructible_impl<_Tp, false>
1172 : public __is_nt_default_constructible_atom<_Tp>
1173 { };
1174
1175 /// is_nothrow_default_constructible
1176 template<typename _Tp>
1177 struct is_nothrow_default_constructible
1178 : public __and_<is_default_constructible<_Tp>,
f7632193 1179 __is_nt_default_constructible_impl<_Tp>>
65cee9bd 1180 { };
e4f32cb0
PC
1181
1182 template<typename _Tp, typename... _Args>
65cee9bd
PC
1183 struct __is_nt_constructible_impl
1184 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
1185 { };
e4f32cb0
PC
1186
1187 template<typename _Tp, typename _Arg>
65cee9bd
PC
1188 struct __is_nt_constructible_impl<_Tp, _Arg>
1189 : public integral_constant<bool,
1190 noexcept(static_cast<_Tp>(declval<_Arg>()))>
1191 { };
1192
1193 template<typename _Tp>
1194 struct __is_nt_constructible_impl<_Tp>
1195 : public is_nothrow_default_constructible<_Tp>
1196 { };
e4f32cb0
PC
1197
1198 /// is_nothrow_constructible
1199 template<typename _Tp, typename... _Args>
1200 struct is_nothrow_constructible
65cee9bd 1201 : public __and_<is_constructible<_Tp, _Args...>,
f7632193 1202 __is_nt_constructible_impl<_Tp, _Args...>>
65cee9bd
PC
1203 { };
1204
89898034 1205 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
65cee9bd
PC
1206 struct __is_nothrow_copy_constructible_impl;
1207
1208 template<typename _Tp>
89898034 1209 struct __is_nothrow_copy_constructible_impl<_Tp, false>
65cee9bd
PC
1210 : public false_type { };
1211
1212 template<typename _Tp>
89898034 1213 struct __is_nothrow_copy_constructible_impl<_Tp, true>
65cee9bd
PC
1214 : public is_nothrow_constructible<_Tp, const _Tp&>
1215 { };
1216
1217 /// is_nothrow_copy_constructible
1218 template<typename _Tp>
1219 struct is_nothrow_copy_constructible
1220 : public __is_nothrow_copy_constructible_impl<_Tp>
1221 { };
1222
89898034 1223 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
65cee9bd
PC
1224 struct __is_nothrow_move_constructible_impl;
1225
1226 template<typename _Tp>
89898034 1227 struct __is_nothrow_move_constructible_impl<_Tp, false>
65cee9bd
PC
1228 : public false_type { };
1229
1230 template<typename _Tp>
89898034 1231 struct __is_nothrow_move_constructible_impl<_Tp, true>
65cee9bd
PC
1232 : public is_nothrow_constructible<_Tp, _Tp&&>
1233 { };
1234
1235 /// is_nothrow_move_constructible
1236 template<typename _Tp>
1237 struct is_nothrow_move_constructible
1238 : public __is_nothrow_move_constructible_impl<_Tp>
1239 { };
1240
f263981a
PC
1241 template<typename _Tp, typename _Up>
1242 class __is_assignable_helper
f263981a 1243 {
82b12c4b
FD
1244 template<typename _Tp1, typename _Up1,
1245 typename = decltype(declval<_Tp1>() = declval<_Up1>())>
1246 static true_type
f263981a
PC
1247 __test(int);
1248
1249 template<typename, typename>
82b12c4b
FD
1250 static false_type
1251 __test(...);
f263981a
PC
1252
1253 public:
82b12c4b 1254 typedef decltype(__test<_Tp, _Up>(0)) type;
f263981a
PC
1255 };
1256
1257 /// is_assignable
1258 template<typename _Tp, typename _Up>
1259 struct is_assignable
82b12c4b 1260 : public __is_assignable_helper<_Tp, _Up>::type
f263981a
PC
1261 { };
1262
89898034 1263 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
f263981a
PC
1264 struct __is_copy_assignable_impl;
1265
1266 template<typename _Tp>
89898034 1267 struct __is_copy_assignable_impl<_Tp, false>
f263981a
PC
1268 : public false_type { };
1269
1270 template<typename _Tp>
89898034 1271 struct __is_copy_assignable_impl<_Tp, true>
9b3a81da 1272 : public is_assignable<_Tp&, const _Tp&>
f263981a
PC
1273 { };
1274
1275 /// is_copy_assignable
1276 template<typename _Tp>
1277 struct is_copy_assignable
1278 : public __is_copy_assignable_impl<_Tp>
1279 { };
1280
89898034 1281 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
f263981a
PC
1282 struct __is_move_assignable_impl;
1283
1284 template<typename _Tp>
89898034 1285 struct __is_move_assignable_impl<_Tp, false>
f263981a
PC
1286 : public false_type { };
1287
1288 template<typename _Tp>
89898034 1289 struct __is_move_assignable_impl<_Tp, true>
f263981a
PC
1290 : public is_assignable<_Tp&, _Tp&&>
1291 { };
1292
1293 /// is_move_assignable
1294 template<typename _Tp>
1295 struct is_move_assignable
1296 : public __is_move_assignable_impl<_Tp>
1297 { };
1298
1299 template<typename _Tp, typename _Up>
1300 struct __is_nt_assignable_impl
1301 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
1302 { };
1303
1304 /// is_nothrow_assignable
1305 template<typename _Tp, typename _Up>
1306 struct is_nothrow_assignable
1307 : public __and_<is_assignable<_Tp, _Up>,
f7632193 1308 __is_nt_assignable_impl<_Tp, _Up>>
f263981a
PC
1309 { };
1310
89898034 1311 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
f263981a
PC
1312 struct __is_nt_copy_assignable_impl;
1313
1314 template<typename _Tp>
89898034 1315 struct __is_nt_copy_assignable_impl<_Tp, false>
f263981a
PC
1316 : public false_type { };
1317
1318 template<typename _Tp>
89898034 1319 struct __is_nt_copy_assignable_impl<_Tp, true>
9b3a81da 1320 : public is_nothrow_assignable<_Tp&, const _Tp&>
f263981a
PC
1321 { };
1322
1323 /// is_nothrow_copy_assignable
1324 template<typename _Tp>
1325 struct is_nothrow_copy_assignable
1326 : public __is_nt_copy_assignable_impl<_Tp>
1327 { };
1328
89898034 1329 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
f263981a
PC
1330 struct __is_nt_move_assignable_impl;
1331
1332 template<typename _Tp>
89898034 1333 struct __is_nt_move_assignable_impl<_Tp, false>
f263981a
PC
1334 : public false_type { };
1335
1336 template<typename _Tp>
89898034 1337 struct __is_nt_move_assignable_impl<_Tp, true>
f263981a
PC
1338 : public is_nothrow_assignable<_Tp&, _Tp&&>
1339 { };
1340
1341 /// is_nothrow_move_assignable
65cee9bd 1342 template<typename _Tp>
f263981a
PC
1343 struct is_nothrow_move_assignable
1344 : public __is_nt_move_assignable_impl<_Tp>
e4f32cb0
PC
1345 { };
1346
f5e523b7
VV
1347 /// is_trivially_constructible
1348 template<typename _Tp, typename... _Args>
1349 struct is_trivially_constructible
1350 : public __and_<is_constructible<_Tp, _Args...>, integral_constant<bool,
f7632193 1351 __is_trivially_constructible(_Tp, _Args...)>>
f5e523b7 1352 { };
6a9ecd34 1353
f5e523b7
VV
1354 /// is_trivially_default_constructible
1355 template<typename _Tp>
1356 struct is_trivially_default_constructible
1357 : public is_trivially_constructible<_Tp>::type
1358 { };
6a9ecd34 1359
f7632193
VV
1360 struct __do_is_implicitly_default_constructible_impl
1361 {
1362 template <typename _Tp>
1363 static void __helper(const _Tp&);
1364
1365 template <typename _Tp>
1366 static true_type __test(const _Tp&,
1367 decltype(__helper<const _Tp&>({}))* = 0);
1368
1369 static false_type __test(...);
1370 };
1371
1372 template<typename _Tp>
1373 struct __is_implicitly_default_constructible_impl
1374 : public __do_is_implicitly_default_constructible_impl
1375 {
1376 typedef decltype(__test(declval<_Tp>())) type;
1377 };
1378
1379 template<typename _Tp>
1380 struct __is_implicitly_default_constructible_safe
1381 : public __is_implicitly_default_constructible_impl<_Tp>::type
1382 { };
1383
1384 template <typename _Tp>
1385 struct __is_implicitly_default_constructible
1386 : public __and_<is_default_constructible<_Tp>,
1387 __is_implicitly_default_constructible_safe<_Tp>>
1388 { };
1389
f5e523b7
VV
1390 /// is_trivially_copy_constructible
1391 template<typename _Tp>
1392 struct is_trivially_copy_constructible
1393 : public __and_<is_copy_constructible<_Tp>,
1394 integral_constant<bool,
f7632193 1395 __is_trivially_constructible(_Tp, const _Tp&)>>
f5e523b7
VV
1396 { };
1397
1398 /// is_trivially_move_constructible
1399 template<typename _Tp>
1400 struct is_trivially_move_constructible
1401 : public __and_<is_move_constructible<_Tp>,
1402 integral_constant<bool,
f7632193 1403 __is_trivially_constructible(_Tp, _Tp&&)>>
f5e523b7 1404 { };
6a9ecd34 1405
f5e523b7
VV
1406 /// is_trivially_assignable
1407 template<typename _Tp, typename _Up>
1408 struct is_trivially_assignable
1409 : public __and_<is_assignable<_Tp, _Up>,
1410 integral_constant<bool,
f7632193 1411 __is_trivially_assignable(_Tp, _Up)>>
f5e523b7 1412 { };
6a9ecd34 1413
f5e523b7
VV
1414 /// is_trivially_copy_assignable
1415 template<typename _Tp>
1416 struct is_trivially_copy_assignable
1417 : public __and_<is_copy_assignable<_Tp>,
1418 integral_constant<bool,
f7632193 1419 __is_trivially_assignable(_Tp&, const _Tp&)>>
f5e523b7 1420 { };
6a9ecd34 1421
f5e523b7
VV
1422 /// is_trivially_move_assignable
1423 template<typename _Tp>
1424 struct is_trivially_move_assignable
1425 : public __and_<is_move_assignable<_Tp>,
1426 integral_constant<bool,
f7632193 1427 __is_trivially_assignable(_Tp&, _Tp&&)>>
f5e523b7 1428 { };
6a9ecd34
PC
1429
1430 /// is_trivially_destructible
1431 template<typename _Tp>
1432 struct is_trivially_destructible
1433 : public __and_<is_destructible<_Tp>, integral_constant<bool,
f7632193 1434 __has_trivial_destructor(_Tp)>>
6a9ecd34
PC
1435 { };
1436
1437 /// has_trivial_default_constructor (temporary legacy)
e133ace8
PC
1438 template<typename _Tp>
1439 struct has_trivial_default_constructor
1440 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
c66b93fe 1441 { } _GLIBCXX_DEPRECATED;
e133ace8 1442
6a9ecd34 1443 /// has_trivial_copy_constructor (temporary legacy)
e133ace8
PC
1444 template<typename _Tp>
1445 struct has_trivial_copy_constructor
1446 : public integral_constant<bool, __has_trivial_copy(_Tp)>
c66b93fe 1447 { } _GLIBCXX_DEPRECATED;
e133ace8 1448
6a9ecd34 1449 /// has_trivial_copy_assign (temporary legacy)
e133ace8 1450 template<typename _Tp>
6f5e9b8d 1451 struct has_trivial_copy_assign
e133ace8 1452 : public integral_constant<bool, __has_trivial_assign(_Tp)>
c66b93fe 1453 { } _GLIBCXX_DEPRECATED;
e133ace8 1454
123c516a
PC
1455 /// has_virtual_destructor
1456 template<typename _Tp>
1457 struct has_virtual_destructor
1458 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1459 { };
1460
1461
1462 // type property queries.
1463
1464 /// alignment_of
1465 template<typename _Tp>
1466 struct alignment_of
1467 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1468
1469 /// rank
1470 template<typename>
1471 struct rank
1472 : public integral_constant<std::size_t, 0> { };
1473
1474 template<typename _Tp, std::size_t _Size>
1475 struct rank<_Tp[_Size]>
1476 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1477
1478 template<typename _Tp>
1479 struct rank<_Tp[]>
1480 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1481
1482 /// extent
1483 template<typename, unsigned _Uint>
1484 struct extent
1485 : public integral_constant<std::size_t, 0> { };
1486
1487 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1488 struct extent<_Tp[_Size], _Uint>
1489 : public integral_constant<std::size_t,
1490 _Uint == 0 ? _Size : extent<_Tp,
1491 _Uint - 1>::value>
1492 { };
1493
1494 template<typename _Tp, unsigned _Uint>
1495 struct extent<_Tp[], _Uint>
1496 : public integral_constant<std::size_t,
1497 _Uint == 0 ? 0 : extent<_Tp,
1498 _Uint - 1>::value>
1499 { };
1500
1501
c0ffa2ba 1502 // Type relations.
123c516a
PC
1503
1504 /// is_same
1505 template<typename, typename>
1506 struct is_same
1507 : public false_type { };
1508
1509 template<typename _Tp>
1510 struct is_same<_Tp, _Tp>
1511 : public true_type { };
b0302c68 1512
939759fc 1513 /// is_base_of
e133ace8
PC
1514 template<typename _Base, typename _Derived>
1515 struct is_base_of
1516 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1517 { };
1518
297f34d7 1519 template<typename _From, typename _To,
123c516a
PC
1520 bool = __or_<is_void<_From>, is_function<_To>,
1521 is_array<_To>>::value>
297f34d7 1522 struct __is_convertible_helper
82b12c4b 1523 { typedef typename is_void<_To>::type type; };
297f34d7 1524
e133ace8 1525 template<typename _From, typename _To>
b0302c68 1526 class __is_convertible_helper<_From, _To, false>
e133ace8 1527 {
82b12c4b
FD
1528 template<typename _To1>
1529 static void __test_aux(_To1);
8e7d962a 1530
82b12c4b
FD
1531 template<typename _From1, typename _To1,
1532 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1533 static true_type
8e7d962a
PC
1534 __test(int);
1535
1536 template<typename, typename>
82b12c4b
FD
1537 static false_type
1538 __test(...);
297f34d7 1539
e133ace8 1540 public:
82b12c4b 1541 typedef decltype(__test<_From, _To>(0)) type;
e133ace8
PC
1542 };
1543
82b12c4b 1544
b0302c68 1545 /// is_convertible
e133ace8
PC
1546 template<typename _From, typename _To>
1547 struct is_convertible
82b12c4b 1548 : public __is_convertible_helper<_From, _To>::type
e133ace8
PC
1549 { };
1550
fd735b6a 1551
c0ffa2ba 1552 // Const-volatile modifications.
7b50cdef 1553
123c516a 1554 /// remove_const
7b50cdef 1555 template<typename _Tp>
123c516a
PC
1556 struct remove_const
1557 { typedef _Tp type; };
7b50cdef 1558
123c516a
PC
1559 template<typename _Tp>
1560 struct remove_const<_Tp const>
1561 { typedef _Tp type; };
1562
1563 /// remove_volatile
1564 template<typename _Tp>
1565 struct remove_volatile
1566 { typedef _Tp type; };
7b50cdef 1567
123c516a
PC
1568 template<typename _Tp>
1569 struct remove_volatile<_Tp volatile>
1570 { typedef _Tp type; };
1571
1572 /// remove_cv
1573 template<typename _Tp>
1574 struct remove_cv
1575 {
1576 typedef typename
1577 remove_const<typename remove_volatile<_Tp>::type>::type type;
1578 };
1579
1580 /// add_const
1581 template<typename _Tp>
1582 struct add_const
1583 { typedef _Tp const type; };
1584
1585 /// add_volatile
1586 template<typename _Tp>
1587 struct add_volatile
1588 { typedef _Tp volatile type; };
1589
1590 /// add_cv
1591 template<typename _Tp>
1592 struct add_cv
1593 {
1594 typedef typename
1595 add_const<typename add_volatile<_Tp>::type>::type type;
1596 };
7b50cdef 1597
4457e88c 1598#if __cplusplus > 201103L
a15f7cb8
ESR
1599
1600#define __cpp_lib_transformation_trait_aliases 201304
1601
4457e88c
JW
1602 /// Alias template for remove_const
1603 template<typename _Tp>
1604 using remove_const_t = typename remove_const<_Tp>::type;
1605
1606 /// Alias template for remove_volatile
1607 template<typename _Tp>
1608 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1609
1610 /// Alias template for remove_cv
1611 template<typename _Tp>
1612 using remove_cv_t = typename remove_cv<_Tp>::type;
1613
1614 /// Alias template for add_const
1615 template<typename _Tp>
1616 using add_const_t = typename add_const<_Tp>::type;
1617
1618 /// Alias template for add_volatile
1619 template<typename _Tp>
1620 using add_volatile_t = typename add_volatile<_Tp>::type;
1621
1622 /// Alias template for add_cv
1623 template<typename _Tp>
1624 using add_cv_t = typename add_cv<_Tp>::type;
1625#endif
7b50cdef 1626
123c516a 1627 // Reference transformations.
7b50cdef 1628
123c516a
PC
1629 /// remove_reference
1630 template<typename _Tp>
1631 struct remove_reference
1632 { typedef _Tp type; };
7b50cdef 1633
123c516a
PC
1634 template<typename _Tp>
1635 struct remove_reference<_Tp&>
1636 { typedef _Tp type; };
7b50cdef 1637
123c516a
PC
1638 template<typename _Tp>
1639 struct remove_reference<_Tp&&>
1640 { typedef _Tp type; };
1641
89898034 1642 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
123c516a
PC
1643 struct __add_lvalue_reference_helper
1644 { typedef _Tp type; };
7b50cdef 1645
5e108459 1646 template<typename _Tp>
89898034 1647 struct __add_lvalue_reference_helper<_Tp, true>
123c516a 1648 { typedef _Tp& type; };
5e108459 1649
123c516a 1650 /// add_lvalue_reference
5e108459 1651 template<typename _Tp>
123c516a
PC
1652 struct add_lvalue_reference
1653 : public __add_lvalue_reference_helper<_Tp>
1654 { };
1655
89898034 1656 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
123c516a
PC
1657 struct __add_rvalue_reference_helper
1658 { typedef _Tp type; };
5e108459
PC
1659
1660 template<typename _Tp>
123c516a
PC
1661 struct __add_rvalue_reference_helper<_Tp, true>
1662 { typedef _Tp&& type; };
5e108459 1663
123c516a 1664 /// add_rvalue_reference
5e108459 1665 template<typename _Tp>
123c516a
PC
1666 struct add_rvalue_reference
1667 : public __add_rvalue_reference_helper<_Tp>
1668 { };
5e108459 1669
4457e88c
JW
1670#if __cplusplus > 201103L
1671 /// Alias template for remove_reference
1672 template<typename _Tp>
1673 using remove_reference_t = typename remove_reference<_Tp>::type;
1674
1675 /// Alias template for add_lvalue_reference
1676 template<typename _Tp>
1677 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1678
1679 /// Alias template for add_rvalue_reference
1680 template<typename _Tp>
1681 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1682#endif
7b50cdef 1683
c0ffa2ba 1684 // Sign modifications.
123c516a 1685
7b50cdef
BK
1686 // Utility for constructing identically cv-qualified types.
1687 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1688 struct __cv_selector;
1689
1690 template<typename _Unqualified>
1691 struct __cv_selector<_Unqualified, false, false>
1692 { typedef _Unqualified __type; };
1693
1694 template<typename _Unqualified>
1695 struct __cv_selector<_Unqualified, false, true>
1696 { typedef volatile _Unqualified __type; };
1697
1698 template<typename _Unqualified>
1699 struct __cv_selector<_Unqualified, true, false>
1700 { typedef const _Unqualified __type; };
1701
1702 template<typename _Unqualified>
1703 struct __cv_selector<_Unqualified, true, true>
1704 { typedef const volatile _Unqualified __type; };
1705
1706 template<typename _Qualified, typename _Unqualified,
1707 bool _IsConst = is_const<_Qualified>::value,
1708 bool _IsVol = is_volatile<_Qualified>::value>
b0302c68 1709 class __match_cv_qualifiers
7b50cdef 1710 {
7b50cdef
BK
1711 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1712
1713 public:
1714 typedef typename __match::__type __type;
1715 };
1716
7b50cdef
BK
1717 // Utility for finding the unsigned versions of signed integral types.
1718 template<typename _Tp>
e133ace8
PC
1719 struct __make_unsigned
1720 { typedef _Tp __type; };
7b50cdef
BK
1721
1722 template<>
1723 struct __make_unsigned<char>
1724 { typedef unsigned char __type; };
1725
1726 template<>
1727 struct __make_unsigned<signed char>
1728 { typedef unsigned char __type; };
1729
7b50cdef
BK
1730 template<>
1731 struct __make_unsigned<short>
1732 { typedef unsigned short __type; };
1733
1734 template<>
1735 struct __make_unsigned<int>
1736 { typedef unsigned int __type; };
1737
1738 template<>
1739 struct __make_unsigned<long>
1740 { typedef unsigned long __type; };
1741
1742 template<>
1743 struct __make_unsigned<long long>
1744 { typedef unsigned long long __type; };
1745
c0eef1c8
JW
1746#if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__)
1747 template<>
1748 struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__>
1749 { };
1750#endif
1751
78a7c317
DD
1752#if defined(__GLIBCXX_TYPE_INT_N_0)
1753 template<>
1754 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1755 { typedef unsigned __GLIBCXX_TYPE_INT_N_0 __type; };
1756#endif
1757#if defined(__GLIBCXX_TYPE_INT_N_1)
1758 template<>
1759 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1760 { typedef unsigned __GLIBCXX_TYPE_INT_N_1 __type; };
1761#endif
1762#if defined(__GLIBCXX_TYPE_INT_N_2)
6d585f01 1763 template<>
78a7c317
DD
1764 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1765 { typedef unsigned __GLIBCXX_TYPE_INT_N_2 __type; };
1766#endif
1767#if defined(__GLIBCXX_TYPE_INT_N_3)
1768 template<>
1769 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1770 { typedef unsigned __GLIBCXX_TYPE_INT_N_3 __type; };
6d585f01
PC
1771#endif
1772
7b50cdef
BK
1773 // Select between integral and enum: not possible to be both.
1774 template<typename _Tp,
1775 bool _IsInt = is_integral<_Tp>::value,
7b50cdef 1776 bool _IsEnum = is_enum<_Tp>::value>
b0302c68
PC
1777 class __make_unsigned_selector;
1778
7b50cdef 1779 template<typename _Tp>
b0302c68 1780 class __make_unsigned_selector<_Tp, true, false>
7b50cdef 1781 {
7b50cdef
BK
1782 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1783 typedef typename __unsignedt::__type __unsigned_type;
1784 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1785
1786 public:
1787 typedef typename __cv_unsigned::__type __type;
1788 };
1789
7b50cdef 1790 template<typename _Tp>
b0302c68 1791 class __make_unsigned_selector<_Tp, false, true>
7b50cdef 1792 {
a0230468
MM
1793 // With -fshort-enums, an enum may be as small as a char.
1794 typedef unsigned char __smallest;
1795 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1796 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
ce2e6349 1797 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
73d81d3a
JW
1798 static const bool __b3 = sizeof(_Tp) <= sizeof(unsigned long);
1799 typedef conditional<__b3, unsigned long, unsigned long long> __cond3;
1800 typedef typename __cond3::type __cond3_type;
1801 typedef conditional<__b2, unsigned int, __cond3_type> __cond2;
a0230468
MM
1802 typedef typename __cond2::type __cond2_type;
1803 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1804 typedef typename __cond1::type __cond1_type;
7b50cdef 1805
73d81d3a
JW
1806 typedef typename conditional<__b0, __smallest, __cond1_type>::type
1807 __unsigned_type;
1808 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1809
7b50cdef 1810 public:
73d81d3a 1811 typedef typename __cv_unsigned::__type __type;
7b50cdef
BK
1812 };
1813
7b50cdef
BK
1814 // Given an integral/enum type, return the corresponding unsigned
1815 // integer type.
5b9daa7e
BK
1816 // Primary template.
1817 /// make_unsigned
7b50cdef
BK
1818 template<typename _Tp>
1819 struct make_unsigned
1820 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1821
1822 // Integral, but don't define.
1823 template<>
1824 struct make_unsigned<bool>;
1825
1826
1827 // Utility for finding the signed versions of unsigned integral types.
1828 template<typename _Tp>
e133ace8
PC
1829 struct __make_signed
1830 { typedef _Tp __type; };
7b50cdef
BK
1831
1832 template<>
1833 struct __make_signed<char>
1834 { typedef signed char __type; };
1835
1836 template<>
1837 struct __make_signed<unsigned char>
1838 { typedef signed char __type; };
1839
7b50cdef
BK
1840 template<>
1841 struct __make_signed<unsigned short>
1842 { typedef signed short __type; };
1843
1844 template<>
1845 struct __make_signed<unsigned int>
1846 { typedef signed int __type; };
1847
1848 template<>
1849 struct __make_signed<unsigned long>
1850 { typedef signed long __type; };
1851
1852 template<>
1853 struct __make_signed<unsigned long long>
1854 { typedef signed long long __type; };
1855
c0eef1c8
JW
1856#if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__)
1857 template<>
1858 struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__>
1859 { };
1860#endif
1861
1862#ifdef _GLIBCXX_USE_C99_STDINT_TR1
1863 template<>
1864 struct __make_signed<char16_t> : __make_signed<uint_least16_t>
1865 { };
1866 template<>
1867 struct __make_signed<char32_t> : __make_signed<uint_least32_t>
1868 { };
1869#endif
1870
78a7c317
DD
1871#if defined(__GLIBCXX_TYPE_INT_N_0)
1872 template<>
1873 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
1874 { typedef __GLIBCXX_TYPE_INT_N_0 __type; };
1875#endif
1876#if defined(__GLIBCXX_TYPE_INT_N_1)
1877 template<>
1878 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
1879 { typedef __GLIBCXX_TYPE_INT_N_1 __type; };
1880#endif
1881#if defined(__GLIBCXX_TYPE_INT_N_2)
1882 template<>
1883 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
1884 { typedef __GLIBCXX_TYPE_INT_N_2 __type; };
1885#endif
1886#if defined(__GLIBCXX_TYPE_INT_N_3)
6d585f01 1887 template<>
78a7c317
DD
1888 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
1889 { typedef __GLIBCXX_TYPE_INT_N_3 __type; };
6d585f01
PC
1890#endif
1891
fb8ffd10 1892 // Select between integral and enum: not possible to be both.
7b50cdef
BK
1893 template<typename _Tp,
1894 bool _IsInt = is_integral<_Tp>::value,
7b50cdef 1895 bool _IsEnum = is_enum<_Tp>::value>
b0302c68
PC
1896 class __make_signed_selector;
1897
7b50cdef 1898 template<typename _Tp>
b0302c68 1899 class __make_signed_selector<_Tp, true, false>
7b50cdef 1900 {
7b50cdef
BK
1901 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1902 typedef typename __signedt::__type __signed_type;
1903 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1904
1905 public:
1906 typedef typename __cv_signed::__type __type;
1907 };
1908
7b50cdef 1909 template<typename _Tp>
b0302c68 1910 class __make_signed_selector<_Tp, false, true>
7b50cdef 1911 {
73d81d3a 1912 typedef typename __make_unsigned_selector<_Tp>::__type __unsigned_type;
7b50cdef
BK
1913
1914 public:
73d81d3a 1915 typedef typename __make_signed_selector<__unsigned_type>::__type __type;
7b50cdef
BK
1916 };
1917
7b50cdef
BK
1918 // Given an integral/enum type, return the corresponding signed
1919 // integer type.
5b9daa7e
BK
1920 // Primary template.
1921 /// make_signed
7b50cdef
BK
1922 template<typename _Tp>
1923 struct make_signed
1924 { typedef typename __make_signed_selector<_Tp>::__type type; };
1925
1926 // Integral, but don't define.
1927 template<>
1928 struct make_signed<bool>;
cfa9a96b 1929
4457e88c
JW
1930#if __cplusplus > 201103L
1931 /// Alias template for make_signed
1932 template<typename _Tp>
1933 using make_signed_t = typename make_signed<_Tp>::type;
1934
1935 /// Alias template for make_unsigned
1936 template<typename _Tp>
1937 using make_unsigned_t = typename make_unsigned<_Tp>::type;
1938#endif
123c516a 1939
c0ffa2ba 1940 // Array modifications.
123c516a
PC
1941
1942 /// remove_extent
1943 template<typename _Tp>
1944 struct remove_extent
1945 { typedef _Tp type; };
1946
1947 template<typename _Tp, std::size_t _Size>
1948 struct remove_extent<_Tp[_Size]>
1949 { typedef _Tp type; };
1950
1951 template<typename _Tp>
1952 struct remove_extent<_Tp[]>
1953 { typedef _Tp type; };
1954
1955 /// remove_all_extents
1956 template<typename _Tp>
1957 struct remove_all_extents
1958 { typedef _Tp type; };
1959
1960 template<typename _Tp, std::size_t _Size>
1961 struct remove_all_extents<_Tp[_Size]>
1962 { typedef typename remove_all_extents<_Tp>::type type; };
1963
1964 template<typename _Tp>
1965 struct remove_all_extents<_Tp[]>
1966 { typedef typename remove_all_extents<_Tp>::type type; };
1967
4457e88c
JW
1968#if __cplusplus > 201103L
1969 /// Alias template for remove_extent
1970 template<typename _Tp>
1971 using remove_extent_t = typename remove_extent<_Tp>::type;
1972
1973 /// Alias template for remove_all_extents
1974 template<typename _Tp>
1975 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1976#endif
123c516a 1977
c0ffa2ba 1978 // Pointer modifications.
123c516a
PC
1979
1980 template<typename _Tp, typename>
1981 struct __remove_pointer_helper
1982 { typedef _Tp type; };
1983
1984 template<typename _Tp, typename _Up>
1985 struct __remove_pointer_helper<_Tp, _Up*>
1986 { typedef _Up type; };
1987
1988 /// remove_pointer
1989 template<typename _Tp>
1990 struct remove_pointer
1991 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1992 { };
1993
1994 /// add_pointer
89898034
DK
1995 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
1996 is_void<_Tp>>::value>
1997 struct __add_pointer_helper
1998 { typedef _Tp type; };
1999
123c516a 2000 template<typename _Tp>
89898034 2001 struct __add_pointer_helper<_Tp, true>
123c516a
PC
2002 { typedef typename remove_reference<_Tp>::type* type; };
2003
89898034
DK
2004 template<typename _Tp>
2005 struct add_pointer
2006 : public __add_pointer_helper<_Tp>
2007 { };
2008
4457e88c
JW
2009#if __cplusplus > 201103L
2010 /// Alias template for remove_pointer
2011 template<typename _Tp>
2012 using remove_pointer_t = typename remove_pointer<_Tp>::type;
2013
2014 /// Alias template for add_pointer
2015 template<typename _Tp>
2016 using add_pointer_t = typename add_pointer<_Tp>::type;
2017#endif
123c516a
PC
2018
2019 template<std::size_t _Len>
2020 struct __aligned_storage_msa
2021 {
2022 union __type
2023 {
2024 unsigned char __data[_Len];
2025 struct __attribute__((__aligned__)) { } __align;
2026 };
2027 };
2028
2029 /**
2030 * @brief Alignment type.
2031 *
2032 * The value of _Align is a default-alignment which shall be the
2033 * most stringent alignment requirement for any C++ object type
2034 * whose size is no greater than _Len (3.9). The member typedef
2035 * type shall be a POD type suitable for use as uninitialized
2036 * storage for any object whose size is at most _Len and whose
2037 * alignment is a divisor of _Align.
2038 */
2039 template<std::size_t _Len, std::size_t _Align =
2040 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2041 struct aligned_storage
2042 {
2043 union type
2044 {
2045 unsigned char __data[_Len];
2046 struct __attribute__((__aligned__((_Align)))) { } __align;
2047 };
2048 };
2049
d3718027
RS
2050 template <typename... _Types>
2051 struct __strictest_alignment
2052 {
2053 static const size_t _S_alignment = 0;
2054 static const size_t _S_size = 0;
2055 };
2056
2057 template <typename _Tp, typename... _Types>
2058 struct __strictest_alignment<_Tp, _Types...>
2059 {
2060 static const size_t _S_alignment =
2061 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2062 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2063 static const size_t _S_size =
2064 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2065 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2066 };
2067
2068 /**
2069 * @brief Provide aligned storage for types.
2070 *
2071 * [meta.trans.other]
2072 *
2073 * Provides aligned storage for any of the provided types of at
2074 * least size _Len.
2075 *
2076 * @see aligned_storage
2077 */
2078 template <size_t _Len, typename... _Types>
2079 struct aligned_union
2080 {
2081 private:
2082 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2083
2084 using __strictest = __strictest_alignment<_Types...>;
2085 static const size_t _S_len = _Len > __strictest::_S_size
2086 ? _Len : __strictest::_S_size;
2087 public:
2088 /// The value of the strictest alignment of _Types.
2089 static const size_t alignment_value = __strictest::_S_alignment;
2090 /// The storage.
2091 typedef typename aligned_storage<_S_len, alignment_value>::type type;
2092 };
2093
2094 template <size_t _Len, typename... _Types>
2095 const size_t aligned_union<_Len, _Types...>::alignment_value;
123c516a
PC
2096
2097 // Decay trait for arrays and functions, used for perfect forwarding
2098 // in make_pair, make_tuple, etc.
2099 template<typename _Up,
2100 bool _IsArray = is_array<_Up>::value,
2101 bool _IsFunction = is_function<_Up>::value>
2102 struct __decay_selector;
2103
2104 // NB: DR 705.
2105 template<typename _Up>
2106 struct __decay_selector<_Up, false, false>
2107 { typedef typename remove_cv<_Up>::type __type; };
2108
2109 template<typename _Up>
2110 struct __decay_selector<_Up, true, false>
2111 { typedef typename remove_extent<_Up>::type* __type; };
2112
2113 template<typename _Up>
2114 struct __decay_selector<_Up, false, true>
2115 { typedef typename add_pointer<_Up>::type __type; };
2116
2117 /// decay
2118 template<typename _Tp>
2119 class decay
2120 {
2121 typedef typename remove_reference<_Tp>::type __remove_type;
2122
2123 public:
2124 typedef typename __decay_selector<__remove_type>::__type type;
2125 };
2126
2127 template<typename _Tp>
2128 class reference_wrapper;
2129
2130 // Helper which adds a reference to a type when given a reference_wrapper
2131 template<typename _Tp>
2132 struct __strip_reference_wrapper
2133 {
2134 typedef _Tp __type;
2135 };
2136
2137 template<typename _Tp>
2138 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2139 {
2140 typedef _Tp& __type;
2141 };
2142
123c516a
PC
2143 template<typename _Tp>
2144 struct __decay_and_strip
2145 {
2146 typedef typename __strip_reference_wrapper<
2147 typename decay<_Tp>::type>::__type __type;
2148 };
2149
2150
123c516a 2151 // Primary template.
13901e4b 2152 /// Define a member typedef @c type only if a boolean constant is true.
123c516a
PC
2153 template<bool, typename _Tp = void>
2154 struct enable_if
2155 { };
2156
2157 // Partial specialization for true.
2158 template<typename _Tp>
2159 struct enable_if<true, _Tp>
2160 { typedef _Tp type; };
2161
23df8534
JW
2162 template<typename... _Cond>
2163 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
123c516a 2164
123c516a 2165 // Primary template.
13901e4b 2166 /// Define a member typedef @c type to one of two argument types.
123c516a
PC
2167 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2168 struct conditional
2169 { typedef _Iftrue type; };
2170
2171 // Partial specialization for false.
2172 template<typename _Iftrue, typename _Iffalse>
2173 struct conditional<false, _Iftrue, _Iffalse>
2174 { typedef _Iffalse type; };
2175
5b9daa7e 2176 /// common_type
cfa9a96b
CF
2177 template<typename... _Tp>
2178 struct common_type;
2179
c0ffa2ba 2180 // Sfinae-friendly common_type implementation:
b3618b71
DK
2181
2182 struct __do_common_type_impl
2183 {
2184 template<typename _Tp, typename _Up>
6c5173c0 2185 static __success_type<typename decay<decltype
fe4e4e3b 2186 (true ? std::declval<_Tp>()
6c5173c0 2187 : std::declval<_Up>())>::type> _S_test(int);
b3618b71
DK
2188
2189 template<typename, typename>
2190 static __failure_type _S_test(...);
2191 };
2192
2193 template<typename _Tp, typename _Up>
2194 struct __common_type_impl
2195 : private __do_common_type_impl
2196 {
2197 typedef decltype(_S_test<_Tp, _Up>(0)) type;
2198 };
2199
2200 struct __do_member_type_wrapper
2201 {
2202 template<typename _Tp>
2203 static __success_type<typename _Tp::type> _S_test(int);
2204
2205 template<typename>
2206 static __failure_type _S_test(...);
2207 };
2208
2209 template<typename _Tp>
2210 struct __member_type_wrapper
2211 : private __do_member_type_wrapper
2212 {
2213 typedef decltype(_S_test<_Tp>(0)) type;
2214 };
2215
2216 template<typename _CTp, typename... _Args>
2217 struct __expanded_common_type_wrapper
2218 {
2219 typedef common_type<typename _CTp::type, _Args...> type;
2220 };
2221
2222 template<typename... _Args>
2223 struct __expanded_common_type_wrapper<__failure_type, _Args...>
2224 { typedef __failure_type type; };
2225
cfa9a96b
CF
2226 template<typename _Tp>
2227 struct common_type<_Tp>
6c5173c0 2228 { typedef typename decay<_Tp>::type type; };
cfa9a96b
CF
2229
2230 template<typename _Tp, typename _Up>
7274deff 2231 struct common_type<_Tp, _Up>
b3618b71
DK
2232 : public __common_type_impl<_Tp, _Up>::type
2233 { };
cfa9a96b
CF
2234
2235 template<typename _Tp, typename _Up, typename... _Vp>
2236 struct common_type<_Tp, _Up, _Vp...>
b3618b71
DK
2237 : public __expanded_common_type_wrapper<typename __member_type_wrapper<
2238 common_type<_Tp, _Up>>::type, _Vp...>::type
2239 { };
7274deff 2240
13901e4b 2241 /// The underlying type of an enum.
a47407f6
PC
2242 template<typename _Tp>
2243 struct underlying_type
2244 {
2245 typedef __underlying_type(_Tp) type;
2246 };
123c516a 2247
7274deff
PC
2248 template<typename _Tp>
2249 struct __declval_protector
2250 {
2251 static const bool __stop = false;
2252 static typename add_rvalue_reference<_Tp>::type __delegate();
2253 };
2254
2255 template<typename _Tp>
2256 inline typename add_rvalue_reference<_Tp>::type
e4f32cb0 2257 declval() noexcept
7274deff
PC
2258 {
2259 static_assert(__declval_protector<_Tp>::__stop,
2260 "declval() must not be used!");
2261 return __declval_protector<_Tp>::__delegate();
2262 }
1041daba 2263
be7f7822
JW
2264 /// result_of
2265 template<typename _Signature>
2266 class result_of;
2267
c0ffa2ba 2268 // Sfinae-friendly result_of implementation:
83ddb39f 2269
a15f7cb8
ESR
2270#define __cpp_lib_result_of_sfinae 201210
2271
93e95400
JW
2272 struct __invoke_memfun_ref { };
2273 struct __invoke_memfun_deref { };
2274 struct __invoke_memobj_ref { };
2275 struct __invoke_memobj_deref { };
2276 struct __invoke_other { };
2277
2278 // Associate a tag type with a specialization of __success_type.
2279 template<typename _Tp, typename _Tag>
2280 struct __result_of_success : __success_type<_Tp>
2281 { using __invoke_type = _Tag; };
2282
83ddb39f
DK
2283 // [func.require] paragraph 1 bullet 1:
2284 struct __result_of_memfun_ref_impl
2285 {
2286 template<typename _Fp, typename _Tp1, typename... _Args>
93e95400 2287 static __result_of_success<decltype(
83ddb39f 2288 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
93e95400 2289 ), __invoke_memfun_ref> _S_test(int);
83ddb39f
DK
2290
2291 template<typename...>
2292 static __failure_type _S_test(...);
2293 };
2294
2295 template<typename _MemPtr, typename _Arg, typename... _Args>
2296 struct __result_of_memfun_ref
2297 : private __result_of_memfun_ref_impl
2298 {
2299 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2300 };
2301
2302 // [func.require] paragraph 1 bullet 2:
2303 struct __result_of_memfun_deref_impl
2304 {
2305 template<typename _Fp, typename _Tp1, typename... _Args>
93e95400 2306 static __result_of_success<decltype(
83ddb39f 2307 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
93e95400 2308 ), __invoke_memfun_deref> _S_test(int);
83ddb39f
DK
2309
2310 template<typename...>
2311 static __failure_type _S_test(...);
2312 };
2313
2314 template<typename _MemPtr, typename _Arg, typename... _Args>
2315 struct __result_of_memfun_deref
2316 : private __result_of_memfun_deref_impl
2317 {
2318 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2319 };
2320
2321 // [func.require] paragraph 1 bullet 3:
2322 struct __result_of_memobj_ref_impl
2323 {
2324 template<typename _Fp, typename _Tp1>
93e95400 2325 static __result_of_success<decltype(
83ddb39f 2326 std::declval<_Tp1>().*std::declval<_Fp>()
93e95400 2327 ), __invoke_memobj_ref> _S_test(int);
83ddb39f
DK
2328
2329 template<typename, typename>
2330 static __failure_type _S_test(...);
2331 };
2332
2333 template<typename _MemPtr, typename _Arg>
2334 struct __result_of_memobj_ref
2335 : private __result_of_memobj_ref_impl
2336 {
2337 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2338 };
2339
2340 // [func.require] paragraph 1 bullet 4:
2341 struct __result_of_memobj_deref_impl
2342 {
2343 template<typename _Fp, typename _Tp1>
93e95400 2344 static __result_of_success<decltype(
83ddb39f 2345 (*std::declval<_Tp1>()).*std::declval<_Fp>()
93e95400 2346 ), __invoke_memobj_deref> _S_test(int);
83ddb39f
DK
2347
2348 template<typename, typename>
2349 static __failure_type _S_test(...);
2350 };
2351
be7f7822 2352 template<typename _MemPtr, typename _Arg>
83ddb39f
DK
2353 struct __result_of_memobj_deref
2354 : private __result_of_memobj_deref_impl
2355 {
2356 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2357 };
2358
2359 template<typename _MemPtr, typename _Arg>
2360 struct __result_of_memobj;
be7f7822
JW
2361
2362 template<typename _Res, typename _Class, typename _Arg>
83ddb39f 2363 struct __result_of_memobj<_Res _Class::*, _Arg>
be7f7822 2364 {
83ddb39f
DK
2365 typedef typename remove_cv<typename remove_reference<
2366 _Arg>::type>::type _Argval;
2367 typedef _Res _Class::* _MemPtr;
2368 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2369 is_base_of<_Class, _Argval>>::value,
2370 __result_of_memobj_ref<_MemPtr, _Arg>,
2371 __result_of_memobj_deref<_MemPtr, _Arg>
2372 >::type::type type;
be7f7822
JW
2373 };
2374
83ddb39f
DK
2375 template<typename _MemPtr, typename _Arg, typename... _Args>
2376 struct __result_of_memfun;
be7f7822
JW
2377
2378 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
83ddb39f 2379 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
be7f7822 2380 {
83ddb39f
DK
2381 typedef typename remove_cv<typename remove_reference<
2382 _Arg>::type>::type _Argval;
2383 typedef _Res _Class::* _MemPtr;
2384 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2385 is_base_of<_Class, _Argval>>::value,
2386 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2387 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2388 >::type::type type;
be7f7822
JW
2389 };
2390
93e95400
JW
2391 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2392 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2393 // as the object expression
93e95400
JW
2394
2395 template<typename _Res, typename _Class, typename _Arg>
2396 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>>
f3d7dd52
JW
2397 : __result_of_memobj_ref<_Res _Class::*, _Arg&>
2398 { };
93e95400
JW
2399
2400 template<typename _Res, typename _Class, typename _Arg>
2401 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>&>
f3d7dd52
JW
2402 : __result_of_memobj_ref<_Res _Class::*, _Arg&>
2403 { };
2404
2405 template<typename _Res, typename _Class, typename _Arg>
2406 struct __result_of_memobj<_Res _Class::*, const reference_wrapper<_Arg>&>
2407 : __result_of_memobj_ref<_Res _Class::*, _Arg&>
93e95400
JW
2408 { };
2409
2410 template<typename _Res, typename _Class, typename _Arg>
2411 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>&&>
f3d7dd52
JW
2412 : __result_of_memobj_ref<_Res _Class::*, _Arg&>
2413 { };
2414
2415 template<typename _Res, typename _Class, typename _Arg>
2416 struct __result_of_memobj<_Res _Class::*, const reference_wrapper<_Arg>&&>
2417 : __result_of_memobj_ref<_Res _Class::*, _Arg&>
93e95400
JW
2418 { };
2419
2420 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2421 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>, _Args...>
f3d7dd52
JW
2422 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>
2423 { };
93e95400
JW
2424
2425 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2426 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>&,
2427 _Args...>
f3d7dd52
JW
2428 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>
2429 { };
2430
2431 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2432 struct __result_of_memfun<_Res _Class::*, const reference_wrapper<_Arg>&,
2433 _Args...>
2434 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>
93e95400
JW
2435 { };
2436
2437 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2438 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>&&,
2439 _Args...>
f3d7dd52
JW
2440 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>
2441 { };
2442
2443 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2444 struct __result_of_memfun<_Res _Class::*, const reference_wrapper<_Arg>&&,
2445 _Args...>
2446 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>
93e95400
JW
2447 { };
2448
be7f7822 2449 template<bool, bool, typename _Functor, typename... _ArgTypes>
83ddb39f 2450 struct __result_of_impl
be7f7822 2451 {
83ddb39f 2452 typedef __failure_type type;
be7f7822
JW
2453 };
2454
2455 template<typename _MemPtr, typename _Arg>
83ddb39f
DK
2456 struct __result_of_impl<true, false, _MemPtr, _Arg>
2457 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg>
c4db9a77 2458 { };
be7f7822 2459
83ddb39f
DK
2460 template<typename _MemPtr, typename _Arg, typename... _Args>
2461 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2462 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...>
c4db9a77 2463 { };
be7f7822 2464
83ddb39f
DK
2465 // [func.require] paragraph 1 bullet 5:
2466 struct __result_of_other_impl
2467 {
2468 template<typename _Fn, typename... _Args>
93e95400 2469 static __result_of_success<decltype(
83ddb39f 2470 std::declval<_Fn>()(std::declval<_Args>()...)
93e95400 2471 ), __invoke_other> _S_test(int);
83ddb39f
DK
2472
2473 template<typename...>
2474 static __failure_type _S_test(...);
2475 };
2476
be7f7822 2477 template<typename _Functor, typename... _ArgTypes>
83ddb39f
DK
2478 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2479 : private __result_of_other_impl
be7f7822 2480 {
83ddb39f 2481 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
be7f7822
JW
2482 };
2483
83ddb39f
DK
2484 template<typename _Functor, typename... _ArgTypes>
2485 struct result_of<_Functor(_ArgTypes...)>
2486 : public __result_of_impl<
2487 is_member_object_pointer<
2488 typename remove_reference<_Functor>::type
2489 >::value,
2490 is_member_function_pointer<
2491 typename remove_reference<_Functor>::type
2492 >::value,
2493 _Functor, _ArgTypes...
2494 >::type
2495 { };
c0ffa2ba 2496
4457e88c
JW
2497#if __cplusplus > 201103L
2498 /// Alias template for aligned_storage
2499 template<size_t _Len, size_t _Align =
2500 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2501 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
2502
d3718027
RS
2503 template <size_t _Len, typename... _Types>
2504 using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
2505
4457e88c
JW
2506 /// Alias template for decay
2507 template<typename _Tp>
2508 using decay_t = typename decay<_Tp>::type;
2509
2510 /// Alias template for enable_if
2511 template<bool _Cond, typename _Tp = void>
2512 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2513
2514 /// Alias template for conditional
2515 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2516 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2517
2518 /// Alias template for common_type
2519 template<typename... _Tp>
2520 using common_type_t = typename common_type<_Tp...>::type;
2521
2522 /// Alias template for underlying_type
2523 template<typename _Tp>
2524 using underlying_type_t = typename underlying_type<_Tp>::type;
2525
2526 /// Alias template for result_of
2527 template<typename _Tp>
2528 using result_of_t = typename result_of<_Tp>::type;
2529#endif
2530
847e9cf8
JW
2531 template<typename...> using __void_t = void;
2532
bd1eb5e0
JW
2533#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
2534#define __cpp_lib_void_t 201411
2535 /// A metafunction that always yields void, used for detecting valid types.
2536 template<typename...> using void_t = void;
2537#endif
2538
6af6bef4
JW
2539 /// Implementation of the detection idiom (negative case).
2540 template<typename _Default, typename _AlwaysVoid,
2541 template<typename...> class _Op, typename... _Args>
2542 struct __detector
2543 {
2544 using value_t = false_type;
2545 using type = _Default;
2546 };
2547
2548 /// Implementation of the detection idiom (positive case).
2549 template<typename _Default, template<typename...> class _Op,
2550 typename... _Args>
2551 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
2552 {
2553 using value_t = true_type;
2554 using type = _Op<_Args...>;
2555 };
2556
2557 // Detect whether _Op<_Args...> is a valid type, use _Default if not.
2558 template<typename _Default, template<typename...> class _Op,
2559 typename... _Args>
2560 using __detected_or = __detector<_Default, void, _Op, _Args...>;
2561
2562 // _Op<_Args...> if that is a valid type, otherwise _Default.
2563 template<typename _Default, template<typename...> class _Op,
2564 typename... _Args>
2565 using __detected_or_t
2566 = typename __detected_or<_Default, _Op, _Args...>::type;
2567
2568 // _Op<_Args...> if that is a valid type, otherwise _Default<_Args...>.
2569 template<template<typename...> class _Default,
2570 template<typename...> class _Op, typename... _Args>
2571 using __detected_or_t_ =
2572 __detected_or_t<_Default<_Args...>, _Op, _Args...>;
2573
c0ffa2ba 2574 /// @} group metaprogramming
847e9cf8 2575
033b71ce
PC
2576 /**
2577 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2578 * member type _NTYPE.
2579 */
82b12c4b 2580#define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
847e9cf8 2581 template<typename _Tp, typename = __void_t<>> \
82b12c4b 2582 struct __has_##_NTYPE \
847e9cf8
JW
2583 : false_type \
2584 { }; \
2585 template<typename _Tp> \
2586 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2587 : true_type \
033b71ce
PC
2588 { };
2589
ddb63209
VV
2590
2591 namespace __is_swappable_impl {
2592 template <typename _Tp, typename=void>
2593 struct __is_swappable : public false_type
2594 { };
2595 }
2596
2597 template<typename _Tp>
2598 inline
2599 typename enable_if<__and_<is_move_constructible<_Tp>,
2600 is_move_assignable<_Tp>>::value>::type
2601 swap(_Tp&, _Tp&)
2602 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
2603 is_nothrow_move_assignable<_Tp>>::value);
2604
2605 template<typename _Tp, size_t _Nm>
2606 inline
2607 typename enable_if<__is_swappable_impl::__is_swappable<_Tp>::value>::type
2608 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
2609 noexcept(noexcept(swap(*__a, *__b)));
2610
2611 namespace __is_swappable_impl {
2612 using std::swap;
2613
2614 template <typename _Tp>
2615 struct __is_swappable<_Tp, __void_t<decltype(swap(declval<_Tp&>(),
2616 declval<_Tp&>()))>>
2617 : public true_type
2618 { };
2619 }
2620
2621 template <bool, typename _Tp>
2622 struct __is_nothrow_swappable_impl
2623 : public __bool_constant<noexcept(swap(declval<_Tp&>(), declval<_Tp&>()))>
2624 { };
2625
2626 template <typename _Tp>
2627 struct __is_nothrow_swappable_impl<false, _Tp> : public false_type
2628 { };
2629
2630 template <typename _Tp>
2631 struct __is_nothrow_swappable
2632 : public __is_nothrow_swappable_impl<
2633 __is_swappable_impl::__is_swappable<_Tp>::value, _Tp>
2634 { };
2635
12ffa228 2636_GLIBCXX_END_NAMESPACE_VERSION
c0ffa2ba 2637} // namespace std
7b50cdef 2638
734f5023 2639#endif // C++11
57317d2a 2640
7274deff 2641#endif // _GLIBCXX_TYPE_TRAITS