Move error inside and_then

Fixes #49
This commit is contained in:
Simon Brand
2019-02-25 11:51:54 +00:00
parent 2e007e9f57
commit edfdf3e689
2 changed files with 24 additions and 5 deletions

View File

@@ -105,4 +105,23 @@ TEST_CASE("Issue 42", "[issues.42]") {
TEST_CASE("Issue 43", "[issues.43]") {
auto result = tl::expected<void, std::string>{};
result = tl::make_unexpected(std::string{ "foo" });
}
}
#include <memory>
using MaybeDataPtr = tl::expected<int, std::unique_ptr<int>>;
MaybeDataPtr test(int i) noexcept
{
return std::move(i);
}
MaybeDataPtr test2(int i) noexcept
{
return std::move(i);
}
TEST_CASE("Issue 49", "[issues.49]") {
auto m = test(10)
.and_then(test2);
}

View File

@@ -1910,7 +1910,7 @@ constexpr auto and_then_impl(Exp &&exp, F &&f) {
return exp.has_value()
? detail::invoke(std::forward<F>(f), *std::forward<Exp>(exp))
: Ret(unexpect, exp.error());
: Ret(unexpect, std::forward<Exp>(exp).error());
}
template <class Exp, class F,
@@ -1920,7 +1920,7 @@ constexpr auto and_then_impl(Exp &&exp, F &&f) {
static_assert(detail::is_expected<Ret>::value, "F must return an expected");
return exp.has_value() ? detail::invoke(std::forward<F>(f))
: Ret(unexpect, exp.error());
: Ret(unexpect, std::forward<Exp>(exp).error());
}
#else
template <class> struct TC;
@@ -1933,7 +1933,7 @@ auto and_then_impl(Exp &&exp, F &&f) -> Ret {
return exp.has_value()
? detail::invoke(std::forward<F>(f), *std::forward<Exp>(exp))
: Ret(unexpect, exp.error());
: Ret(unexpect, std::forward<Exp>(exp).error());
}
template <class Exp, class F,
@@ -1943,7 +1943,7 @@ constexpr auto and_then_impl(Exp &&exp, F &&f) -> Ret {
static_assert(detail::is_expected<Ret>::value, "F must return an expected");
return exp.has_value() ? detail::invoke(std::forward<F>(f))
: Ret(unexpect, exp.error());
: Ret(unexpect, std::forward<Exp>(exp).error());
}
#endif