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