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