Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

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:
  // construct/copy/destruct
  template<typename F> defer_guard(F &&) noexcept(...);
  defer_guard(defer_guard const &) = delete;
  defer_guard & operator=(defer_guard const &) = delete;
  ~defer_guard() noexcept(...);
};

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 construct/copy/destruct

  1. template<typename F> defer_guard(F && func) noexcept(...);
    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() noexcept(...);
    Invokes the wrapped callable function object and destroys the callable.

    Throws: Nothing, unless invoking the callable throws.


PrevUpHomeNext