浏览代码

Strategy extracted for scope exit.

main
offa 8 年前
父节点
当前提交
176180601d
共有 2 个文件被更改,包括 16 次插入5 次删除
  1. +13
    -2
      include/scope_exit.h
  2. +3
    -3
      include/scope_guard_base.h

+ 13
- 2
include/scope_exit.h 查看文件



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:

+ 3
- 3
include/scope_guard_base.h 查看文件

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();
} }

正在加载...
取消
保存