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