forked from TartanLlama/expected
Fix #17
This commit is contained in:
@@ -5,22 +5,20 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
tl::expected<int, string> getInt3(int val)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
tl::expected<int, string> getInt3(int val) { return val; }
|
||||
|
||||
tl::expected<int, string> getInt2(int val)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
tl::expected<int, string> getInt2(int val) { return val; }
|
||||
|
||||
tl::expected<int, string> getInt1()
|
||||
{
|
||||
return getInt2(5).and_then(getInt3);
|
||||
}
|
||||
tl::expected<int, string> getInt1() { return getInt2(5).and_then(getInt3); }
|
||||
|
||||
TEST_CASE("Issue 1", "[issues.1]") { getInt1(); }
|
||||
|
||||
TEST_CASE("Issue 1", "[issues.1]") {
|
||||
getInt1();
|
||||
tl::expected<int, int> operation1() { return 42; }
|
||||
|
||||
tl::expected<std::string, int> operation2(int const val) { return "Bananas"; }
|
||||
|
||||
TEST_CASE("Issue 17", "[issues.17]") {
|
||||
auto const intermediate_result = operation1();
|
||||
|
||||
intermediate_result.and_then(operation2);
|
||||
}
|
||||
|
@@ -293,7 +293,7 @@ template <class T, class E, bool = std::is_trivially_destructible<T>::value,
|
||||
bool = std::is_trivially_destructible<E>::value>
|
||||
struct expected_storage_base {
|
||||
constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {}
|
||||
constexpr expected_storage_base(no_init_t) : m_has_val(false) {}
|
||||
constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {}
|
||||
|
||||
template <class... Args,
|
||||
detail::enable_if_t<std::is_constructible<T, Args &&...>::value> * =
|
||||
@@ -329,6 +329,7 @@ struct expected_storage_base {
|
||||
}
|
||||
}
|
||||
union {
|
||||
char m_no_init;
|
||||
T m_val;
|
||||
unexpected<E> m_unexpect;
|
||||
};
|
||||
@@ -339,7 +340,7 @@ struct expected_storage_base {
|
||||
// so the destructor of the `expected` can be trivial.
|
||||
template <class T, class E> struct expected_storage_base<T, E, true, true> {
|
||||
constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {}
|
||||
constexpr expected_storage_base(no_init_t) : m_has_val(false) {}
|
||||
constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {}
|
||||
|
||||
template <class... Args,
|
||||
detail::enable_if_t<std::is_constructible<T, Args &&...>::value> * =
|
||||
@@ -369,6 +370,7 @@ template <class T, class E> struct expected_storage_base<T, E, true, true> {
|
||||
|
||||
~expected_storage_base() = default;
|
||||
union {
|
||||
char m_no_init;
|
||||
T m_val;
|
||||
unexpected<E> m_unexpect;
|
||||
};
|
||||
@@ -379,7 +381,7 @@ template <class T, class E> struct expected_storage_base<T, E, true, true> {
|
||||
template <class T, class E> struct expected_storage_base<T, E, true, false> {
|
||||
constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {}
|
||||
TL_EXPECTED_MSVC2015_CONSTEXPR expected_storage_base(no_init_t)
|
||||
: m_has_val(false) {}
|
||||
: m_no_init(), m_has_val(false) {}
|
||||
|
||||
template <class... Args,
|
||||
detail::enable_if_t<std::is_constructible<T, Args &&...>::value> * =
|
||||
@@ -414,6 +416,7 @@ template <class T, class E> struct expected_storage_base<T, E, true, false> {
|
||||
}
|
||||
|
||||
union {
|
||||
char m_no_init;
|
||||
T m_val;
|
||||
unexpected<E> m_unexpect;
|
||||
};
|
||||
@@ -423,7 +426,7 @@ template <class T, class E> struct expected_storage_base<T, E, true, false> {
|
||||
// E is trivial, T is not.
|
||||
template <class T, class E> struct expected_storage_base<T, E, false, true> {
|
||||
constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {}
|
||||
constexpr expected_storage_base(no_init_t) : m_has_val(false) {}
|
||||
constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {}
|
||||
|
||||
template <class... Args,
|
||||
detail::enable_if_t<std::is_constructible<T, Args &&...>::value> * =
|
||||
@@ -457,6 +460,7 @@ template <class T, class E> struct expected_storage_base<T, E, false, true> {
|
||||
}
|
||||
}
|
||||
union {
|
||||
char m_no_init;
|
||||
T m_val;
|
||||
unexpected<E> m_unexpect;
|
||||
};
|
||||
@@ -466,7 +470,7 @@ template <class T, class E> struct expected_storage_base<T, E, false, true> {
|
||||
// `T` is `void`, `E` is trivially-destructible
|
||||
template <class E> struct expected_storage_base<void, E, false, true> {
|
||||
TL_EXPECTED_MSVC2015_CONSTEXPR expected_storage_base() : m_has_val(true) {}
|
||||
constexpr expected_storage_base(no_init_t) : m_has_val(false) {}
|
||||
constexpr expected_storage_base(no_init_t) : m_val(), m_has_val(false) {}
|
||||
|
||||
constexpr expected_storage_base(in_place_t) : m_has_val(true) {}
|
||||
|
||||
@@ -522,6 +526,7 @@ template <class E> struct expected_storage_base<void, E, false, false> {
|
||||
|
||||
struct dummy {};
|
||||
union {
|
||||
char m_no_init;
|
||||
dummy m_val;
|
||||
unexpected<E> m_unexpect;
|
||||
};
|
||||
|
Reference in New Issue
Block a user