...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::scope::defer_guard — Defer guard that invokes a function upon leaving the scope.
// 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(...); };
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/destructtemplate<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: |
|
defer_guard(defer_guard const &) = delete;
defer_guard & operator=(defer_guard const &) = delete;
~defer_guard() noexcept(...);Invokes the wrapped callable function object and destroys the callable.
Throws: Nothing, unless invoking the callable throws.