Skip to content

Commit

Permalink
Fix disabling of swap() (#50, thanks @negatratoron)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmoene committed Nov 2, 2022
1 parent 61e4481 commit 22906db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/nonstd/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,11 +1002,12 @@ class unexpected_type

// x.x.5.2.4 Swap

template< typename U=E >
nsel_REQUIRES_R( void,
std17::is_swappable<E>::value
std17::is_swappable<U>::value
)
swap( unexpected_type & other ) noexcept (
std17::is_nothrow_swappable<E>::value
std17::is_nothrow_swappable<U>::value
)
{
using std::swap;
Expand Down
18 changes: 18 additions & 0 deletions test/expected.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyConstMemberNonMoveableObject> create_nonmoveable()
{
return nonstd::make_unexpected<MyConstMemberNonMoveableObject>( MyConstMemberNonMoveableObject(3) );
}

} // namespace issue_50

// -----------------------------------------------------------------------
// using as optional

Expand Down

0 comments on commit 22906db

Please sign in to comment.