diff --git a/README.md b/README.md index c7295dc..6a621ec 100644 --- a/README.md +++ b/README.md @@ -371,6 +371,8 @@ bad_expected_access: Allows to observe its error bad_expected_access: Allows to change its error bad_expected_access: Provides non-empty what() expected: Allows to default construct +expected: Allows to default construct from noncopyable, noncopyable value type +expected: Allows to default construct from noncopyable, noncopyable error type expected: Allows to copy-construct from expected: value expected: Allows to copy-construct from expected: error expected: Allows to move-construct from expected: value diff --git a/test/expected.t.cpp b/test/expected.t.cpp index ea256f2..59ef0dd 100644 --- a/test/expected.t.cpp +++ b/test/expected.t.cpp @@ -29,19 +29,35 @@ using namespace nonstd; struct Implicit { int x; Implicit(int v) : x(v) {} }; struct Explicit { int x; explicit Explicit(int v) : x(v) {} }; -struct MoveOnly { + +struct MoveOnly +{ int x; explicit MoveOnly(int x) :x{x} {} - MoveOnly(const MoveOnly&) = delete; - MoveOnly(MoveOnly&& other) noexcept :x{other.x} {} - MoveOnly& operator=(const MoveOnly&) = delete; - MoveOnly& operator=(MoveOnly&& other) noexcept { - if (&other == this) return *this; + + MoveOnly( MoveOnly const & ) = delete; + MoveOnly( MoveOnly && other ) noexcept : x{ other.x } {} + + MoveOnly& operator=( MoveOnly const & ) = delete; + MoveOnly& operator=( MoveOnly && other ) noexcept + { + if (&other == this) + return *this; x = other.x; return *this; } }; +struct NonMovableNonCopyable +{ + NonMovableNonCopyable() = default; + + NonMovableNonCopyable( NonMovableNonCopyable const & ) = delete; + NonMovableNonCopyable( NonMovableNonCopyable && ) = delete; + NonMovableNonCopyable& operator=( NonMovableNonCopyable const & ) = delete; + NonMovableNonCopyable& operator=( NonMovableNonCopyable && ) = delete; +}; + bool operator==( Implicit a, Implicit b ) { return a.x == b.x; } bool operator==( Explicit a, Explicit b ) { return a.x == b.x; } @@ -619,6 +635,20 @@ CASE( "expected: Allows to default construct" ) EXPECT( e.has_value() ); } +CASE( "expected: Allows to default construct from noncopyable, noncopyable value type" ) +{ + expected e; + + EXPECT( e.has_value() ); +} + +CASE( "expected: Allows to default construct from noncopyable, noncopyable error type" ) +{ + expected e{ unexpect_t{} }; + + EXPECT( !e.has_value() ); +} + CASE( "expected: Allows to copy-construct from expected: value" ) { expected a = 7; @@ -1892,13 +1922,11 @@ struct NonMovableNonCopyable CASE( "issue-58" ) { - using namespace issue_59; - - static_assert( !std::is_copy_constructible::value, "is not copy constructible" ); - static_assert( !std::is_move_constructible::value, "is not move constructible" ); + static_assert( !std::is_copy_constructible::value, "is not copy constructible" ); + static_assert( !std::is_move_constructible::value, "is not move constructible" ); - nonstd::expected expected; - nonstd::expected unexpected( nonstd::unexpect_t{} ); + nonstd::expected expected; + nonstd::expected unexpected( nonstd::unexpect_t{} ); EXPECT( expected.has_value() ); EXPECT( !unexpected.has_value() );