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