## Class template defer_guard

boost::scope::defer_guard — Defer guard that invokes a function upon leaving the scope.

## Synopsis

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

    template<typename Func>
    class defer_guard {
    public:

      // public member functions
      template<typename F> defer_guard(F &&);
      defer_guard(defer_guard const &) = delete;
      defer_guard & operator=(defer_guard const &) = delete;
      ~defer_guard();
    };

## Description

The scope guard wraps a function object callable with no arguments that 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 defer guard unconditionally invokes the wrapped function object on destruction.

### `defer_guard` public member functions

1.     template<typename F> defer_guard(F && func);

   Constructs a defer guard with a given callable function object.

   Requires: `Func` is constructible from func.

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

   If `Func` construction throws, invokes func before returning with the exception.

   Throws: Nothing, unless construction of the function object throws.

   Parameters:

   `func` | The callable function object to invoke on destruction.

2.     defer_guard(defer_guard const &) = delete;

3.     defer_guard & operator=(defer_guard const &) = delete;

4.     ~defer_guard();

   Invokes the wrapped callable function object and destroys the callable.

   Throws: Nothing, unless invoking the callable throws.