| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -366,6 +366,17 @@ auto is( X const* x ) -> bool { | |||
| 366 | 366 | //------------------------------------------------------------------------------------------------------------- | |
| 367 | 367 | // Built-in as (partial) | |
| 368 | 368 | // | |
| 369 | + template< typename C > | ||
| 370 | + auto as(...) -> auto { | ||
| 371 | + return nonesuch; | ||
| 372 | + } | ||
| 373 | + | ||
| 374 | + template< typename C, typename X > | ||
| 375 | + requires std::is_same_v<C, X> | ||
| 376 | + auto as( X const& x ) -> auto&& { | ||
| 377 | + return x; | ||
| 378 | + } | ||
| 379 | + | ||
| 369 | 380 | template< typename C, typename X > | |
| 370 | 381 | requires std::is_base_of_v<C, X> | |
| 371 | 382 | auto as( X&& x ) -> C&& { | |
@@ -448,29 +459,28 @@ auto as( std::variant<Ts...> const& x ) { | |||
| 448 | 459 | //------------------------------------------------------------------------------------------------------------- | |
| 449 | 460 | // std::any is and as | |
| 450 | 461 | // | |
| 451 | - template<typename T> | ||
| 452 | - constexpr auto is( std::any const& x ) -> bool | ||
| 462 | + template<typename T, typename X> | ||
| 463 | + requires std::is_same_v<X,std::any> | ||
| 464 | + constexpr auto is( X const& x ) -> bool | ||
| 453 | 465 | { return x.type() == typeid(T); } | |
| 454 | 466 | ||
| 455 | - template<typename T> requires (!std::is_reference_v<T>) | ||
| 456 | - constexpr auto as( std::any const& x ) -> T | ||
| 467 | + template<typename T, typename X> | ||
| 468 | + requires (!std::is_reference_v<T> && std::is_same_v<X,std::any>) | ||
| 469 | + constexpr auto as( X const& x ) -> T | ||
| 457 | 470 | { return std::any_cast<T>( x ); } | |
| 458 | 471 | ||
| 459 | 472 | ||
| 460 | 473 | //------------------------------------------------------------------------------------------------------------- | |
| 461 | 474 | // std::optional is and as | |
| 462 | 475 | // | |
| 463 | - template<typename T> | ||
| 464 | - constexpr auto is( std::optional<T> const& x ) -> bool | ||
| 476 | + template<typename T, typename X> | ||
| 477 | + requires std::is_same_v<X,std::optional<T>> | ||
| 478 | + constexpr auto is( X const& x ) -> bool | ||
| 465 | 479 | { return x.has_value(); } | |
| 466 | 480 | ||
| 467 | - template<typename T, typename U> | ||
| 468 | - requires (!std::is_same_v<T,U>) | ||
| 469 | - constexpr auto is( std::optional<U> const& x ) -> bool | ||
| 470 | - { return false; } | ||
| 471 | - | ||
| 472 | - template<typename T> | ||
| 473 | - constexpr auto as( std::optional<T> const& x ) -> auto&& | ||
| 481 | + template<typename T, typename X> | ||
| 482 | + requires std::is_same_v<X,std::optional<T>> | ||
| 483 | + constexpr auto as( X const& x ) -> auto&& | ||
| 474 | 484 | { return x.value(); } | |
| 475 | 485 | ||
| 476 | 486 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments