value = std::move(other.value); | 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))>) | void reset(T&& newValue) noexcept(std::is_nothrow_assignable_v<T, decltype(std::move_if_noexcept(newValue))>) | ||||
{ | { | ||||
value = std::forward<T>(newValue); | value = std::forward<T>(newValue); |
static inline bool throwOnNextCopy{false}; | 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 | |||||
{ | |||||
} | |||||
}; | |||||
} |
[[maybe_unused]] auto guard = sr::make_unique_resource_checked(Handle{-1}, Handle{-1}, deleter); | [[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); | |||||
} |