forked from TartanLlama/expected
@@ -105,4 +105,23 @@ TEST_CASE("Issue 42", "[issues.42]") {
|
|||||||
TEST_CASE("Issue 43", "[issues.43]") {
|
TEST_CASE("Issue 43", "[issues.43]") {
|
||||||
auto result = tl::expected<void, std::string>{};
|
auto result = tl::expected<void, std::string>{};
|
||||||
result = tl::make_unexpected(std::string{ "foo" });
|
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);
|
||||||
|
}
|
||||||
|
@@ -1910,7 +1910,7 @@ constexpr auto and_then_impl(Exp &&exp, F &&f) {
|
|||||||
|
|
||||||
return exp.has_value()
|
return exp.has_value()
|
||||||
? detail::invoke(std::forward<F>(f), *std::forward<Exp>(exp))
|
? 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,
|
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");
|
static_assert(detail::is_expected<Ret>::value, "F must return an expected");
|
||||||
|
|
||||||
return exp.has_value() ? detail::invoke(std::forward<F>(f))
|
return exp.has_value() ? detail::invoke(std::forward<F>(f))
|
||||||
: Ret(unexpect, exp.error());
|
: Ret(unexpect, std::forward<Exp>(exp).error());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
template <class> struct TC;
|
template <class> struct TC;
|
||||||
@@ -1933,7 +1933,7 @@ auto and_then_impl(Exp &&exp, F &&f) -> Ret {
|
|||||||
|
|
||||||
return exp.has_value()
|
return exp.has_value()
|
||||||
? detail::invoke(std::forward<F>(f), *std::forward<Exp>(exp))
|
? 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,
|
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");
|
static_assert(detail::is_expected<Ret>::value, "F must return an expected");
|
||||||
|
|
||||||
return exp.has_value() ? detail::invoke(std::forward<F>(f))
|
return exp.has_value() ? detail::invoke(std::forward<F>(f))
|
||||||
: Ret(unexpect, exp.error());
|
: Ret(unexpect, std::forward<Exp>(exp).error());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user