| namespace sr | namespace sr | ||||
| { | { | ||||
| namespace detail | |||||
| { | |||||
| struct scope_exit_strategy | |||||
| { | |||||
| constexpr bool should_execute() const | |||||
| { | |||||
| return true; | |||||
| } | |||||
| }; | |||||
| } | |||||
| template<class EF> | template<class EF> | ||||
| class scope_exit : public detail::scope_guard_base<EF> | |||||
| class scope_exit : public detail::scope_guard_base<EF, detail::scope_exit_strategy> | |||||
| { | { | ||||
| public: | public: | ||||
| using detail::scope_guard_base<EF>::scope_guard_base; | |||||
| using detail::scope_guard_base<EF, detail::scope_exit_strategy>::scope_guard_base; | |||||
| private: | private: |
| namespace detail | namespace detail | ||||
| { | { | ||||
| template<class EF> | |||||
| class scope_guard_base | |||||
| template<class EF, class Strategy> | |||||
| class scope_guard_base : private Strategy | |||||
| { | { | ||||
| public: | public: | ||||
| ~scope_guard_base() noexcept(true) | ~scope_guard_base() noexcept(true) | ||||
| { | { | ||||
| if( m_execute_on_destruction == true ) | |||||
| if( m_execute_on_destruction == true && this->should_execute() == true ) | |||||
| { | { | ||||
| m_exitFunction(); | m_exitFunction(); | ||||
| } | } |