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