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