Skip to content

Commit 58a2727

Browse files
committed
Add inspection of optional value
1 parent 43d1e72 commit 58a2727

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

811+
template<auto value, typename T>
812+
constexpr auto is_impl( std::optional<T> const& x ) -> bool {
813+
if ( x.has_value() )
814+
return cpp2::is<value>(x.value());
815+
else
816+
return false;
817+
}
818+
819+
template<auto value, typename T>
820+
constexpr auto is( std::optional<T> const& x ) -> bool
821+
{ return cpp2::is_impl<value>(x); }
822+
823+
template<cstring_wrapper value, typename T>
824+
constexpr auto is( std::optional<T> const& x ) -> bool
825+
{ return cpp2::is_impl<value>(x); }
826+
827+
template<double_wrapper value, typename T>
828+
constexpr auto is( std::optional<T> const& x ) -> bool
829+
{ return cpp2::is_impl<value>(x); }
830+
811831
template<typename T, typename X>
812832
requires std::is_same_v<X,std::optional<T>>
813833
constexpr auto as( X const& x ) -> auto&&

0 commit comments

Comments
 (0)