Skip to content

Commit

Permalink
Fix rvalue result<void> cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Oct 29, 2023
1 parent 92c24da commit 7ffd63d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/boost/system/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,23 @@ template<class E, class F,
}
}

template<class E, class F,
class U = decltype( std::declval<F>()() ),
class En1 = typename std::enable_if<detail::is_result<U>::value>::type,
class En2 = typename std::enable_if<std::is_void<typename U::value_type>::value>::type
>
U operator|( result<void, E>&& r, F&& f )
{
if( r )
{
return {};
}
else
{
return std::forward<F>( f )();
}
}

} // namespace system
} // namespace boost

Expand Down
20 changes: 20 additions & 0 deletions test/result_or_fn0r.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,25 @@ int main()
BOOST_TEST( r2.has_error() );
}

{
result<void, E> r2 = result<void>() | fv;
BOOST_TEST( r2.has_value() );
}

{
result<void, E> r2 = result<void>() | fv2;
BOOST_TEST( r2.has_value() );
}

{
result<void, E> r2 = result<void>( in_place_error ) | fv;
BOOST_TEST( r2.has_value() );
}

{
result<void, E> r2 = result<void>( in_place_error ) | fv2;
BOOST_TEST( r2.has_error() );
}

return boost::report_errors();
}

0 comments on commit 7ffd63d

Please sign in to comment.