| } | } | ||||
| void swap(unique_resource& other) noexcept(std::is_nothrow_swappable_v<R> | |||||
| && std::is_nothrow_swappable_v<D> | |||||
| && std::is_nothrow_swappable_v<bool>) | |||||
| { | |||||
| using std::swap; | |||||
| swap(m_resource.get(), other.m_resource.get()); | |||||
| swap(m_deleter.get(), other.m_deleter.get()); | |||||
| swap(m_execute_on_destruction, other.m_execute_on_destruction); | |||||
| } | |||||
| void reset() | void reset() | ||||
| { | { | ||||
| if( m_execute_on_destruction == true ) | if( m_execute_on_destruction == true ) |
| } | } | ||||
| } | } | ||||
| TEST_CASE("swap", "[UniqueResource]") | |||||
| { | |||||
| REQUIRE_CALL(m, deleter(7)); | |||||
| auto guard1 = sr::unique_resource(Handle{3}, deleter); | |||||
| { | |||||
| REQUIRE_CALL(m, deleter(3)); | |||||
| auto guard2 = sr::unique_resource{Handle{7}, deleter}; | |||||
| guard2.swap(guard1); | |||||
| REQUIRE(guard1.get() == 7); | |||||
| REQUIRE(guard2.get() == 3); | |||||
| } | |||||
| } | |||||
| TEST_CASE("make unique resource", "[UniqueResource]") | TEST_CASE("make unique resource", "[UniqueResource]") | ||||
| { | { | ||||
| REQUIRE_CALL(m, deleter(7)); | REQUIRE_CALL(m, deleter(7)); |