From 22906db64970de2d2af46ddc1b5990c701b93368 Mon Sep 17 00:00:00 2001 From: Martin Moene Date: Wed, 2 Nov 2022 20:48:32 +0100 Subject: [PATCH] Fix disabling of swap() (#50, thanks @negatratoron) --- include/nonstd/expected.hpp | 5 +++-- test/expected.t.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/nonstd/expected.hpp b/include/nonstd/expected.hpp index f2b7f94..d9473a7 100644 --- a/include/nonstd/expected.hpp +++ b/include/nonstd/expected.hpp @@ -1002,11 +1002,12 @@ class unexpected_type // x.x.5.2.4 Swap + template< typename U=E > nsel_REQUIRES_R( void, - std17::is_swappable::value + std17::is_swappable::value ) swap( unexpected_type & other ) noexcept ( - std17::is_nothrow_swappable::value + std17::is_nothrow_swappable::value ) { using std::swap; diff --git a/test/expected.t.cpp b/test/expected.t.cpp index f7664ab..2f70046 100644 --- a/test/expected.t.cpp +++ b/test/expected.t.cpp @@ -1820,6 +1820,24 @@ CASE( "pr-41" ) EXPECT( std::move(cc).error() == 7 ); } +// issue #50, https://github.com/martinmoene/expected-lite/issues/50 + +namespace issue_50 { + +struct MyConstMemberNonMoveableObject +{ + const int x; + MyConstMemberNonMoveableObject( int x_ ) : x( x_ ) {} + MyConstMemberNonMoveableObject( MyConstMemberNonMoveableObject const & ) = default; +}; + +nonstd::unexpected_type create_nonmoveable() +{ + return nonstd::make_unexpected( MyConstMemberNonMoveableObject(3) ); +} + +} // namespace issue_50 + // ----------------------------------------------------------------------- // using as optional