diff --git a/include/rvarago/optional_extras/algorithm.hpp b/include/rvarago/optional_extras/algorithm.hpp index 8098abd..71cc8a8 100644 --- a/include/rvarago/optional_extras/algorithm.hpp +++ b/include/rvarago/optional_extras/algorithm.hpp @@ -105,15 +105,14 @@ append(std::optional opt_lhs, std::optional opt_rhs, template NullaryFunction, std::regular_invocable UnaryFunction> - requires std::same_as, - std::invoke_result_t> constexpr auto fold( std::optional opt, NullaryFunction &&when_empty, UnaryFunction && when_engaged) noexcept(std::is_nothrow_move_constructible_v && std::is_nothrow_invocable_v && std::is_nothrow_invocable_v) - -> std::invoke_result_t { + -> std::common_type_t, + std::invoke_result_t> { if (opt) { return std::invoke(std::forward(when_engaged), std::move(*opt)); diff --git a/test/algorithm_test.cpp b/test/algorithm_test.cpp index 7ab2dbc..5f1d3d7 100644 --- a/test/algorithm_test.cpp +++ b/test/algorithm_test.cpp @@ -92,4 +92,8 @@ TEST_CASE("When engaged transform it otherwise invoke default", "[fold]") { STATIC_REQUIRE(optx::fold(none, zero, bail) == 0); STATIC_REQUIRE(optx::fold(optional{1}, bail, inc) == 2); + + // implicit return-type conversion. + STATIC_REQUIRE( + optx::fold(none, [] { return true; }, bail) == 1); }