| @@ -62,6 +62,11 @@ namespace sr::detail | |||
| value = std::move(other.value); | |||
| } | |||
| void reset(const Wrapper<T>& other) noexcept(std::is_nothrow_assignable_v<T, const T&>) | |||
| { | |||
| value = other.value; | |||
| } | |||
| void reset(T&& newValue) noexcept(std::is_nothrow_assignable_v<T, decltype(std::move_if_noexcept(newValue))>) | |||
| { | |||
| value = std::forward<T>(newValue); | |||
| @@ -204,5 +204,50 @@ namespace mock | |||
| static inline bool throwOnNextCopy{false}; | |||
| }; | |||
| } | |||
| template<bool noexceptMove> | |||
| struct NoexceptResource | |||
| { | |||
| NoexceptResource() = default; | |||
| ~NoexceptResource() = default; | |||
| NoexceptResource(const NoexceptResource&) = default; | |||
| NoexceptResource(NoexceptResource&&) noexcept(noexceptMove) | |||
| { | |||
| } | |||
| NoexceptResource& operator=(const NoexceptResource&) = default; | |||
| NoexceptResource& operator=(NoexceptResource&&) noexcept(noexceptMove) | |||
| { | |||
| return *this; | |||
| } | |||
| }; | |||
| template<bool noexceptMove> | |||
| struct NoexceptDeleter | |||
| { | |||
| NoexceptDeleter() = default; | |||
| ~NoexceptDeleter() = default; | |||
| NoexceptDeleter(const NoexceptDeleter&) = default; | |||
| NoexceptDeleter(NoexceptDeleter&&) noexcept(noexceptMove) | |||
| { | |||
| } | |||
| NoexceptDeleter& operator=(const NoexceptDeleter&) = default; | |||
| NoexceptDeleter& operator=(NoexceptDeleter&&) noexcept(noexceptMove) | |||
| { | |||
| return *this; | |||
| } | |||
| template<class Resource> | |||
| void operator()(const Resource&) const | |||
| { | |||
| } | |||
| }; | |||
| } | |||
| @@ -222,3 +222,18 @@ TEST_CASE("make unique resource checked releases if invalid", "[UniqueResource]" | |||
| [[maybe_unused]] auto guard = sr::make_unique_resource_checked(Handle{-1}, Handle{-1}, deleter); | |||
| } | |||
| TEST_CASE("not noexcept move", "[UniqueResource]") | |||
| { | |||
| NoexceptDeleter<false> deleter{}; | |||
| auto guard = sr::unique_resource{NoexceptResource<false>{}, deleter}; | |||
| auto temp = std::move(guard); | |||
| guard = std::move(temp); | |||
| } | |||
| TEST_CASE("noexcept move", "[UniqueResource]") | |||
| { | |||
| NoexceptDeleter<true> deleter{}; | |||
| auto guard = sr::unique_resource{NoexceptResource<true>{}, deleter}; | |||
| auto temp = std::move(guard); | |||
| guard = std::move(temp); | |||
| } | |||