|
|
|
|
|
|
|
|
&& (std::is_nothrow_constructible_v<D, DD> || std::is_nothrow_constructible_v<D, DD&>)) |
|
|
&& (std::is_nothrow_constructible_v<D, DD> || std::is_nothrow_constructible_v<D, DD&>)) |
|
|
: resource(detail::forward_if_nothrow_constructible<R, RR>(std::forward<RR>(r)), scope_exit{[&r, &d] { d(r); }}), |
|
|
: resource(detail::forward_if_nothrow_constructible<R, RR>(std::forward<RR>(r)), scope_exit{[&r, &d] { d(r); }}), |
|
|
deleter(detail::forward_if_nothrow_constructible<D, DD>(std::forward<DD>(d)), scope_exit{[this, &d] { d(get()); }}), |
|
|
deleter(detail::forward_if_nothrow_constructible<D, DD>(std::forward<DD>(d)), scope_exit{[this, &d] { d(get()); }}), |
|
|
execute_on_destruction(true) |
|
|
|
|
|
|
|
|
execute_on_reset(true) |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deleter(std::move_if_noexcept(other.deleter.get()), scope_exit{[&other] { |
|
|
deleter(std::move_if_noexcept(other.deleter.get()), scope_exit{[&other] { |
|
|
other.get_deleter()(other.resource.get()); |
|
|
other.get_deleter()(other.resource.get()); |
|
|
other.release(); }}), |
|
|
other.release(); }}), |
|
|
execute_on_destruction(std::exchange(other.execute_on_destruction, false)) |
|
|
|
|
|
|
|
|
execute_on_reset(std::exchange(other.execute_on_reset, false)) |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void reset() noexcept |
|
|
void reset() noexcept |
|
|
{ |
|
|
{ |
|
|
if( execute_on_destruction == true ) |
|
|
|
|
|
|
|
|
if( execute_on_reset == true ) |
|
|
{ |
|
|
{ |
|
|
execute_on_destruction = false; |
|
|
|
|
|
|
|
|
execute_on_reset = false; |
|
|
get_deleter()(resource.get()); |
|
|
get_deleter()(resource.get()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
resource.reset(std::as_const(r)); |
|
|
resource.reset(std::as_const(r)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
execute_on_destruction = true; |
|
|
|
|
|
|
|
|
execute_on_reset = true; |
|
|
se.release(); |
|
|
se.release(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void release() noexcept |
|
|
void release() noexcept |
|
|
{ |
|
|
{ |
|
|
execute_on_destruction = false; |
|
|
|
|
|
|
|
|
execute_on_reset = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const R& get() const noexcept |
|
|
const R& get() const noexcept |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
execute_on_destruction = std::exchange(other.execute_on_destruction, false); |
|
|
|
|
|
|
|
|
execute_on_reset = std::exchange(other.execute_on_reset, false); |
|
|
} |
|
|
} |
|
|
return *this; |
|
|
return *this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
detail::Wrapper<R> resource; |
|
|
detail::Wrapper<R> resource; |
|
|
detail::Wrapper<D> deleter; |
|
|
detail::Wrapper<D> deleter; |
|
|
bool execute_on_destruction; |
|
|
|
|
|
|
|
|
bool execute_on_reset; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|