diff --git a/include/boost/system/result.hpp b/include/boost/system/result.hpp index 762afa37..f3d841f2 100644 --- a/include/boost/system/result.hpp +++ b/include/boost/system/result.hpp @@ -1103,6 +1103,22 @@ result operator&( result&& r, F&& f ) } } +template()() ), + class En = typename std::enable_if::value>::type +> +result operator&( result const& r, F&& f ) +{ + if( r.has_error() ) + { + return r.error(); + } + else + { + return std::forward( f )(); + } +} + // result & unary-returning-result template r; + result r2 = r & k; + + BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 7 ); + } + + { + result const r; + result r2 = r & k; + + BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 7 ); + } + + { + result r2 = result() & k; + + BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( *r2, 7 ); + } + + { + result r( in_place_error ); + result r2 = r & k; + + BOOST_TEST( r2.has_error() ); + } + + { + result const r( in_place_error ); + result r2 = r & k; + + BOOST_TEST( r2.has_error() ); + } + + { + result r2 = result( in_place_error ) & k; + + BOOST_TEST( r2.has_error() ); + } + return boost::report_errors(); }