|
|
|
|
|
|
|
|
std::enable_if_t<(!std::is_lvalue_reference<D>::value) |
|
|
std::enable_if_t<(!std::is_lvalue_reference<D>::value) |
|
|
&& std::is_nothrow_constructible<Deleter, D>::value, int> = 0 |
|
|
&& std::is_nothrow_constructible<Deleter, D>::value, int> = 0 |
|
|
> |
|
|
> |
|
|
explicit scope_exit(D&& deleter) : m_deleter(std::move(deleter)), |
|
|
|
|
|
|
|
|
explicit scope_exit(D&& deleter) : m_exitFunction(std::move(deleter)), |
|
|
m_execute_on_destruction(true) |
|
|
m_execute_on_destruction(true) |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::enable_if_t<std::is_constructible<Deleter, D>::value, int> = 0, |
|
|
std::enable_if_t<std::is_constructible<Deleter, D>::value, int> = 0, |
|
|
std::enable_if_t<std::is_lvalue_reference<D>::value, int> = 0 |
|
|
std::enable_if_t<std::is_lvalue_reference<D>::value, int> = 0 |
|
|
> |
|
|
> |
|
|
explicit scope_exit(D&& deleter) try : m_deleter(deleter), |
|
|
|
|
|
|
|
|
explicit scope_exit(D&& deleter) try : m_exitFunction(deleter), |
|
|
m_execute_on_destruction(true) |
|
|
m_execute_on_destruction(true) |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
template<class T = Deleter, |
|
|
template<class T = Deleter, |
|
|
std::enable_if_t<std::is_nothrow_move_constructible<T>::value, int> = 0 |
|
|
std::enable_if_t<std::is_nothrow_move_constructible<T>::value, int> = 0 |
|
|
> |
|
|
> |
|
|
scope_exit(scope_exit&& other) : m_deleter(std::move(other.m_deleter)), |
|
|
|
|
|
|
|
|
scope_exit(scope_exit&& other) : m_exitFunction(std::move(other.m_exitFunction)), |
|
|
m_execute_on_destruction(other.m_execute_on_destruction) |
|
|
m_execute_on_destruction(other.m_execute_on_destruction) |
|
|
{ |
|
|
{ |
|
|
other.release(); |
|
|
other.release(); |
|
|
|
|
|
|
|
|
template<class T = Deleter, |
|
|
template<class T = Deleter, |
|
|
std::enable_if_t<!std::is_nothrow_move_constructible<T>::value, int> = 0 |
|
|
std::enable_if_t<!std::is_nothrow_move_constructible<T>::value, int> = 0 |
|
|
> |
|
|
> |
|
|
scope_exit(scope_exit&& other) : m_deleter(other.m_deleter), |
|
|
|
|
|
|
|
|
scope_exit(scope_exit&& other) : m_exitFunction(other.m_exitFunction), |
|
|
m_execute_on_destruction(other.m_execute_on_destruction) |
|
|
m_execute_on_destruction(other.m_execute_on_destruction) |
|
|
{ |
|
|
{ |
|
|
other.release(); |
|
|
other.release(); |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
if( m_execute_on_destruction == true ) |
|
|
if( m_execute_on_destruction == true ) |
|
|
{ |
|
|
{ |
|
|
m_deleter(); |
|
|
|
|
|
|
|
|
m_exitFunction(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
|
|
|
|
|
|
Deleter m_deleter; |
|
|
|
|
|
|
|
|
Deleter m_exitFunction; |
|
|
bool m_execute_on_destruction; |
|
|
bool m_execute_on_destruction; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|