| template<class RR = R, class DD = D, | template<class RR = R, class DD = D, | ||||
| std::enable_if_t<(std::is_nothrow_move_assignable_v<RR> | 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_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> | unique_resource& operator=(unique_resource&& other) noexcept(std::is_nothrow_assignable_v<R&, R> | ||||
| && std::is_nothrow_assignable_v<D&, D>) | && std::is_nothrow_assignable_v<D&, D>) | ||||
| { | { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| 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 | |||||
| { | |||||
| } | |||||
| }; | |||||
| } | } |
| TEST_CASE("std::function deleter", "[UniqueResource]") | TEST_CASE("std::function deleter", "[UniqueResource]") | ||||
| { | { | ||||
| const auto deleter = std::function<void(Handle)>{[]([[maybe_unused]] Handle h) { }}; | 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}; | 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); | |||||
| } | } |