Merge branch 'master' of github.com:TartanLlama/expected

This commit is contained in:
Sy Brand
2022-11-24 13:22:17 +00:00
4 changed files with 24 additions and 23 deletions

View File

@ -825,7 +825,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
if (rhs.m_has_val) {
get() = std::forward<Rhs>(rhs).get();
} else {
destroy_val();
destroy_val();
construct_error(std::forward<Rhs>(rhs).geterr());
}
} else {
@ -858,7 +858,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
#endif
TL_EXPECTED_11_CONSTEXPR void destroy_val() {
get().~T();
get().~T();
}
};
@ -913,7 +913,7 @@ struct expected_operations_base<void, E> : expected_storage_base<void, E> {
#endif
TL_EXPECTED_11_CONSTEXPR void destroy_val() {
//no-op
//no-op
}
};
@ -1837,12 +1837,12 @@ private:
void swap_where_only_one_has_value_and_t_is_not_void(
expected &rhs, move_constructing_t_can_throw,
t_is_nothrow_move_constructible) {
e_is_nothrow_move_constructible) {
auto temp = std::move(rhs.err());
rhs.err().~unexpected_type();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try {
::new (rhs.valptr()) T(val());
::new (rhs.valptr()) T(std::move(val()));
val().~T();
::new (errptr()) unexpected_type(std::move(temp));
std::swap(this->m_has_val, rhs.m_has_val);
@ -1851,7 +1851,7 @@ private:
throw;
}
#else
::new (rhs.valptr()) T(val());
::new (rhs.valptr()) T(std::move(val()));
val().~T();
::new (errptr()) unexpected_type(std::move(temp));
std::swap(this->m_has_val, rhs.m_has_val);

View File

@ -38,9 +38,9 @@ TEST_CASE("Triviality", "[bases.triviality]") {
{
struct T {
T(const T&){}
T(T&&) {};
T& operator=(const T&) {}
T& operator=(T&&) {};
T(T&&) {}
T& operator=(const T&) { return *this; }
T& operator=(T&&) { return *this; }
~T(){}
};
REQUIRE(!std::is_trivially_copy_constructible<tl::expected<T,int>>::value);

View File

@ -3,13 +3,15 @@
#define TOKENPASTE(x, y) x##y
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
#undef STATIC_REQUIRE
#define STATIC_REQUIRE(e) \
constexpr bool TOKENPASTE2(rqure, __LINE__) = e; \
(void)TOKENPASTE2(rqure, __LINE__); \
REQUIRE(e);
TEST_CASE("Map extensions", "[extensions.map]") {
auto mul2 = [](int a) { return a * 2; };
auto ret_void = [](int a) {};
auto ret_void = [](int a) { (void)a; };
{
tl::expected<int, int> e = 21;
@ -143,7 +145,7 @@ TEST_CASE("Map extensions", "[extensions.map]") {
TEST_CASE("Map error extensions", "[extensions.map_error]") {
auto mul2 = [](int a) { return a * 2; };
auto ret_void = [](int a) {};
auto ret_void = [](int a) { (void)a; };
{
tl::expected<int, int> e = 21;
@ -252,8 +254,8 @@ TEST_CASE("Map error extensions", "[extensions.map_error]") {
}
TEST_CASE("And then extensions", "[extensions.and_then]") {
auto succeed = [](int a) { return tl::expected<int, int>(21 * 2); };
auto fail = [](int a) { return tl::expected<int, int>(tl::unexpect, 17); };
auto succeed = [](int a) { (void)a; return tl::expected<int, int>(21 * 2); };
auto fail = [](int a) { (void)a; return tl::expected<int, int>(tl::unexpect, 17); };
{
tl::expected<int, int> e = 21;
@ -370,11 +372,10 @@ TEST_CASE("And then extensions", "[extensions.and_then]") {
TEST_CASE("or_else", "[extensions.or_else]") {
using eptr = std::unique_ptr<int>;
auto succeed = [](int a) { return tl::expected<int, int>(21 * 2); };
auto succeedptr = [](eptr e) { return tl::expected<int,eptr>(21*2);};
auto fail = [](int a) { return tl::expected<int,int>(tl::unexpect, 17);};
auto efail = [](eptr e) { *e = 17;return tl::expected<int,eptr>(tl::unexpect, std::move(e));};
auto failptr = [](eptr e) { return tl::expected<int,eptr>(tl::unexpect, std::move(e));};
auto succeed = [](int a) { (void)a; return tl::expected<int, int>(21 * 2); };
auto succeedptr = [](eptr e) { (void)e; return tl::expected<int,eptr>(21*2);};
auto fail = [](int a) { (void)a; return tl::expected<int,int>(tl::unexpect, 17);};
auto failptr = [](eptr e) { *e = 17;return tl::expected<int,eptr>(tl::unexpect, std::move(e));};
auto failvoid = [](int) {};
auto failvoidptr = [](const eptr&) { /* don't consume */};
auto consumeptr = [](eptr) {};
@ -439,7 +440,7 @@ TEST_CASE("or_else", "[extensions.or_else]") {
{
tl::expected<int, eptr> e = 21;
auto ret = std::move(e).or_else(efail);
auto ret = std::move(e).or_else(failptr);
REQUIRE(ret);
REQUIRE(ret == 21);
}
@ -569,7 +570,7 @@ TEST_CASE("14", "[issue.14]") {
auto res = tl::expected<S,F>{tl::unexpect, F{}};
res.map_error([](F f) {
(void)f;
});
}

View File

@ -15,7 +15,7 @@ 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"; }
tl::expected<std::string, int> operation2(int const val) { (void)val; return "Bananas"; }
TEST_CASE("Issue 17", "[issues.17]") {
auto const intermediate_result = operation1();
@ -67,7 +67,7 @@ struct i31{
};
TEST_CASE("Issue 31", "[issues.31]") {
const tl::expected<i31, int> a = i31{42};
a->i;
(void)a->i;
tl::expected< void, std::string > result;
tl::expected< void, std::string > result2 = result;
@ -77,7 +77,7 @@ TEST_CASE("Issue 31", "[issues.31]") {
TEST_CASE("Issue 33", "[issues.33]") {
tl::expected<void, int> res {tl::unexpect, 0};
REQUIRE(!res);
res = res.map_error([](int i) { return 42; });
res = res.map_error([](int i) { (void)i; return 42; });
REQUIRE(res.error() == 42);
}