Browse Source

Strategy extracted for scope exit.

main
offa 7 years ago
parent
commit
176180601d
2 changed files with 16 additions and 5 deletions
  1. +13
    -2
      include/scope_exit.h
  2. +3
    -3
      include/scope_guard_base.h

+ 13
- 2
include/scope_exit.h View File

@@ -24,13 +24,24 @@

namespace sr
{
namespace detail
{
struct scope_exit_strategy
{
constexpr bool should_execute() const
{
return true;
}
};
}


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:

using detail::scope_guard_base<EF>::scope_guard_base;
using detail::scope_guard_base<EF, detail::scope_exit_strategy>::scope_guard_base;


private:

+ 3
- 3
include/scope_guard_base.h View File

@@ -28,8 +28,8 @@ namespace sr
namespace detail
{

template<class EF>
class scope_guard_base
template<class EF, class Strategy>
class scope_guard_base : private Strategy
{
public:

@@ -79,7 +79,7 @@ namespace detail

~scope_guard_base() noexcept(true)
{
if( m_execute_on_destruction == true )
if( m_execute_on_destruction == true && this->should_execute() == true )
{
m_exitFunction();
}

Loading…
Cancel
Save