Scope exit guard that invokes a function upon leaving the scope with a failure condition not satisfied.

Synopsis

Declared in header <boost/scope/scope_success.hpp>

template<
    typename Func,
    typename Cond = exception_checker>
class scope_success
    : public scope_exit<Func, logical_not<Cond>>;

Member Functions

Name

Description

active

Returns true if the scope guard is active, otherwise false.

operator=

release

Deactivates the scope guard.

scope_success

set_active

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 to true, if the failure is detected and the action function object is not allowed to be executed, and false otherwise. Additionally, the failure condition function object operator() 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 only be called if the scope is left normally.