Skip to content

Commit

Permalink
Merge pull request #7 from TartanLlama/void_support
Browse files Browse the repository at this point in the history
Void support
  • Loading branch information
TartanLlama authored Dec 23, 2017
2 parents 07f7b57 + 6a0a4f8 commit 2468058
Show file tree
Hide file tree
Showing 4 changed files with 332 additions and 160 deletions.
21 changes: 13 additions & 8 deletions tests/bases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ TEST_CASE("Triviality", "[bases.triviality]") {
REQUIRE(std::is_trivially_move_assignable<tl::expected<int,int>>::value);
REQUIRE(std::is_trivially_destructible<tl::expected<int,int>>::value);

REQUIRE(std::is_trivially_copy_constructible<tl::expected<void,int>>::value);
REQUIRE(std::is_trivially_move_constructible<tl::expected<void,int>>::value);
REQUIRE(std::is_trivially_destructible<tl::expected<void,int>>::value);


{
struct T {
T(const T&) = default;
Expand Down Expand Up @@ -127,8 +132,8 @@ TEST_CASE("Deletion", "[bases.deletion]") {
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
REQUIRE(IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
REQUIRE(IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(std::is_trivially_move_assignable<decltype(e)>::value);
Expand All @@ -142,8 +147,8 @@ TEST_CASE("Deletion", "[bases.deletion]") {
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
Expand All @@ -157,8 +162,8 @@ TEST_CASE("Deletion", "[bases.deletion]") {
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
Expand All @@ -172,8 +177,8 @@ TEST_CASE("Deletion", "[bases.deletion]") {
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
Expand Down
27 changes: 19 additions & 8 deletions tests/constructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ TEST_CASE("Constructors", "[constructors]") {
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
REQUIRE(IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
REQUIRE(IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(std::is_trivially_move_assignable<decltype(e)>::value);
Expand All @@ -83,8 +83,8 @@ TEST_CASE("Constructors", "[constructors]") {
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
Expand All @@ -98,8 +98,8 @@ TEST_CASE("Constructors", "[constructors]") {
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
Expand All @@ -113,11 +113,22 @@ TEST_CASE("Constructors", "[constructors]") {
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
# endif
}

{
tl::expected<void,int> e;
REQUIRE(e);
}

{
tl::expected<void,int> e (tl::unexpect, 42);
REQUIRE(!e);
REQUIRE(e.error() == 42);
}
}
16 changes: 8 additions & 8 deletions tests/extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,63 +72,63 @@ TEST_CASE("Map extensions", "[extensions.map]") {
auto ret = e.map(ret_void);
REQUIRE(ret);
STATIC_REQUIRE(
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
}

{
const tl::expected<int, int> e = 21;
auto ret = e.map(ret_void);
REQUIRE(ret);
STATIC_REQUIRE(
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
}

{
tl::expected<int, int> e = 21;
auto ret = std::move(e).map(ret_void);
REQUIRE(ret);
STATIC_REQUIRE(
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
}

{
const tl::expected<int, int> e = 21;
auto ret = std::move(e).map(ret_void);
REQUIRE(ret);
STATIC_REQUIRE(
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
}

{
tl::expected<int, int> e(tl::unexpect, 21);
auto ret = e.map(ret_void);
REQUIRE(!ret);
STATIC_REQUIRE(
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
}

{
const tl::expected<int, int> e(tl::unexpect, 21);
auto ret = e.map(ret_void);
REQUIRE(!ret);
STATIC_REQUIRE(
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
}

{
tl::expected<int, int> e(tl::unexpect, 21);
auto ret = std::move(e).map(ret_void);
REQUIRE(!ret);
STATIC_REQUIRE(
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
}

{
const tl::expected<int, int> e(tl::unexpect, 21);
auto ret = std::move(e).map(ret_void);
REQUIRE(!ret);
STATIC_REQUIRE(
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
}


Expand Down
Loading

0 comments on commit 2468058

Please sign in to comment.