Skip to content

Commit dd7d4a3

Browse files
committed
Add inspection of optional value
1 parent 466d5db commit dd7d4a3

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
@@ -804,6 +804,26 @@ template<typename T, typename U>
804804
constexpr auto is( std::optional<U> const& x ) -> bool
805805
{ return !x.has_value(); }
806806

807+
template<auto value, typename T>
808+
constexpr auto is_impl( std::optional<T> const& x ) -> bool {
809+
if ( x.has_value() )
810+
return cpp2::is<value>(x.value());
811+
else
812+
return false;
813+
}
814+
815+
template<auto value, typename T>
816+
constexpr auto is( std::optional<T> const& x ) -> bool
817+
{ return cpp2::is_impl<value>(x); }
818+
819+
template<cstring_wrapper value, typename T>
820+
constexpr auto is( std::optional<T> const& x ) -> bool
821+
{ return cpp2::is_impl<value>(x); }
822+
823+
template<double_wrapper value, typename T>
824+
constexpr auto is( std::optional<T> const& x ) -> bool
825+
{ return cpp2::is_impl<value>(x); }
826+
807827
template<typename T, typename X>
808828
requires std::is_same_v<X,std::optional<T>>
809829
constexpr auto as( X const& x ) -> auto&&

0 commit comments

Comments
 (0)