## Class template scope_success

boost::scope::scope_success — Scope exit guard that invokes a function upon leaving the scope, if a failure condition is not satisfied.

## Synopsis

    // In header: <boost/scope/scope_success.hpp>

    template<typename Func, typename Cond = exception_checker>
    class scope_success {
    public:

      // public member functions
      template<typename F> explicit scope_success(F &&, bool = true);
      template<typename F, typename C>
        explicit scope_success(F &&, C &&, bool = true);
      scope_success(scope_success &&);
      scope_success & operator=(scope_success &&) = delete;
      scope_success(scope_success const &) = delete;
      scope_success & operator=(scope_success const &) = delete;
    };

## 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.

See Also: scope_exit

See Also: scope_fail

### Template Parameters

1.     typename Func

   Scope guard action function object type.

2.     typename Cond = exception_checker

   Scope guard failure condition function object type.

### `scope_success` public member functions

1.     template<typename F> explicit scope_success(F && func, bool active = true);

   Constructs a scope guard with a given callable function object.

   Requires: `Func` is constructible from func. `Cond` is nothrow default-constructible.

   Effects: Constructs the scope guard as if by calling `scope_success(std::forward< F >(func), Cond(), active)`.

   Throws: Nothing, unless construction of the function objects throw.

   Parameters: |
   `func` | The callable action function object to invoke on destruction.
   `active` | Indicates whether the scope guard should be active upon construction.
   Postconditions: | `this->active() == active`

2.     template<typename F, typename C>
         explicit scope_success(F && func, C && cond, bool active = true);

   Constructs a scope guard with a given callable action and failure condition function objects.

   Requires: `Func` is constructible from func. `Cond` is constructible from cond.

   Effects: If `Func` is nothrow constructible from `F&&` then constructs `Func` from `std::forward< F >(func)`, otherwise constructs from `func`. If `Cond` is nothrow constructible from `C&&` then constructs `Cond` from `std::forward< C >(cond)`, otherwise constructs from `cond`.

   If `Func` or `Cond` construction throws and active is `true`, invokes cond and, if it returns `true`, func before returning with the exception.

   Throws: Nothing, unless construction of the function objects throw.

   Parameters: |
   `func` | The callable action function object to invoke on destruction.
   `cond` | The callable failure condition function object.
   `active` | Indicates whether the scope guard should be active upon construction.
   Postconditions: | `this->active() == active`

3.     scope_success(scope_success && that);

   Move-constructs a scope guard.

   Requires: `Func` and `Cond` are nothrow move-constructible or copy-constructible.

   Effects: If `Func` is nothrow move-constructible then move-constructs `Func` from a member of that, otherwise copy-constructs `Func`. If `Cond` is nothrow move-constructible then move-constructs `Cond` from a member of that, otherwise copy-constructs `Cond`.

   If `Func` or `Cond` construction throws and `that.active() == true`, invokes `Cond` object stored in that and, if it returns `true`, Func object (either the newly constructed one, if its construction succeeded, or the original one stored in that) before returning with the exception.

   If the construction succeeds, marks that as inactive.

   Throws: Nothing, unless move-construction of the function objects throw.

   Parameters: |
   `that` | Move source.
   Postconditions: | `that.active() == false`

4.     scope_success & operator=(scope_success &&) = delete;

5.     scope_success(scope_success const &) = delete;

6.     scope_success & operator=(scope_success const &) = delete;