mirror of
https://github.com/TartanLlama/expected.git
synced 2025-08-03 10:54:31 +02:00
Fix #1
This commit is contained in:
@@ -12,6 +12,7 @@ set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/extensions.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/assignment.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/emplace.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/issues.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/bases.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/observers.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp)
|
||||
|
26
tests/issues.cpp
Normal file
26
tests/issues.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "catch.hpp"
|
||||
#include "expected.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
tl::expected<int, string> getInt3(int val)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
tl::expected<int, string> getInt2(int val)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
tl::expected<int, string> getInt1()
|
||||
{
|
||||
return getInt2(5).and_then(getInt3);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Issue 1", "[issues.1]") {
|
||||
getInt1();
|
||||
}
|
@@ -999,8 +999,9 @@ public:
|
||||
/// is returned.
|
||||
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) &;
|
||||
template <class F>
|
||||
TL_EXPECTED_11_CONSTEXPR detail::invoke_result_t<F, T &> and_then(F &&f) & {
|
||||
using result = detail::invoke_result_t<F, T &>;
|
||||
TL_EXPECTED_11_CONSTEXPR auto and_then(F &&f) &
|
||||
-> decltype(detail::invoke(std::forward<F>(f), std::declval<T&>())) {
|
||||
using result = decltype(detail::invoke(std::forward<F>(f), **this));
|
||||
static_assert(detail::is_expected<result>::value,
|
||||
"F must return an expected");
|
||||
|
||||
@@ -1011,20 +1012,22 @@ public:
|
||||
/// \group and_then
|
||||
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) &&;
|
||||
template <class F>
|
||||
TL_EXPECTED_11_CONSTEXPR detail::invoke_result_t<F, T &&> and_then(F &&f) && {
|
||||
using result = detail::invoke_result_t<F, T &&>;
|
||||
TL_EXPECTED_11_CONSTEXPR auto and_then(F &&f) &&
|
||||
-> decltype(detail::invoke(std::forward<F>(f), std::declval<T&&>())) {
|
||||
using result = decltype(detail::invoke(std::forward<F>(f), std::move(**this)));
|
||||
static_assert(detail::is_expected<result>::value,
|
||||
"F must return an expected");
|
||||
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), **this)
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
|
||||
: result(unexpect, std::move(this->error()));
|
||||
}
|
||||
|
||||
/// \group and_then
|
||||
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) const &;
|
||||
template <class F>
|
||||
constexpr detail::invoke_result_t<F, const T &> and_then(F &&f) const & {
|
||||
using result = detail::invoke_result_t<F, const T &>;
|
||||
constexpr auto and_then(F &&f) const &
|
||||
-> decltype(detail::invoke(std::forward<F>(f), std::declval<const T&>())) {
|
||||
using result = decltype(detail::invoke(std::forward<F>(f), **this));
|
||||
static_assert(detail::is_expected<result>::value,
|
||||
"F must return an expected");
|
||||
|
||||
@@ -1036,8 +1039,9 @@ public:
|
||||
/// \group and_then
|
||||
/// \synopsis template <class F>\nconstexpr auto and_then(F &&f) const &&;
|
||||
template <class F>
|
||||
constexpr detail::invoke_result_t<F, const T &&> and_then(F &&f) const && {
|
||||
using result = detail::invoke_result_t<F, const T &&>;
|
||||
constexpr auto and_then(F &&f) const &&
|
||||
-> decltype(detail::invoke(std::forward<F>(f), std::declval<const T&&>())) {
|
||||
using result = decltype(detail::invoke(std::forward<F>(f), std::move(**this)));
|
||||
static_assert(detail::is_expected<result>::value,
|
||||
"F must return an expected");
|
||||
|
||||
|
Reference in New Issue
Block a user