@@ -149,9 +149,9 @@ namespace sr | |||
template<class RR = R, class DD = D, | |||
std::enable_if_t<(std::is_nothrow_move_assignable_v<RR> | |||
|| std::is_nothrow_copy_assignable_v<RR>) | |||
|| std::is_copy_assignable_v<RR>) | |||
&& (std::is_nothrow_move_assignable_v<DD> | |||
|| std::is_nothrow_copy_assignable_v<DD>), int> = 0> | |||
|| std::is_copy_assignable_v<DD>), int> = 0> | |||
unique_resource& operator=(unique_resource&& other) noexcept(std::is_nothrow_assignable_v<R&, R> | |||
&& std::is_nothrow_assignable_v<D&, D>) | |||
{ | |||
@@ -222,5 +222,3 @@ namespace sr | |||
} | |||
} | |||
@@ -249,5 +249,25 @@ namespace mock | |||
} | |||
}; | |||
struct FunctionDeleter | |||
{ | |||
FunctionDeleter() noexcept = default; | |||
FunctionDeleter(const FunctionDeleter&) = default; | |||
FunctionDeleter(FunctionDeleter&&) = default; | |||
FunctionDeleter& operator=(const FunctionDeleter&) | |||
{ | |||
return *this; | |||
} | |||
FunctionDeleter& operator=(FunctionDeleter&&) | |||
{ | |||
return *this; | |||
} | |||
void operator()(Handle) const | |||
{ | |||
} | |||
}; | |||
} |
@@ -241,7 +241,14 @@ TEST_CASE("noexcept move", "[UniqueResource]") | |||
TEST_CASE("std::function deleter", "[UniqueResource]") | |||
{ | |||
const auto deleter = std::function<void(Handle)>{[]([[maybe_unused]] Handle h) { }}; | |||
sr::unique_resource guard1{Handle{3}, deleter}; | |||
sr::unique_resource movedFrom{Handle{3}, deleter}; | |||
sr::unique_resource guard2{Handle{4}, deleter}; | |||
guard2 = std::move(guard1); | |||
guard2 = std::move(movedFrom); | |||
} | |||
TEST_CASE("not noexcept move and copy assignable deleter", "[UniqueResource]") | |||
{ | |||
sr::unique_resource movedFrom{0, FunctionDeleter{}}; | |||
sr::unique_resource guard{0, FunctionDeleter{}}; | |||
guard = std::move(movedFrom); | |||
} |