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