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