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