mirror of
https://github.com/TartanLlama/expected.git
synced 2025-08-04 19:34:30 +02:00
@@ -101,3 +101,8 @@ struct non_copyable {
|
|||||||
TEST_CASE("Issue 42", "[issues.42]") {
|
TEST_CASE("Issue 42", "[issues.42]") {
|
||||||
tl::expected<non_copyable,int>{}.map([](non_copyable) {});
|
tl::expected<non_copyable,int>{}.map([](non_copyable) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Issue 43", "[issues.43]") {
|
||||||
|
auto result = tl::expected<void, std::string>{};
|
||||||
|
result = tl::make_unexpected(std::string{ "foo" });
|
||||||
|
}
|
@@ -732,7 +732,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
|
|||||||
if (rhs.m_has_val) {
|
if (rhs.m_has_val) {
|
||||||
get() = std::forward<Rhs>(rhs).get();
|
get() = std::forward<Rhs>(rhs).get();
|
||||||
} else {
|
} else {
|
||||||
get().~T();
|
destroy_val();
|
||||||
construct_error(std::forward<Rhs>(rhs).geterr());
|
construct_error(std::forward<Rhs>(rhs).geterr());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -763,6 +763,10 @@ struct expected_operations_base : expected_storage_base<T, E> {
|
|||||||
return std::move(this->m_unexpect);
|
return std::move(this->m_unexpect);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
constexpr void destroy_val() {
|
||||||
|
get().~T();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// This base class provides some handy member functions which can be used in
|
// This base class provides some handy member functions which can be used in
|
||||||
@@ -814,6 +818,10 @@ struct expected_operations_base<void, E> : expected_storage_base<void, E> {
|
|||||||
return std::move(this->m_unexpect);
|
return std::move(this->m_unexpect);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
constexpr void destroy_val() {
|
||||||
|
//no-op
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class manages conditionally having a trivial copy constructor
|
// This class manages conditionally having a trivial copy constructor
|
||||||
@@ -1655,7 +1663,7 @@ public:
|
|||||||
if (!has_value()) {
|
if (!has_value()) {
|
||||||
err() = rhs;
|
err() = rhs;
|
||||||
} else {
|
} else {
|
||||||
val().~T();
|
this->destroy_val();
|
||||||
::new (errptr()) unexpected<E>(rhs);
|
::new (errptr()) unexpected<E>(rhs);
|
||||||
this->m_has_val = false;
|
this->m_has_val = false;
|
||||||
}
|
}
|
||||||
@@ -1670,7 +1678,7 @@ public:
|
|||||||
if (!has_value()) {
|
if (!has_value()) {
|
||||||
err() = std::move(rhs);
|
err() = std::move(rhs);
|
||||||
} else {
|
} else {
|
||||||
val().~T();
|
this->destroy_val();
|
||||||
::new (errptr()) unexpected<E>(std::move(rhs));
|
::new (errptr()) unexpected<E>(std::move(rhs));
|
||||||
this->m_has_val = false;
|
this->m_has_val = false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user