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