Skip to content

Commit b0915bb

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

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

include/cpp2util.h

+10-13
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+
specialization_of_template<X, std::optional>
1664+
)
1665+
{
1666+
if (x.has_value()) {
1667+
return is<C>(x.value());
1668+
} else {
1669+
return std::is_same_v<C, empty>;
1670+
}
1671+
}
16621672
else {
16631673
return false;
16641674
}
@@ -2135,19 +2145,6 @@ constexpr auto as( X const& x ) -> T
21352145
// std::optional is and as
21362146
//
21372147

2138-
// is Type
2139-
//
2140-
template<typename T, typename X>
2141-
requires std::is_same_v<X,std::optional<T>>
2142-
constexpr auto is( X const& x ) -> bool
2143-
{ return x.has_value(); }
2144-
2145-
template<typename T, typename U>
2146-
requires std::is_same_v<T,empty>
2147-
constexpr auto is( std::optional<U> const& x ) -> bool
2148-
{ return !x.has_value(); }
2149-
2150-
21512148
// is Value
21522149
//
21532150
template<typename T>

0 commit comments

Comments
 (0)