Skip to content

Commit 95359ca

Browse files
committed
Add inspection of optional value
1 parent b459f09 commit 95359ca

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

846+
template<auto value, typename T>
847+
constexpr auto is_impl( std::optional<T> const& x ) -> bool {
848+
if ( x.has_value() )
849+
return cpp2::is<value>(x.value());
850+
else
851+
return false;
852+
}
853+
854+
template<auto value, typename T>
855+
constexpr auto is( std::optional<T> const& x ) -> bool
856+
{ return cpp2::is_impl<value>(x); }
857+
858+
template<cstring_wrapper value, typename T>
859+
constexpr auto is( std::optional<T> const& x ) -> bool
860+
{ return cpp2::is_impl<value>(x); }
861+
862+
template<double_wrapper value, typename T>
863+
constexpr auto is( std::optional<T> const& x ) -> bool
864+
{ return cpp2::is_impl<value>(x); }
865+
846866
template<typename T, typename X>
847867
requires std::is_same_v<X,std::optional<T>>
848868
constexpr auto as( X const& x ) -> auto&&

0 commit comments

Comments
 (0)