mirror of
https://github.com/TartanLlama/expected.git
synced 2025-07-30 08:57:18 +02:00
Merge branch 'master' of github.com:TartanLlama/expected
This commit is contained in:
@ -825,7 +825,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 {
|
||||||
destroy_val();
|
destroy_val();
|
||||||
construct_error(std::forward<Rhs>(rhs).geterr());
|
construct_error(std::forward<Rhs>(rhs).geterr());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -858,7 +858,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
TL_EXPECTED_11_CONSTEXPR void destroy_val() {
|
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
|
#endif
|
||||||
|
|
||||||
TL_EXPECTED_11_CONSTEXPR void destroy_val() {
|
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(
|
void swap_where_only_one_has_value_and_t_is_not_void(
|
||||||
expected &rhs, move_constructing_t_can_throw,
|
expected &rhs, move_constructing_t_can_throw,
|
||||||
t_is_nothrow_move_constructible) {
|
e_is_nothrow_move_constructible) {
|
||||||
auto temp = std::move(rhs.err());
|
auto temp = std::move(rhs.err());
|
||||||
rhs.err().~unexpected_type();
|
rhs.err().~unexpected_type();
|
||||||
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
|
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
|
||||||
try {
|
try {
|
||||||
::new (rhs.valptr()) T(val());
|
::new (rhs.valptr()) T(std::move(val()));
|
||||||
val().~T();
|
val().~T();
|
||||||
::new (errptr()) unexpected_type(std::move(temp));
|
::new (errptr()) unexpected_type(std::move(temp));
|
||||||
std::swap(this->m_has_val, rhs.m_has_val);
|
std::swap(this->m_has_val, rhs.m_has_val);
|
||||||
@ -1851,7 +1851,7 @@ private:
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
::new (rhs.valptr()) T(val());
|
::new (rhs.valptr()) T(std::move(val()));
|
||||||
val().~T();
|
val().~T();
|
||||||
::new (errptr()) unexpected_type(std::move(temp));
|
::new (errptr()) unexpected_type(std::move(temp));
|
||||||
std::swap(this->m_has_val, rhs.m_has_val);
|
std::swap(this->m_has_val, rhs.m_has_val);
|
||||||
|
@ -38,9 +38,9 @@ TEST_CASE("Triviality", "[bases.triviality]") {
|
|||||||
{
|
{
|
||||||
struct T {
|
struct T {
|
||||||
T(const T&){}
|
T(const T&){}
|
||||||
T(T&&) {};
|
T(T&&) {}
|
||||||
T& operator=(const T&) {}
|
T& operator=(const T&) { return *this; }
|
||||||
T& operator=(T&&) {};
|
T& operator=(T&&) { return *this; }
|
||||||
~T(){}
|
~T(){}
|
||||||
};
|
};
|
||||||
REQUIRE(!std::is_trivially_copy_constructible<tl::expected<T,int>>::value);
|
REQUIRE(!std::is_trivially_copy_constructible<tl::expected<T,int>>::value);
|
||||||
|
@ -3,13 +3,15 @@
|
|||||||
|
|
||||||
#define TOKENPASTE(x, y) x##y
|
#define TOKENPASTE(x, y) x##y
|
||||||
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
|
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
|
||||||
|
#undef STATIC_REQUIRE
|
||||||
#define STATIC_REQUIRE(e) \
|
#define STATIC_REQUIRE(e) \
|
||||||
constexpr bool TOKENPASTE2(rqure, __LINE__) = e; \
|
constexpr bool TOKENPASTE2(rqure, __LINE__) = e; \
|
||||||
|
(void)TOKENPASTE2(rqure, __LINE__); \
|
||||||
REQUIRE(e);
|
REQUIRE(e);
|
||||||
|
|
||||||
TEST_CASE("Map extensions", "[extensions.map]") {
|
TEST_CASE("Map extensions", "[extensions.map]") {
|
||||||
auto mul2 = [](int a) { return a * 2; };
|
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;
|
tl::expected<int, int> e = 21;
|
||||||
@ -143,7 +145,7 @@ TEST_CASE("Map extensions", "[extensions.map]") {
|
|||||||
|
|
||||||
TEST_CASE("Map error extensions", "[extensions.map_error]") {
|
TEST_CASE("Map error extensions", "[extensions.map_error]") {
|
||||||
auto mul2 = [](int a) { return a * 2; };
|
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;
|
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]") {
|
TEST_CASE("And then extensions", "[extensions.and_then]") {
|
||||||
auto succeed = [](int a) { return tl::expected<int, int>(21 * 2); };
|
auto succeed = [](int a) { (void)a; return tl::expected<int, int>(21 * 2); };
|
||||||
auto fail = [](int a) { return tl::expected<int, int>(tl::unexpect, 17); };
|
auto fail = [](int a) { (void)a; return tl::expected<int, int>(tl::unexpect, 17); };
|
||||||
|
|
||||||
{
|
{
|
||||||
tl::expected<int, int> e = 21;
|
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]") {
|
TEST_CASE("or_else", "[extensions.or_else]") {
|
||||||
using eptr = std::unique_ptr<int>;
|
using eptr = std::unique_ptr<int>;
|
||||||
auto succeed = [](int a) { return tl::expected<int, int>(21 * 2); };
|
auto succeed = [](int a) { (void)a; return tl::expected<int, int>(21 * 2); };
|
||||||
auto succeedptr = [](eptr e) { return tl::expected<int,eptr>(21*2);};
|
auto succeedptr = [](eptr e) { (void)e; return tl::expected<int,eptr>(21*2);};
|
||||||
auto fail = [](int a) { return tl::expected<int,int>(tl::unexpect, 17);};
|
auto fail = [](int a) { (void)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) { *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 failvoid = [](int) {};
|
auto failvoid = [](int) {};
|
||||||
auto failvoidptr = [](const eptr&) { /* don't consume */};
|
auto failvoidptr = [](const eptr&) { /* don't consume */};
|
||||||
auto consumeptr = [](eptr) {};
|
auto consumeptr = [](eptr) {};
|
||||||
@ -439,7 +440,7 @@ TEST_CASE("or_else", "[extensions.or_else]") {
|
|||||||
|
|
||||||
{
|
{
|
||||||
tl::expected<int, eptr> e = 21;
|
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);
|
||||||
REQUIRE(ret == 21);
|
REQUIRE(ret == 21);
|
||||||
}
|
}
|
||||||
@ -569,7 +570,7 @@ TEST_CASE("14", "[issue.14]") {
|
|||||||
auto res = tl::expected<S,F>{tl::unexpect, F{}};
|
auto res = tl::expected<S,F>{tl::unexpect, F{}};
|
||||||
|
|
||||||
res.map_error([](F f) {
|
res.map_error([](F f) {
|
||||||
|
(void)f;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ TEST_CASE("Issue 1", "[issues.1]") { getInt1(); }
|
|||||||
|
|
||||||
tl::expected<int, int> operation1() { return 42; }
|
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]") {
|
TEST_CASE("Issue 17", "[issues.17]") {
|
||||||
auto const intermediate_result = operation1();
|
auto const intermediate_result = operation1();
|
||||||
@ -67,7 +67,7 @@ struct i31{
|
|||||||
};
|
};
|
||||||
TEST_CASE("Issue 31", "[issues.31]") {
|
TEST_CASE("Issue 31", "[issues.31]") {
|
||||||
const tl::expected<i31, int> a = i31{42};
|
const tl::expected<i31, int> a = i31{42};
|
||||||
a->i;
|
(void)a->i;
|
||||||
|
|
||||||
tl::expected< void, std::string > result;
|
tl::expected< void, std::string > result;
|
||||||
tl::expected< void, std::string > result2 = result;
|
tl::expected< void, std::string > result2 = result;
|
||||||
@ -77,7 +77,7 @@ TEST_CASE("Issue 31", "[issues.31]") {
|
|||||||
TEST_CASE("Issue 33", "[issues.33]") {
|
TEST_CASE("Issue 33", "[issues.33]") {
|
||||||
tl::expected<void, int> res {tl::unexpect, 0};
|
tl::expected<void, int> res {tl::unexpect, 0};
|
||||||
REQUIRE(!res);
|
REQUIRE(!res);
|
||||||
res = res.map_error([](int i) { return 42; });
|
res = res.map_error([](int i) { (void)i; return 42; });
|
||||||
REQUIRE(res.error() == 42);
|
REQUIRE(res.error() == 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user