diff --git a/include/boost/variant2/expected.hpp b/include/boost/variant2/expected.hpp index fb90ea1..452ae35 100644 --- a/include/boost/variant2/expected.hpp +++ b/include/boost/variant2/expected.hpp @@ -95,7 +95,7 @@ public: } }; -// expected +// throw_on_unexpected template void throw_on_unexpected( E const& e ) { @@ -119,6 +119,13 @@ void throw_on_unexpected( std::exception_ptr const & e ) } } +// expected + +template class expected; + +template struct is_expected: std::false_type {}; +template struct is_expected>: std::true_type {}; + template class expected { private: @@ -387,6 +394,28 @@ public: }); } + + // then + +private: + + template using then_result_ = decltype( std::declval()( std::declval() ) ); + + template> using then_result = mp_if, R, expected>; + +public: + + template then_result then( F && f ) const + { + if( has_value() ) + { + return std::forward(f)( **this ); + } + else + { + return unexpected(); + } + } }; template inline constexpr bool operator==( expected const & x1, expected const & x2 )