diff --git a/tests/issues.cpp b/tests/issues.cpp index 429e2f5..1cd8550 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -80,3 +80,14 @@ TEST_CASE("Issue 33", "[issues.33]") { res = res.map_error([](int i) { return 42; }); REQUIRE(res.error() == 42); } + + +tl::expected voidWork() { return {}; } +tl::expected work2() { return 42; } +void errorhandling(std::string){} + +TEST_CASE("Issue 34", "[issues.34]") { + tl::expected result = voidWork () + .and_then (work2); + result.map_error ([&] (std::string result) {errorhandling (result);}); +} diff --git a/tl/expected.hpp b/tl/expected.hpp index 71329f2..f19e8da 100644 --- a/tl/expected.hpp +++ b/tl/expected.hpp @@ -1893,9 +1893,9 @@ template using ret_t = expected>; #ifdef TL_EXPECTED_CXX14 template >::value> * = nullptr, class Ret = decltype(detail::invoke(std::declval(), - *std::declval())), - detail::enable_if_t>::value> * = nullptr> + *std::declval()))> constexpr auto and_then_impl(Exp &&exp, F &&f) { static_assert(detail::is_expected::value, "F must return an expected"); @@ -1905,9 +1905,8 @@ constexpr auto and_then_impl(Exp &&exp, F &&f) { } template (), - *std::declval())), - detail::enable_if_t>::value> * = nullptr> + detail::enable_if_t>::value> * = nullptr, + class Ret = decltype(detail::invoke(std::declval()))> constexpr auto and_then_impl(Exp &&exp, F &&f) { static_assert(detail::is_expected::value, "F must return an expected"); @@ -1929,8 +1928,7 @@ auto and_then_impl(Exp &&exp, F &&f) -> Ret { } template (), - *std::declval())), + class Ret = decltype(detail::invoke(std::declval())), detail::enable_if_t>::value> * = nullptr> constexpr auto and_then_impl(Exp &&exp, F &&f) -> Ret { static_assert(detail::is_expected::value, "F must return an expected");