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