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