@@ -2083,28 +2083,22 @@ auto as(X&& x CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT_AS) -> decltype(auto)
2083
2083
2084
2084
// is Type
2085
2085
//
2086
- template <typename T, typename X>
2087
- requires (std::is_same_v<X,std::any> && !std::is_same_v<T,std::any> && !std::is_same_v<T,empty>)
2088
- constexpr auto is ( X const & x ) -> bool
2089
- { return x.type () == Typeid<T>(); }
2090
-
2091
- template <typename T, typename X>
2092
- requires (std::is_same_v<X,std::any> && std::is_same_v<T,empty>)
2093
- constexpr auto is ( X const & x ) -> bool
2094
- { return !x.has_value (); }
2095
-
2086
+ template <typename T, std::same_as<std::any> X>
2087
+ constexpr auto is ( X const & x ) -> bool{
2088
+ if (!x.has_value ()) {
2089
+ return std::is_same_v<T,empty>;
2090
+ }
2091
+ return x.type () == Typeid<T>();
2092
+ }
2096
2093
2097
2094
// is Value
2098
2095
//
2099
2096
inline constexpr auto is ( std::any const & x, auto && value ) -> bool
2100
2097
{
2101
2098
// Predicate case
2102
- if constexpr (requires { bool { value (x) }; } ) {
2099
+ if constexpr (valid_predicate< decltype ( value), decltype (x)> ) {
2103
2100
return value (x);
2104
2101
}
2105
- else if constexpr (std::is_function_v<decltype (value)> || requires { &value.operator (); }) {
2106
- return false ;
2107
- }
2108
2102
2109
2103
// Value case
2110
2104
else if constexpr (requires { bool { *std::any_cast<CPP2_TYPEOF (value)>(&x) == value }; }) {
@@ -2118,10 +2112,12 @@ inline constexpr auto is( std::any const& x, auto&& value ) -> bool
2118
2112
2119
2113
// as
2120
2114
//
2121
- template <typename T, typename X>
2122
- requires (!std::is_reference_v<T> && std::is_same_v<X,std::any> && !std::is_same_v<T,std::any>)
2123
- constexpr auto as ( X const & x ) -> T
2124
- { return std::any_cast<T>( x ); }
2115
+ template <typename T, same_type_as<std::any> X>
2116
+ constexpr auto as ( X && x ) -> decltype(auto ) {
2117
+ constness_like_t <T, X>* ptr = std::any_cast<T>( &x );
2118
+ if (!ptr) { Throw ( std::bad_any_cast (), " 'as' cast failed for 'std::any'" ); }
2119
+ return cpp2::forward_like<X>(*ptr);
2120
+ }
2125
2121
2126
2122
2127
2123
// -------------------------------------------------------------------------------------------------------------
0 commit comments