]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/std/type_traits
missed error format change in previous commit
[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
f7632193 718 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>
123c516a
PC
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
f7632193 747 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>
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 864 : public __and_<__not_<is_void<_Tp>>,
f7632193 865 __is_default_constructible_impl<_Tp>>
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
f7632193 880 remove_all_extents<_Tp>::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>,
f7632193 960 __is_direct_constructible_impl<_Tp, _Arg>>
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>
f7632193 1032 >>>
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
f7632193 1147 remove_all_extents<_Tp>::type>>
65cee9bd
PC
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>,
f7632193 1159 __is_nt_default_constructible_impl<_Tp>>
65cee9bd 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 1181 : public __and_<is_constructible<_Tp, _Args...>,
f7632193 1182 __is_nt_constructible_impl<_Tp, _Args...>>
65cee9bd
PC
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>,
f7632193 1288 __is_nt_assignable_impl<_Tp, _Up>>
f263981a
PC
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,
f7632193 1331 __is_trivially_constructible(_Tp, _Args...)>>
f5e523b7 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
f7632193
VV
1340 struct __do_is_implicitly_default_constructible_impl
1341 {
1342 template <typename _Tp>
1343 static void __helper(const _Tp&);
1344
1345 template <typename _Tp>
1346 static true_type __test(const _Tp&,
1347 decltype(__helper<const _Tp&>({}))* = 0);
1348
1349 static false_type __test(...);
1350 };
1351
1352 template<typename _Tp>
1353 struct __is_implicitly_default_constructible_impl
1354 : public __do_is_implicitly_default_constructible_impl
1355 {
1356 typedef decltype(__test(declval<_Tp>())) type;
1357 };
1358
1359 template<typename _Tp>
1360 struct __is_implicitly_default_constructible_safe
1361 : public __is_implicitly_default_constructible_impl<_Tp>::type
1362 { };
1363
1364 template <typename _Tp>
1365 struct __is_implicitly_default_constructible
1366 : public __and_<is_default_constructible<_Tp>,
1367 __is_implicitly_default_constructible_safe<_Tp>>
1368 { };
1369
f5e523b7
VV
1370 /// is_trivially_copy_constructible
1371 template<typename _Tp>
1372 struct is_trivially_copy_constructible
1373 : public __and_<is_copy_constructible<_Tp>,
1374 integral_constant<bool,
f7632193 1375 __is_trivially_constructible(_Tp, const _Tp&)>>
f5e523b7
VV
1376 { };
1377
1378 /// is_trivially_move_constructible
1379 template<typename _Tp>
1380 struct is_trivially_move_constructible
1381 : public __and_<is_move_constructible<_Tp>,
1382 integral_constant<bool,
f7632193 1383 __is_trivially_constructible(_Tp, _Tp&&)>>
f5e523b7 1384 { };
6a9ecd34 1385
f5e523b7
VV
1386 /// is_trivially_assignable
1387 template<typename _Tp, typename _Up>
1388 struct is_trivially_assignable
1389 : public __and_<is_assignable<_Tp, _Up>,
1390 integral_constant<bool,
f7632193 1391 __is_trivially_assignable(_Tp, _Up)>>
f5e523b7 1392 { };
6a9ecd34 1393
f5e523b7
VV
1394 /// is_trivially_copy_assignable
1395 template<typename _Tp>
1396 struct is_trivially_copy_assignable
1397 : public __and_<is_copy_assignable<_Tp>,
1398 integral_constant<bool,
f7632193 1399 __is_trivially_assignable(_Tp&, const _Tp&)>>
f5e523b7 1400 { };
6a9ecd34 1401
f5e523b7
VV
1402 /// is_trivially_move_assignable
1403 template<typename _Tp>
1404 struct is_trivially_move_assignable
1405 : public __and_<is_move_assignable<_Tp>,
1406 integral_constant<bool,
f7632193 1407 __is_trivially_assignable(_Tp&, _Tp&&)>>
f5e523b7 1408 { };
6a9ecd34
PC
1409
1410 /// is_trivially_destructible
1411 template<typename _Tp>
1412 struct is_trivially_destructible
1413 : public __and_<is_destructible<_Tp>, integral_constant<bool,
f7632193 1414 __has_trivial_destructor(_Tp)>>
6a9ecd34
PC
1415 { };
1416
1417 /// has_trivial_default_constructor (temporary legacy)
e133ace8
PC
1418 template<typename _Tp>
1419 struct has_trivial_default_constructor
1420 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
c66b93fe 1421 { } _GLIBCXX_DEPRECATED;
e133ace8 1422
6a9ecd34 1423 /// has_trivial_copy_constructor (temporary legacy)
e133ace8
PC
1424 template<typename _Tp>
1425 struct has_trivial_copy_constructor
1426 : public integral_constant<bool, __has_trivial_copy(_Tp)>
c66b93fe 1427 { } _GLIBCXX_DEPRECATED;
e133ace8 1428
6a9ecd34 1429 /// has_trivial_copy_assign (temporary legacy)
e133ace8 1430 template<typename _Tp>
6f5e9b8d 1431 struct has_trivial_copy_assign
e133ace8 1432 : public integral_constant<bool, __has_trivial_assign(_Tp)>
c66b93fe 1433 { } _GLIBCXX_DEPRECATED;
e133ace8 1434
123c516a
PC
1435 /// has_virtual_destructor
1436 template<typename _Tp>
1437 struct has_virtual_destructor
1438 : public integral_constant<bool, __has_virtual_destructor(_Tp)>
1439 { };
1440
1441
1442 // type property queries.
1443
1444 /// alignment_of
1445 template<typename _Tp>
1446 struct alignment_of
1447 : public integral_constant<std::size_t, __alignof__(_Tp)> { };
1448
1449 /// rank
1450 template<typename>
1451 struct rank
1452 : public integral_constant<std::size_t, 0> { };
1453
1454 template<typename _Tp, std::size_t _Size>
1455 struct rank<_Tp[_Size]>
1456 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1457
1458 template<typename _Tp>
1459 struct rank<_Tp[]>
1460 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
1461
1462 /// extent
1463 template<typename, unsigned _Uint>
1464 struct extent
1465 : public integral_constant<std::size_t, 0> { };
1466
1467 template<typename _Tp, unsigned _Uint, std::size_t _Size>
1468 struct extent<_Tp[_Size], _Uint>
1469 : public integral_constant<std::size_t,
1470 _Uint == 0 ? _Size : extent<_Tp,
1471 _Uint - 1>::value>
1472 { };
1473
1474 template<typename _Tp, unsigned _Uint>
1475 struct extent<_Tp[], _Uint>
1476 : public integral_constant<std::size_t,
1477 _Uint == 0 ? 0 : extent<_Tp,
1478 _Uint - 1>::value>
1479 { };
1480
1481
c0ffa2ba 1482 // Type relations.
123c516a
PC
1483
1484 /// is_same
1485 template<typename, typename>
1486 struct is_same
1487 : public false_type { };
1488
1489 template<typename _Tp>
1490 struct is_same<_Tp, _Tp>
1491 : public true_type { };
b0302c68 1492
939759fc 1493 /// is_base_of
e133ace8
PC
1494 template<typename _Base, typename _Derived>
1495 struct is_base_of
1496 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
1497 { };
1498
297f34d7 1499 template<typename _From, typename _To,
123c516a
PC
1500 bool = __or_<is_void<_From>, is_function<_To>,
1501 is_array<_To>>::value>
297f34d7 1502 struct __is_convertible_helper
82b12c4b 1503 { typedef typename is_void<_To>::type type; };
297f34d7 1504
e133ace8 1505 template<typename _From, typename _To>
b0302c68 1506 class __is_convertible_helper<_From, _To, false>
e133ace8 1507 {
82b12c4b
FD
1508 template<typename _To1>
1509 static void __test_aux(_To1);
8e7d962a 1510
82b12c4b
FD
1511 template<typename _From1, typename _To1,
1512 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
1513 static true_type
8e7d962a
PC
1514 __test(int);
1515
1516 template<typename, typename>
82b12c4b
FD
1517 static false_type
1518 __test(...);
297f34d7 1519
e133ace8 1520 public:
82b12c4b 1521 typedef decltype(__test<_From, _To>(0)) type;
e133ace8
PC
1522 };
1523
82b12c4b 1524
b0302c68 1525 /// is_convertible
e133ace8
PC
1526 template<typename _From, typename _To>
1527 struct is_convertible
82b12c4b 1528 : public __is_convertible_helper<_From, _To>::type
e133ace8
PC
1529 { };
1530
fd735b6a 1531
c0ffa2ba 1532 // Const-volatile modifications.
7b50cdef 1533
123c516a 1534 /// remove_const
7b50cdef 1535 template<typename _Tp>
123c516a
PC
1536 struct remove_const
1537 { typedef _Tp type; };
7b50cdef 1538
123c516a
PC
1539 template<typename _Tp>
1540 struct remove_const<_Tp const>
1541 { typedef _Tp type; };
1542
1543 /// remove_volatile
1544 template<typename _Tp>
1545 struct remove_volatile
1546 { typedef _Tp type; };
7b50cdef 1547
123c516a
PC
1548 template<typename _Tp>
1549 struct remove_volatile<_Tp volatile>
1550 { typedef _Tp type; };
1551
1552 /// remove_cv
1553 template<typename _Tp>
1554 struct remove_cv
1555 {
1556 typedef typename
1557 remove_const<typename remove_volatile<_Tp>::type>::type type;
1558 };
1559
1560 /// add_const
1561 template<typename _Tp>
1562 struct add_const
1563 { typedef _Tp const type; };
1564
1565 /// add_volatile
1566 template<typename _Tp>
1567 struct add_volatile
1568 { typedef _Tp volatile type; };
1569
1570 /// add_cv
1571 template<typename _Tp>
1572 struct add_cv
1573 {
1574 typedef typename
1575 add_const<typename add_volatile<_Tp>::type>::type type;
1576 };
7b50cdef 1577
4457e88c 1578#if __cplusplus > 201103L
a15f7cb8
ESR
1579
1580#define __cpp_lib_transformation_trait_aliases 201304
1581
4457e88c
JW
1582 /// Alias template for remove_const
1583 template<typename _Tp>
1584 using remove_const_t = typename remove_const<_Tp>::type;
1585
1586 /// Alias template for remove_volatile
1587 template<typename _Tp>
1588 using remove_volatile_t = typename remove_volatile<_Tp>::type;
1589
1590 /// Alias template for remove_cv
1591 template<typename _Tp>
1592 using remove_cv_t = typename remove_cv<_Tp>::type;
1593
1594 /// Alias template for add_const
1595 template<typename _Tp>
1596 using add_const_t = typename add_const<_Tp>::type;
1597
1598 /// Alias template for add_volatile
1599 template<typename _Tp>
1600 using add_volatile_t = typename add_volatile<_Tp>::type;
1601
1602 /// Alias template for add_cv
1603 template<typename _Tp>
1604 using add_cv_t = typename add_cv<_Tp>::type;
1605#endif
7b50cdef 1606
123c516a 1607 // Reference transformations.
7b50cdef 1608
123c516a
PC
1609 /// remove_reference
1610 template<typename _Tp>
1611 struct remove_reference
1612 { typedef _Tp type; };
7b50cdef 1613
123c516a
PC
1614 template<typename _Tp>
1615 struct remove_reference<_Tp&>
1616 { typedef _Tp type; };
7b50cdef 1617
123c516a
PC
1618 template<typename _Tp>
1619 struct remove_reference<_Tp&&>
1620 { typedef _Tp type; };
1621
89898034 1622 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
123c516a
PC
1623 struct __add_lvalue_reference_helper
1624 { typedef _Tp type; };
7b50cdef 1625
5e108459 1626 template<typename _Tp>
89898034 1627 struct __add_lvalue_reference_helper<_Tp, true>
123c516a 1628 { typedef _Tp& type; };
5e108459 1629
123c516a 1630 /// add_lvalue_reference
5e108459 1631 template<typename _Tp>
123c516a
PC
1632 struct add_lvalue_reference
1633 : public __add_lvalue_reference_helper<_Tp>
1634 { };
1635
89898034 1636 template<typename _Tp, bool = __is_referenceable<_Tp>::value>
123c516a
PC
1637 struct __add_rvalue_reference_helper
1638 { typedef _Tp type; };
5e108459
PC
1639
1640 template<typename _Tp>
123c516a
PC
1641 struct __add_rvalue_reference_helper<_Tp, true>
1642 { typedef _Tp&& type; };
5e108459 1643
123c516a 1644 /// add_rvalue_reference
5e108459 1645 template<typename _Tp>
123c516a
PC
1646 struct add_rvalue_reference
1647 : public __add_rvalue_reference_helper<_Tp>
1648 { };
5e108459 1649
4457e88c
JW
1650#if __cplusplus > 201103L
1651 /// Alias template for remove_reference
1652 template<typename _Tp>
1653 using remove_reference_t = typename remove_reference<_Tp>::type;
1654
1655 /// Alias template for add_lvalue_reference
1656 template<typename _Tp>
1657 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1658
1659 /// Alias template for add_rvalue_reference
1660 template<typename _Tp>
1661 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1662#endif
7b50cdef 1663
c0ffa2ba 1664 // Sign modifications.
123c516a 1665
7b50cdef
BK
1666 // Utility for constructing identically cv-qualified types.
1667 template<typename _Unqualified, bool _IsConst, bool _IsVol>
1668 struct __cv_selector;
1669
1670 template<typename _Unqualified>
1671 struct __cv_selector<_Unqualified, false, false>
1672 { typedef _Unqualified __type; };
1673
1674 template<typename _Unqualified>
1675 struct __cv_selector<_Unqualified, false, true>
1676 { typedef volatile _Unqualified __type; };
1677
1678 template<typename _Unqualified>
1679 struct __cv_selector<_Unqualified, true, false>
1680 { typedef const _Unqualified __type; };
1681
1682 template<typename _Unqualified>
1683 struct __cv_selector<_Unqualified, true, true>
1684 { typedef const volatile _Unqualified __type; };
1685
1686 template<typename _Qualified, typename _Unqualified,
1687 bool _IsConst = is_const<_Qualified>::value,
1688 bool _IsVol = is_volatile<_Qualified>::value>
b0302c68 1689 class __match_cv_qualifiers
7b50cdef 1690 {
7b50cdef
BK
1691 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
1692
1693 public:
1694 typedef typename __match::__type __type;
1695 };
1696
7b50cdef
BK
1697 // Utility for finding the unsigned versions of signed integral types.
1698 template<typename _Tp>
e133ace8
PC
1699 struct __make_unsigned
1700 { typedef _Tp __type; };
7b50cdef
BK
1701
1702 template<>
1703 struct __make_unsigned<char>
1704 { typedef unsigned char __type; };
1705
1706 template<>
1707 struct __make_unsigned<signed char>
1708 { typedef unsigned char __type; };
1709
7b50cdef
BK
1710 template<>
1711 struct __make_unsigned<short>
1712 { typedef unsigned short __type; };
1713
1714 template<>
1715 struct __make_unsigned<int>
1716 { typedef unsigned int __type; };
1717
1718 template<>
1719 struct __make_unsigned<long>
1720 { typedef unsigned long __type; };
1721
1722 template<>
1723 struct __make_unsigned<long long>
1724 { typedef unsigned long long __type; };
1725
c0eef1c8
JW
1726#if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__)
1727 template<>
1728 struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__>
1729 { };
1730#endif
1731
78a7c317
DD
1732#if defined(__GLIBCXX_TYPE_INT_N_0)
1733 template<>
1734 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0>
1735 { typedef unsigned __GLIBCXX_TYPE_INT_N_0 __type; };
1736#endif
1737#if defined(__GLIBCXX_TYPE_INT_N_1)
1738 template<>
1739 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1>
1740 { typedef unsigned __GLIBCXX_TYPE_INT_N_1 __type; };
1741#endif
1742#if defined(__GLIBCXX_TYPE_INT_N_2)
6d585f01 1743 template<>
78a7c317
DD
1744 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2>
1745 { typedef unsigned __GLIBCXX_TYPE_INT_N_2 __type; };
1746#endif
1747#if defined(__GLIBCXX_TYPE_INT_N_3)
1748 template<>
1749 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3>
1750 { typedef unsigned __GLIBCXX_TYPE_INT_N_3 __type; };
6d585f01
PC
1751#endif
1752
7b50cdef
BK
1753 // Select between integral and enum: not possible to be both.
1754 template<typename _Tp,
1755 bool _IsInt = is_integral<_Tp>::value,
7b50cdef 1756 bool _IsEnum = is_enum<_Tp>::value>
b0302c68
PC
1757 class __make_unsigned_selector;
1758
7b50cdef 1759 template<typename _Tp>
b0302c68 1760 class __make_unsigned_selector<_Tp, true, false>
7b50cdef 1761 {
7b50cdef
BK
1762 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
1763 typedef typename __unsignedt::__type __unsigned_type;
1764 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1765
1766 public:
1767 typedef typename __cv_unsigned::__type __type;
1768 };
1769
7b50cdef 1770 template<typename _Tp>
b0302c68 1771 class __make_unsigned_selector<_Tp, false, true>
7b50cdef 1772 {
a0230468
MM
1773 // With -fshort-enums, an enum may be as small as a char.
1774 typedef unsigned char __smallest;
1775 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
1776 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
ce2e6349 1777 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
73d81d3a
JW
1778 static const bool __b3 = sizeof(_Tp) <= sizeof(unsigned long);
1779 typedef conditional<__b3, unsigned long, unsigned long long> __cond3;
1780 typedef typename __cond3::type __cond3_type;
1781 typedef conditional<__b2, unsigned int, __cond3_type> __cond2;
a0230468
MM
1782 typedef typename __cond2::type __cond2_type;
1783 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
1784 typedef typename __cond1::type __cond1_type;
7b50cdef 1785
73d81d3a
JW
1786 typedef typename conditional<__b0, __smallest, __cond1_type>::type
1787 __unsigned_type;
1788 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
1789
7b50cdef 1790 public:
73d81d3a 1791 typedef typename __cv_unsigned::__type __type;
7b50cdef
BK
1792 };
1793
7b50cdef
BK
1794 // Given an integral/enum type, return the corresponding unsigned
1795 // integer type.
5b9daa7e
BK
1796 // Primary template.
1797 /// make_unsigned
7b50cdef
BK
1798 template<typename _Tp>
1799 struct make_unsigned
1800 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
1801
1802 // Integral, but don't define.
1803 template<>
1804 struct make_unsigned<bool>;
1805
1806
1807 // Utility for finding the signed versions of unsigned integral types.
1808 template<typename _Tp>
e133ace8
PC
1809 struct __make_signed
1810 { typedef _Tp __type; };
7b50cdef
BK
1811
1812 template<>
1813 struct __make_signed<char>
1814 { typedef signed char __type; };
1815
1816 template<>
1817 struct __make_signed<unsigned char>
1818 { typedef signed char __type; };
1819
7b50cdef
BK
1820 template<>
1821 struct __make_signed<unsigned short>
1822 { typedef signed short __type; };
1823
1824 template<>
1825 struct __make_signed<unsigned int>
1826 { typedef signed int __type; };
1827
1828 template<>
1829 struct __make_signed<unsigned long>
1830 { typedef signed long __type; };
1831
1832 template<>
1833 struct __make_signed<unsigned long long>
1834 { typedef signed long long __type; };
1835
c0eef1c8
JW
1836#if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__)
1837 template<>
1838 struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__>
1839 { };
1840#endif
1841
1842#ifdef _GLIBCXX_USE_C99_STDINT_TR1
1843 template<>
1844 struct __make_signed<char16_t> : __make_signed<uint_least16_t>
1845 { };
1846 template<>
1847 struct __make_signed<char32_t> : __make_signed<uint_least32_t>
1848 { };
1849#endif
1850
78a7c317
DD
1851#if defined(__GLIBCXX_TYPE_INT_N_0)
1852 template<>
1853 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0>
1854 { typedef __GLIBCXX_TYPE_INT_N_0 __type; };
1855#endif
1856#if defined(__GLIBCXX_TYPE_INT_N_1)
1857 template<>
1858 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1>
1859 { typedef __GLIBCXX_TYPE_INT_N_1 __type; };
1860#endif
1861#if defined(__GLIBCXX_TYPE_INT_N_2)
1862 template<>
1863 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2>
1864 { typedef __GLIBCXX_TYPE_INT_N_2 __type; };
1865#endif
1866#if defined(__GLIBCXX_TYPE_INT_N_3)
6d585f01 1867 template<>
78a7c317
DD
1868 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3>
1869 { typedef __GLIBCXX_TYPE_INT_N_3 __type; };
6d585f01
PC
1870#endif
1871
fb8ffd10 1872 // Select between integral and enum: not possible to be both.
7b50cdef
BK
1873 template<typename _Tp,
1874 bool _IsInt = is_integral<_Tp>::value,
7b50cdef 1875 bool _IsEnum = is_enum<_Tp>::value>
b0302c68
PC
1876 class __make_signed_selector;
1877
7b50cdef 1878 template<typename _Tp>
b0302c68 1879 class __make_signed_selector<_Tp, true, false>
7b50cdef 1880 {
7b50cdef
BK
1881 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
1882 typedef typename __signedt::__type __signed_type;
1883 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
1884
1885 public:
1886 typedef typename __cv_signed::__type __type;
1887 };
1888
7b50cdef 1889 template<typename _Tp>
b0302c68 1890 class __make_signed_selector<_Tp, false, true>
7b50cdef 1891 {
73d81d3a 1892 typedef typename __make_unsigned_selector<_Tp>::__type __unsigned_type;
7b50cdef
BK
1893
1894 public:
73d81d3a 1895 typedef typename __make_signed_selector<__unsigned_type>::__type __type;
7b50cdef
BK
1896 };
1897
7b50cdef
BK
1898 // Given an integral/enum type, return the corresponding signed
1899 // integer type.
5b9daa7e
BK
1900 // Primary template.
1901 /// make_signed
7b50cdef
BK
1902 template<typename _Tp>
1903 struct make_signed
1904 { typedef typename __make_signed_selector<_Tp>::__type type; };
1905
1906 // Integral, but don't define.
1907 template<>
1908 struct make_signed<bool>;
cfa9a96b 1909
4457e88c
JW
1910#if __cplusplus > 201103L
1911 /// Alias template for make_signed
1912 template<typename _Tp>
1913 using make_signed_t = typename make_signed<_Tp>::type;
1914
1915 /// Alias template for make_unsigned
1916 template<typename _Tp>
1917 using make_unsigned_t = typename make_unsigned<_Tp>::type;
1918#endif
123c516a 1919
c0ffa2ba 1920 // Array modifications.
123c516a
PC
1921
1922 /// remove_extent
1923 template<typename _Tp>
1924 struct remove_extent
1925 { typedef _Tp type; };
1926
1927 template<typename _Tp, std::size_t _Size>
1928 struct remove_extent<_Tp[_Size]>
1929 { typedef _Tp type; };
1930
1931 template<typename _Tp>
1932 struct remove_extent<_Tp[]>
1933 { typedef _Tp type; };
1934
1935 /// remove_all_extents
1936 template<typename _Tp>
1937 struct remove_all_extents
1938 { typedef _Tp type; };
1939
1940 template<typename _Tp, std::size_t _Size>
1941 struct remove_all_extents<_Tp[_Size]>
1942 { typedef typename remove_all_extents<_Tp>::type type; };
1943
1944 template<typename _Tp>
1945 struct remove_all_extents<_Tp[]>
1946 { typedef typename remove_all_extents<_Tp>::type type; };
1947
4457e88c
JW
1948#if __cplusplus > 201103L
1949 /// Alias template for remove_extent
1950 template<typename _Tp>
1951 using remove_extent_t = typename remove_extent<_Tp>::type;
1952
1953 /// Alias template for remove_all_extents
1954 template<typename _Tp>
1955 using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1956#endif
123c516a 1957
c0ffa2ba 1958 // Pointer modifications.
123c516a
PC
1959
1960 template<typename _Tp, typename>
1961 struct __remove_pointer_helper
1962 { typedef _Tp type; };
1963
1964 template<typename _Tp, typename _Up>
1965 struct __remove_pointer_helper<_Tp, _Up*>
1966 { typedef _Up type; };
1967
1968 /// remove_pointer
1969 template<typename _Tp>
1970 struct remove_pointer
1971 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
1972 { };
1973
1974 /// add_pointer
89898034
DK
1975 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
1976 is_void<_Tp>>::value>
1977 struct __add_pointer_helper
1978 { typedef _Tp type; };
1979
123c516a 1980 template<typename _Tp>
89898034 1981 struct __add_pointer_helper<_Tp, true>
123c516a
PC
1982 { typedef typename remove_reference<_Tp>::type* type; };
1983
89898034
DK
1984 template<typename _Tp>
1985 struct add_pointer
1986 : public __add_pointer_helper<_Tp>
1987 { };
1988
4457e88c
JW
1989#if __cplusplus > 201103L
1990 /// Alias template for remove_pointer
1991 template<typename _Tp>
1992 using remove_pointer_t = typename remove_pointer<_Tp>::type;
1993
1994 /// Alias template for add_pointer
1995 template<typename _Tp>
1996 using add_pointer_t = typename add_pointer<_Tp>::type;
1997#endif
123c516a
PC
1998
1999 template<std::size_t _Len>
2000 struct __aligned_storage_msa
2001 {
2002 union __type
2003 {
2004 unsigned char __data[_Len];
2005 struct __attribute__((__aligned__)) { } __align;
2006 };
2007 };
2008
2009 /**
2010 * @brief Alignment type.
2011 *
2012 * The value of _Align is a default-alignment which shall be the
2013 * most stringent alignment requirement for any C++ object type
2014 * whose size is no greater than _Len (3.9). The member typedef
2015 * type shall be a POD type suitable for use as uninitialized
2016 * storage for any object whose size is at most _Len and whose
2017 * alignment is a divisor of _Align.
2018 */
2019 template<std::size_t _Len, std::size_t _Align =
2020 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2021 struct aligned_storage
2022 {
2023 union type
2024 {
2025 unsigned char __data[_Len];
2026 struct __attribute__((__aligned__((_Align)))) { } __align;
2027 };
2028 };
2029
d3718027
RS
2030 template <typename... _Types>
2031 struct __strictest_alignment
2032 {
2033 static const size_t _S_alignment = 0;
2034 static const size_t _S_size = 0;
2035 };
2036
2037 template <typename _Tp, typename... _Types>
2038 struct __strictest_alignment<_Tp, _Types...>
2039 {
2040 static const size_t _S_alignment =
2041 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
2042 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
2043 static const size_t _S_size =
2044 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
2045 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
2046 };
2047
2048 /**
2049 * @brief Provide aligned storage for types.
2050 *
2051 * [meta.trans.other]
2052 *
2053 * Provides aligned storage for any of the provided types of at
2054 * least size _Len.
2055 *
2056 * @see aligned_storage
2057 */
2058 template <size_t _Len, typename... _Types>
2059 struct aligned_union
2060 {
2061 private:
2062 static_assert(sizeof...(_Types) != 0, "At least one type is required");
2063
2064 using __strictest = __strictest_alignment<_Types...>;
2065 static const size_t _S_len = _Len > __strictest::_S_size
2066 ? _Len : __strictest::_S_size;
2067 public:
2068 /// The value of the strictest alignment of _Types.
2069 static const size_t alignment_value = __strictest::_S_alignment;
2070 /// The storage.
2071 typedef typename aligned_storage<_S_len, alignment_value>::type type;
2072 };
2073
2074 template <size_t _Len, typename... _Types>
2075 const size_t aligned_union<_Len, _Types...>::alignment_value;
123c516a
PC
2076
2077 // Decay trait for arrays and functions, used for perfect forwarding
2078 // in make_pair, make_tuple, etc.
2079 template<typename _Up,
2080 bool _IsArray = is_array<_Up>::value,
2081 bool _IsFunction = is_function<_Up>::value>
2082 struct __decay_selector;
2083
2084 // NB: DR 705.
2085 template<typename _Up>
2086 struct __decay_selector<_Up, false, false>
2087 { typedef typename remove_cv<_Up>::type __type; };
2088
2089 template<typename _Up>
2090 struct __decay_selector<_Up, true, false>
2091 { typedef typename remove_extent<_Up>::type* __type; };
2092
2093 template<typename _Up>
2094 struct __decay_selector<_Up, false, true>
2095 { typedef typename add_pointer<_Up>::type __type; };
2096
2097 /// decay
2098 template<typename _Tp>
2099 class decay
2100 {
2101 typedef typename remove_reference<_Tp>::type __remove_type;
2102
2103 public:
2104 typedef typename __decay_selector<__remove_type>::__type type;
2105 };
2106
2107 template<typename _Tp>
2108 class reference_wrapper;
2109
2110 // Helper which adds a reference to a type when given a reference_wrapper
2111 template<typename _Tp>
2112 struct __strip_reference_wrapper
2113 {
2114 typedef _Tp __type;
2115 };
2116
2117 template<typename _Tp>
2118 struct __strip_reference_wrapper<reference_wrapper<_Tp> >
2119 {
2120 typedef _Tp& __type;
2121 };
2122
123c516a
PC
2123 template<typename _Tp>
2124 struct __decay_and_strip
2125 {
2126 typedef typename __strip_reference_wrapper<
2127 typename decay<_Tp>::type>::__type __type;
2128 };
2129
2130
123c516a 2131 // Primary template.
13901e4b 2132 /// Define a member typedef @c type only if a boolean constant is true.
123c516a
PC
2133 template<bool, typename _Tp = void>
2134 struct enable_if
2135 { };
2136
2137 // Partial specialization for true.
2138 template<typename _Tp>
2139 struct enable_if<true, _Tp>
2140 { typedef _Tp type; };
2141
23df8534
JW
2142 template<typename... _Cond>
2143 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
123c516a 2144
123c516a 2145 // Primary template.
13901e4b 2146 /// Define a member typedef @c type to one of two argument types.
123c516a
PC
2147 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2148 struct conditional
2149 { typedef _Iftrue type; };
2150
2151 // Partial specialization for false.
2152 template<typename _Iftrue, typename _Iffalse>
2153 struct conditional<false, _Iftrue, _Iffalse>
2154 { typedef _Iffalse type; };
2155
5b9daa7e 2156 /// common_type
cfa9a96b
CF
2157 template<typename... _Tp>
2158 struct common_type;
2159
c0ffa2ba 2160 // Sfinae-friendly common_type implementation:
b3618b71
DK
2161
2162 struct __do_common_type_impl
2163 {
2164 template<typename _Tp, typename _Up>
6c5173c0 2165 static __success_type<typename decay<decltype
fe4e4e3b 2166 (true ? std::declval<_Tp>()
6c5173c0 2167 : std::declval<_Up>())>::type> _S_test(int);
b3618b71
DK
2168
2169 template<typename, typename>
2170 static __failure_type _S_test(...);
2171 };
2172
2173 template<typename _Tp, typename _Up>
2174 struct __common_type_impl
2175 : private __do_common_type_impl
2176 {
2177 typedef decltype(_S_test<_Tp, _Up>(0)) type;
2178 };
2179
2180 struct __do_member_type_wrapper
2181 {
2182 template<typename _Tp>
2183 static __success_type<typename _Tp::type> _S_test(int);
2184
2185 template<typename>
2186 static __failure_type _S_test(...);
2187 };
2188
2189 template<typename _Tp>
2190 struct __member_type_wrapper
2191 : private __do_member_type_wrapper
2192 {
2193 typedef decltype(_S_test<_Tp>(0)) type;
2194 };
2195
2196 template<typename _CTp, typename... _Args>
2197 struct __expanded_common_type_wrapper
2198 {
2199 typedef common_type<typename _CTp::type, _Args...> type;
2200 };
2201
2202 template<typename... _Args>
2203 struct __expanded_common_type_wrapper<__failure_type, _Args...>
2204 { typedef __failure_type type; };
2205
cfa9a96b
CF
2206 template<typename _Tp>
2207 struct common_type<_Tp>
6c5173c0 2208 { typedef typename decay<_Tp>::type type; };
cfa9a96b
CF
2209
2210 template<typename _Tp, typename _Up>
7274deff 2211 struct common_type<_Tp, _Up>
b3618b71
DK
2212 : public __common_type_impl<_Tp, _Up>::type
2213 { };
cfa9a96b
CF
2214
2215 template<typename _Tp, typename _Up, typename... _Vp>
2216 struct common_type<_Tp, _Up, _Vp...>
b3618b71
DK
2217 : public __expanded_common_type_wrapper<typename __member_type_wrapper<
2218 common_type<_Tp, _Up>>::type, _Vp...>::type
2219 { };
7274deff 2220
13901e4b 2221 /// The underlying type of an enum.
a47407f6
PC
2222 template<typename _Tp>
2223 struct underlying_type
2224 {
2225 typedef __underlying_type(_Tp) type;
2226 };
123c516a 2227
7274deff
PC
2228 template<typename _Tp>
2229 struct __declval_protector
2230 {
2231 static const bool __stop = false;
2232 static typename add_rvalue_reference<_Tp>::type __delegate();
2233 };
2234
2235 template<typename _Tp>
2236 inline typename add_rvalue_reference<_Tp>::type
e4f32cb0 2237 declval() noexcept
7274deff
PC
2238 {
2239 static_assert(__declval_protector<_Tp>::__stop,
2240 "declval() must not be used!");
2241 return __declval_protector<_Tp>::__delegate();
2242 }
1041daba 2243
be7f7822
JW
2244 /// result_of
2245 template<typename _Signature>
2246 class result_of;
2247
c0ffa2ba 2248 // Sfinae-friendly result_of implementation:
83ddb39f 2249
a15f7cb8
ESR
2250#define __cpp_lib_result_of_sfinae 201210
2251
93e95400
JW
2252 struct __invoke_memfun_ref { };
2253 struct __invoke_memfun_deref { };
2254 struct __invoke_memobj_ref { };
2255 struct __invoke_memobj_deref { };
2256 struct __invoke_other { };
2257
2258 // Associate a tag type with a specialization of __success_type.
2259 template<typename _Tp, typename _Tag>
2260 struct __result_of_success : __success_type<_Tp>
2261 { using __invoke_type = _Tag; };
2262
83ddb39f
DK
2263 // [func.require] paragraph 1 bullet 1:
2264 struct __result_of_memfun_ref_impl
2265 {
2266 template<typename _Fp, typename _Tp1, typename... _Args>
93e95400 2267 static __result_of_success<decltype(
83ddb39f 2268 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...)
93e95400 2269 ), __invoke_memfun_ref> _S_test(int);
83ddb39f
DK
2270
2271 template<typename...>
2272 static __failure_type _S_test(...);
2273 };
2274
2275 template<typename _MemPtr, typename _Arg, typename... _Args>
2276 struct __result_of_memfun_ref
2277 : private __result_of_memfun_ref_impl
2278 {
2279 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2280 };
2281
2282 // [func.require] paragraph 1 bullet 2:
2283 struct __result_of_memfun_deref_impl
2284 {
2285 template<typename _Fp, typename _Tp1, typename... _Args>
93e95400 2286 static __result_of_success<decltype(
83ddb39f 2287 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...)
93e95400 2288 ), __invoke_memfun_deref> _S_test(int);
83ddb39f
DK
2289
2290 template<typename...>
2291 static __failure_type _S_test(...);
2292 };
2293
2294 template<typename _MemPtr, typename _Arg, typename... _Args>
2295 struct __result_of_memfun_deref
2296 : private __result_of_memfun_deref_impl
2297 {
2298 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type;
2299 };
2300
2301 // [func.require] paragraph 1 bullet 3:
2302 struct __result_of_memobj_ref_impl
2303 {
2304 template<typename _Fp, typename _Tp1>
93e95400 2305 static __result_of_success<decltype(
83ddb39f 2306 std::declval<_Tp1>().*std::declval<_Fp>()
93e95400 2307 ), __invoke_memobj_ref> _S_test(int);
83ddb39f
DK
2308
2309 template<typename, typename>
2310 static __failure_type _S_test(...);
2311 };
2312
2313 template<typename _MemPtr, typename _Arg>
2314 struct __result_of_memobj_ref
2315 : private __result_of_memobj_ref_impl
2316 {
2317 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2318 };
2319
2320 // [func.require] paragraph 1 bullet 4:
2321 struct __result_of_memobj_deref_impl
2322 {
2323 template<typename _Fp, typename _Tp1>
93e95400 2324 static __result_of_success<decltype(
83ddb39f 2325 (*std::declval<_Tp1>()).*std::declval<_Fp>()
93e95400 2326 ), __invoke_memobj_deref> _S_test(int);
83ddb39f
DK
2327
2328 template<typename, typename>
2329 static __failure_type _S_test(...);
2330 };
2331
be7f7822 2332 template<typename _MemPtr, typename _Arg>
83ddb39f
DK
2333 struct __result_of_memobj_deref
2334 : private __result_of_memobj_deref_impl
2335 {
2336 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type;
2337 };
2338
2339 template<typename _MemPtr, typename _Arg>
2340 struct __result_of_memobj;
be7f7822
JW
2341
2342 template<typename _Res, typename _Class, typename _Arg>
83ddb39f 2343 struct __result_of_memobj<_Res _Class::*, _Arg>
be7f7822 2344 {
83ddb39f
DK
2345 typedef typename remove_cv<typename remove_reference<
2346 _Arg>::type>::type _Argval;
2347 typedef _Res _Class::* _MemPtr;
2348 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2349 is_base_of<_Class, _Argval>>::value,
2350 __result_of_memobj_ref<_MemPtr, _Arg>,
2351 __result_of_memobj_deref<_MemPtr, _Arg>
2352 >::type::type type;
be7f7822
JW
2353 };
2354
83ddb39f
DK
2355 template<typename _MemPtr, typename _Arg, typename... _Args>
2356 struct __result_of_memfun;
be7f7822
JW
2357
2358 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
83ddb39f 2359 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...>
be7f7822 2360 {
83ddb39f
DK
2361 typedef typename remove_cv<typename remove_reference<
2362 _Arg>::type>::type _Argval;
2363 typedef _Res _Class::* _MemPtr;
2364 typedef typename conditional<__or_<is_same<_Argval, _Class>,
2365 is_base_of<_Class, _Argval>>::value,
2366 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
2367 __result_of_memfun_deref<_MemPtr, _Arg, _Args...>
2368 >::type::type type;
be7f7822
JW
2369 };
2370
93e95400
JW
2371 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2372 // 2219. INVOKE-ing a pointer to member with a reference_wrapper
2373 // as the object expression
2374 template<typename> struct reference_wrapper;
2375
2376 template<typename _Res, typename _Class, typename _Arg>
2377 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>>
2378 : __result_of_memobj<_Res _Class::*, _Arg>
2379 {
2380 typedef typename
2381 __result_of_memobj_ref<_Res _Class::*, _Arg&>::type type;
2382 };
2383
2384 template<typename _Res, typename _Class, typename _Arg>
2385 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>&>
2386 : __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>>
2387 { };
2388
2389 template<typename _Res, typename _Class, typename _Arg>
2390 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>&&>
2391 : __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>>
2392 { };
2393
2394 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2395 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>, _Args...>
2396 : __result_of_memfun<_Res _Class::*, _Arg&, _Args...>
2397 {
2398 typedef typename
2399 __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...>::type type;
2400 };
2401
2402 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2403 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>&,
2404 _Args...>
2405 : __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>, _Args...>
2406 { };
2407
2408 template<typename _Res, typename _Class, typename _Arg, typename... _Args>
2409 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>&&,
2410 _Args...>
2411 : __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>, _Args...>
2412 { };
2413
be7f7822 2414 template<bool, bool, typename _Functor, typename... _ArgTypes>
83ddb39f 2415 struct __result_of_impl
be7f7822 2416 {
83ddb39f 2417 typedef __failure_type type;
be7f7822
JW
2418 };
2419
2420 template<typename _MemPtr, typename _Arg>
83ddb39f
DK
2421 struct __result_of_impl<true, false, _MemPtr, _Arg>
2422 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg>
c4db9a77 2423 { };
be7f7822 2424
83ddb39f
DK
2425 template<typename _MemPtr, typename _Arg, typename... _Args>
2426 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...>
2427 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...>
c4db9a77 2428 { };
be7f7822 2429
83ddb39f
DK
2430 // [func.require] paragraph 1 bullet 5:
2431 struct __result_of_other_impl
2432 {
2433 template<typename _Fn, typename... _Args>
93e95400 2434 static __result_of_success<decltype(
83ddb39f 2435 std::declval<_Fn>()(std::declval<_Args>()...)
93e95400 2436 ), __invoke_other> _S_test(int);
83ddb39f
DK
2437
2438 template<typename...>
2439 static __failure_type _S_test(...);
2440 };
2441
be7f7822 2442 template<typename _Functor, typename... _ArgTypes>
83ddb39f
DK
2443 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
2444 : private __result_of_other_impl
be7f7822 2445 {
83ddb39f 2446 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
be7f7822
JW
2447 };
2448
83ddb39f
DK
2449 template<typename _Functor, typename... _ArgTypes>
2450 struct result_of<_Functor(_ArgTypes...)>
2451 : public __result_of_impl<
2452 is_member_object_pointer<
2453 typename remove_reference<_Functor>::type
2454 >::value,
2455 is_member_function_pointer<
2456 typename remove_reference<_Functor>::type
2457 >::value,
2458 _Functor, _ArgTypes...
2459 >::type
2460 { };
c0ffa2ba 2461
4457e88c
JW
2462#if __cplusplus > 201103L
2463 /// Alias template for aligned_storage
2464 template<size_t _Len, size_t _Align =
2465 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
2466 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
2467
d3718027
RS
2468 template <size_t _Len, typename... _Types>
2469 using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
2470
4457e88c
JW
2471 /// Alias template for decay
2472 template<typename _Tp>
2473 using decay_t = typename decay<_Tp>::type;
2474
2475 /// Alias template for enable_if
2476 template<bool _Cond, typename _Tp = void>
2477 using enable_if_t = typename enable_if<_Cond, _Tp>::type;
2478
2479 /// Alias template for conditional
2480 template<bool _Cond, typename _Iftrue, typename _Iffalse>
2481 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type;
2482
2483 /// Alias template for common_type
2484 template<typename... _Tp>
2485 using common_type_t = typename common_type<_Tp...>::type;
2486
2487 /// Alias template for underlying_type
2488 template<typename _Tp>
2489 using underlying_type_t = typename underlying_type<_Tp>::type;
2490
2491 /// Alias template for result_of
2492 template<typename _Tp>
2493 using result_of_t = typename result_of<_Tp>::type;
2494#endif
2495
847e9cf8
JW
2496 template<typename...> using __void_t = void;
2497
bd1eb5e0
JW
2498#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
2499#define __cpp_lib_void_t 201411
2500 /// A metafunction that always yields void, used for detecting valid types.
2501 template<typename...> using void_t = void;
2502#endif
2503
6af6bef4
JW
2504 /// Implementation of the detection idiom (negative case).
2505 template<typename _Default, typename _AlwaysVoid,
2506 template<typename...> class _Op, typename... _Args>
2507 struct __detector
2508 {
2509 using value_t = false_type;
2510 using type = _Default;
2511 };
2512
2513 /// Implementation of the detection idiom (positive case).
2514 template<typename _Default, template<typename...> class _Op,
2515 typename... _Args>
2516 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...>
2517 {
2518 using value_t = true_type;
2519 using type = _Op<_Args...>;
2520 };
2521
2522 // Detect whether _Op<_Args...> is a valid type, use _Default if not.
2523 template<typename _Default, template<typename...> class _Op,
2524 typename... _Args>
2525 using __detected_or = __detector<_Default, void, _Op, _Args...>;
2526
2527 // _Op<_Args...> if that is a valid type, otherwise _Default.
2528 template<typename _Default, template<typename...> class _Op,
2529 typename... _Args>
2530 using __detected_or_t
2531 = typename __detected_or<_Default, _Op, _Args...>::type;
2532
2533 // _Op<_Args...> if that is a valid type, otherwise _Default<_Args...>.
2534 template<template<typename...> class _Default,
2535 template<typename...> class _Op, typename... _Args>
2536 using __detected_or_t_ =
2537 __detected_or_t<_Default<_Args...>, _Op, _Args...>;
2538
c0ffa2ba 2539 /// @} group metaprogramming
847e9cf8 2540
033b71ce
PC
2541 /**
2542 * Use SFINAE to determine if the type _Tp has a publicly-accessible
2543 * member type _NTYPE.
2544 */
82b12c4b 2545#define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
847e9cf8 2546 template<typename _Tp, typename = __void_t<>> \
82b12c4b 2547 struct __has_##_NTYPE \
847e9cf8
JW
2548 : false_type \
2549 { }; \
2550 template<typename _Tp> \
2551 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \
2552 : true_type \
033b71ce
PC
2553 { };
2554
ddb63209
VV
2555
2556 namespace __is_swappable_impl {
2557 template <typename _Tp, typename=void>
2558 struct __is_swappable : public false_type
2559 { };
2560 }
2561
2562 template<typename _Tp>
2563 inline
2564 typename enable_if<__and_<is_move_constructible<_Tp>,
2565 is_move_assignable<_Tp>>::value>::type
2566 swap(_Tp&, _Tp&)
2567 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
2568 is_nothrow_move_assignable<_Tp>>::value);
2569
2570 template<typename _Tp, size_t _Nm>
2571 inline
2572 typename enable_if<__is_swappable_impl::__is_swappable<_Tp>::value>::type
2573 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
2574 noexcept(noexcept(swap(*__a, *__b)));
2575
2576 namespace __is_swappable_impl {
2577 using std::swap;
2578
2579 template <typename _Tp>
2580 struct __is_swappable<_Tp, __void_t<decltype(swap(declval<_Tp&>(),
2581 declval<_Tp&>()))>>
2582 : public true_type
2583 { };
2584 }
2585
2586 template <bool, typename _Tp>
2587 struct __is_nothrow_swappable_impl
2588 : public __bool_constant<noexcept(swap(declval<_Tp&>(), declval<_Tp&>()))>
2589 { };
2590
2591 template <typename _Tp>
2592 struct __is_nothrow_swappable_impl<false, _Tp> : public false_type
2593 { };
2594
2595 template <typename _Tp>
2596 struct __is_nothrow_swappable
2597 : public __is_nothrow_swappable_impl<
2598 __is_swappable_impl::__is_swappable<_Tp>::value, _Tp>
2599 { };
2600
12ffa228 2601_GLIBCXX_END_NAMESPACE_VERSION
c0ffa2ba 2602} // namespace std
7b50cdef 2603
734f5023 2604#endif // C++11
57317d2a 2605
7274deff 2606#endif // _GLIBCXX_TYPE_TRAITS