Skip to content

Commit bd7ddb5

Browse files
committed
is(): refactor is() for std::any to new design
1 parent 4942083 commit bd7ddb5

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

include/cpp2util.h

+10-12
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,16 @@ auto is( X const& x ) -> bool {
16591659
{
16601660
return x == X();
16611661
}
1662+
else if constexpr (
1663+
std::is_same_v<X, std::any>
1664+
)
1665+
{
1666+
if constexpr (std::is_same_v<C, empty>) {
1667+
return !x.has_value();
1668+
} else {
1669+
return x.type() == Typeid<C>();
1670+
}
1671+
}
16621672
else {
16631673
return false;
16641674
}
@@ -2088,18 +2098,6 @@ auto as( std::variant<Ts...> const& x ) -> decltype(auto) {
20882098
// std::any is and as
20892099
//
20902100

2091-
// is Type
2092-
//
2093-
template<typename T, typename X>
2094-
requires (std::is_same_v<X,std::any> && !std::is_same_v<T,std::any> && !std::is_same_v<T,empty>)
2095-
constexpr auto is( X const& x ) -> bool
2096-
{ return x.type() == Typeid<T>(); }
2097-
2098-
template<typename T, typename X>
2099-
requires (std::is_same_v<X,std::any> && std::is_same_v<T,empty>)
2100-
constexpr auto is( X const& x ) -> bool
2101-
{ return !x.has_value(); }
2102-
21032101

21042102
// is Value
21052103
//

0 commit comments

Comments
 (0)