26 #ifndef HT_SCOPEGUARD_H
27 #define HT_SCOPEGUARD_H
44 template <
typename GuardT>
46 if (!guard.m_dismissed)
try {
73 template <
typename FunT>
88 template <
typename FunT>
96 template <
typename FunT,
typename P1T>
113 template <
typename FunT,
typename P1T>
121 template <
typename FunT,
typename P1T,
typename P2T>
139 template <
typename FunT,
typename P1T,
typename P2T>
147 template <
typename FunT,
typename P1T,
typename P2T,
typename P3T>
168 template <
typename FunT,
typename P1T,
typename P2T,
typename P3T>
177 template <
class ObjT,
typename MethodT>
196 template <
class ObjT,
typename MethodT>
205 template <
class ObjT,
typename MethodT,
typename P1T>
225 template <
class ObjT,
typename MethodT,
typename P1T>
234 template <
class ObjT,
typename MethodT,
typename P1T,
typename P2T>
255 template <
class ObjT,
typename MethodT,
typename P1T,
typename P2T>
278 operator T& ()
const {
return m_ref; }
297 #define HT_CONCAT_(s1, s2) s1##s2
298 #define HT_CONCAT(s1, s2) HT_CONCAT_(s1, s2)
299 #define HT_AUTO_VAR(var) HT_CONCAT(var, __LINE__)
301 #define HT_ON_SCOPE_EXIT(...) \
302 ScopeGuard HT_AUTO_VAR(guard) = make_guard(__VA_ARGS__); \
303 HT_UNUSED(HT_AUTO_VAR(guard))
305 #define HT_ON_OBJ_SCOPE_EXIT(...) \
306 ScopeGuard HT_AUTO_VAR(guard) = make_obj_guard(__VA_ARGS__); \
307 HT_UNUSED(HT_AUTO_VAR(guard))
309 #endif // HT_SCOPEGUARD_H
ScopeGuard implementation for free function with 2 parameters.
static ScopeGuardImpl3< FunT, P1T, P2T, P3T > make_guard(FunT fun, P1T p1, P2T p2, P3T p3)
static ObjScopeGuardImpl2< ObjT, MethodT, P1T, P2T > make_obj_guard(ObjT &obj, MethodT method, P1T p1, P2T p2)
ObjScopeGuardImpl0(ObjT &obj, MethodT method)
ScopeGuard implementation for free function with 3 parameters.
ScopeGuard implementation for method with 1 parameter.
ScopeGuardImplBase & operator=(const ScopeGuardImplBase &)
const ScopeGuardImplBase & ScopeGuard
ObjScopeGuardImpl0< ObjT, MethodT > make_obj_guard(ObjT &obj, MethodT method)
ObjScopeGuardImpl1(ObjT &obj, MethodT method, P1T p1)
static ObjScopeGuardImpl0< ObjT, MethodT > make_obj_guard(ObjT &obj, MethodT method)
ScopeGuardImpl0(FunT fun)
ScopeGuard implementation for method with 2 parameters.
ScopeGuardImplBase(const ScopeGuardImplBase &other)
ObjScopeGuardImpl2(ObjT &obj, MethodT method, P1T p1, P2T p2)
ScopeGuard implementation for free function with no paramter.
RefHolder & operator=(const RefHolder &)
static ScopeGuardImpl1< FunT, P1T > make_guard(FunT fun, P1T p1)
ScopeGuardImpl2(FunT fun, P1T p1, P2T p2)
ScopeGuardImpl1(FunT fun, P1T p1)
static ScopeGuardImpl2< FunT, P1T, P2T > make_guard(FunT fun, P1T p1, P2T p2)
static ScopeGuardImpl0< FunT > make_guard(FunT fun)
ScopeGuardImpl0< FunT > make_guard(FunT fun)
ScopeGuardImpl3(FunT fun, P1T p1, P2T p2, P3T p3)
Base class for the ScopeGuards.
ScopeGuard implementation for free function with 1 parameter.
RefHolder< T > by_ref(T &t)
static ObjScopeGuardImpl1< ObjT, MethodT, P1T > make_obj_guard(ObjT &obj, MethodT method, P1T p1)
Helper class used to pass a parameter to the ScopeGuard by reference.
static void safe_run(GuardT &guard)
ScopeGuard implementation for method with no parameter.