Skip to content

Commit a9f26b4

Browse files
committed
Add inspection of optional value
1 parent 7c55623 commit a9f26b4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

include/cpp2util.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,26 @@ template<typename T, typename U>
871871
constexpr auto is( std::optional<U> const& x ) -> bool
872872
{ return !x.has_value(); }
873873

874+
template<auto value, typename T>
875+
constexpr auto is_impl( std::optional<T> const& x ) -> bool {
876+
if ( x.has_value() )
877+
return cpp2::is<value>(x.value());
878+
else
879+
return false;
880+
}
881+
882+
template<auto value, typename T>
883+
constexpr auto is( std::optional<T> const& x ) -> bool
884+
{ return cpp2::is_impl<value>(x); }
885+
886+
template<cstring_wrapper value, typename T>
887+
constexpr auto is( std::optional<T> const& x ) -> bool
888+
{ return cpp2::is_impl<value>(x); }
889+
890+
template<double_wrapper value, typename T>
891+
constexpr auto is( std::optional<T> const& x ) -> bool
892+
{ return cpp2::is_impl<value>(x); }
893+
874894
template<typename T, typename X>
875895
requires std::is_same_v<X,std::optional<T>>
876896
constexpr auto as( X const& x ) -> auto&&

0 commit comments

Comments
 (0)