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