| } | } | ||||
| else | else | ||||
| { | { | ||||
| m_resource = std::as_const(r); | |||||
| m_resource.reset(std::as_const(r)); | |||||
| } | } | ||||
| m_execute_on_destruction = true; | m_execute_on_destruction = true; |
| }; | }; | ||||
| struct NotNothrowAssignable | |||||
| { | |||||
| explicit NotNothrowAssignable(int value) : m_value(value) { } | |||||
| NotNothrowAssignable(const NotNothrowAssignable&) = default; | |||||
| NotNothrowAssignable& operator=(const NotNothrowAssignable& other) | |||||
| { | |||||
| if( this != &other ) | |||||
| { | |||||
| assignNotNoexcept(other.m_value); | |||||
| } | |||||
| return *this; | |||||
| } | |||||
| void assignNotNoexcept(int value) noexcept(false) | |||||
| { | |||||
| m_value = value; | |||||
| } | |||||
| int m_value; | |||||
| }; | |||||
| struct CopyMock | struct CopyMock | ||||
| { | { | ||||
| CopyMock() {} | |||||
| CopyMock() { } | |||||
| CopyMock(const CopyMock&) { } | CopyMock(const CopyMock&) { } | ||||
| }; | }; | ||||
| { | { | ||||
| REQUIRE_CALL(m, deleter(3)); | REQUIRE_CALL(m, deleter(3)); | ||||
| REQUIRE_CALL(m, deleter(7)); | REQUIRE_CALL(m, deleter(7)); | ||||
| auto guard = sr::unique_resource{Handle{3}, deleter}; | |||||
| const Handle h{7}; | |||||
| auto d = [](const auto& v) { deleter(v.m_value); }; | |||||
| auto guard = sr::unique_resource{NotNothrowAssignable{3}, d}; | |||||
| const NotNothrowAssignable h{7}; | |||||
| guard.reset(h); | guard.reset(h); | ||||
| } | } | ||||