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