Scope exit guard that invokes a function upon leaving the scope with a failure condition satisfied.
Synopsis
Declared in header <boost/scope/scope_fail.hpp>
template<
typename Func,
typename Cond = exception_checker>
class scope_fail
: public scope_exit<Func, Cond>;
Member Functions
Name |
Description |
Returns |
|
Deactivates the scope guard. |
|
Activates or deactivates the scope guard. |
Description
The scope guard wraps two function objects: the scope guard action and a failure condition for invoking the action. Both function objects must be callable with no arguments and can be one of:
-
A user-defined class with a public
operator()
. -
An lvalue reference to such class.
-
An lvalue reference or pointer to function taking no arguments. The condition function object
operator()
must return a value contextually convertible totrue,
if the failure is detected and the action function object is allowed to be executed, andfalse
otherwise. Additionally, the failure condition function objectoperator()
must not throw, as otherwise the action function object may not be called. If not specified, the default failure condition checks whether the scope is left due to an exception - the action function object will not be called if the scope is left normally.