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