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