diff --git a/expected.hpp b/expected.hpp index 5d817a5..348cdb5 100644 --- a/expected.hpp +++ b/expected.hpp @@ -612,7 +612,15 @@ struct expected_copy_base : expected_operations_base { } expected_copy_base(expected_copy_base &&rhs) = default; - expected_copy_base &operator=(const expected_copy_base &rhs) = default; + expected_copy_base &operator=(const expected_copy_base &rhs) { + if (rhs.has_value()) { + this->construct(rhs.get()); + } + else { + this->construct_error(rhs.geterr()); + } + return *this; + } expected_copy_base &operator=(expected_copy_base &&rhs) = default; }; @@ -713,6 +721,7 @@ struct expected_move_assign_base operator=(const expected_move_assign_base &rhs) = default; expected_move_assign_base & + operator=(expected_move_assign_base &&rhs) noexcept( std::is_nothrow_move_constructible::value &&std::is_nothrow_move_assignable::value) { diff --git a/tests/constructors.cpp b/tests/constructors.cpp index 817797b..ad669eb 100644 --- a/tests/constructors.cpp +++ b/tests/constructors.cpp @@ -2,6 +2,8 @@ #include "expected.hpp" #include +#include +#include struct takes_init_and_variadic { std::vector v; @@ -59,4 +61,63 @@ TEST_CASE("Constructors", "[constructors]") { REQUIRE(std::get<1>(e->t) == 3); } + { + tl::expected e; + REQUIRE(std::is_default_constructible::value); + REQUIRE(std::is_copy_constructible::value); + REQUIRE(std::is_move_constructible::value); + REQUIRE(std::is_copy_assignable::value); + REQUIRE(std::is_move_assignable::value); + REQUIRE(IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))); + REQUIRE(IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))); +# if !defined(TL_EXPECTED_GCC49) + REQUIRE(std::is_trivially_move_constructible::value); + REQUIRE(std::is_trivially_move_assignable::value); +# endif + } + + { + tl::expected e; + REQUIRE(std::is_default_constructible::value); + REQUIRE(std::is_copy_constructible::value); + REQUIRE(std::is_move_constructible::value); + REQUIRE(std::is_copy_assignable::value); + REQUIRE(std::is_move_assignable::value); + REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))); + REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))); +# if !defined(TL_EXPECTED_GCC49) + REQUIRE(!std::is_trivially_move_constructible::value); + REQUIRE(!std::is_trivially_move_assignable::value); +# endif + } + + { + tl::expected e; + REQUIRE(std::is_default_constructible::value); + REQUIRE(std::is_copy_constructible::value); + REQUIRE(std::is_move_constructible::value); + REQUIRE(std::is_copy_assignable::value); + REQUIRE(std::is_move_assignable::value); + REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))); + REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))); +# if !defined(TL_EXPECTED_GCC49) + REQUIRE(!std::is_trivially_move_constructible::value); + REQUIRE(!std::is_trivially_move_assignable::value); +# endif + } + + { + tl::expected e; + REQUIRE(std::is_default_constructible::value); + REQUIRE(std::is_copy_constructible::value); + REQUIRE(std::is_move_constructible::value); + REQUIRE(std::is_copy_assignable::value); + REQUIRE(std::is_move_assignable::value); + REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))); + REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))); +# if !defined(TL_EXPECTED_GCC49) + REQUIRE(!std::is_trivially_move_constructible::value); + REQUIRE(!std::is_trivially_move_assignable::value); +# endif + } }