template <typename T>
muu::scope_guard class

Performs actions when going out of scope.

Template parameters
T A noexcept function, lambda or other callable not requiring any arguments (e.g. void() noexcept)`.

Use a scope_guard to simplify cleanup routines or code that has acquire/release semantics, e.g. locking:

void do_work()
{
    acquire_magic_lock();
    muu::scope_guard sg{ release_magic_lock };
    something_that_throws();
}

For comparison's sake, here's the same function without a scope_guard:

void do_work()
{
    acquire_magic_lock();
    try
    {
        something_that_throws();
    }
    catch (...)
    {
        release_magic_lock();
        throw;
    }
    release_magic_lock();
}

Constructors, destructors, conversion operators

template <typename U>
scope_guard(U&& func) explicit noexcept(…)
Constructs a scope_guard by wrapping a callable.

Public functions

void dismiss() noexcept
Dismisses the scope guard, cancelling invocation of the wrapped callable.
auto dismissed() const -> bool noexcept
Returns true if the scope guard has been dismissed.

Function documentation

template <typename T>
template <typename U>
muu::scope_guard::scope_guard(U&& func) explicit noexcept(…)

Constructs a scope_guard by wrapping a callable.

Template parameters
U A function, lambda or other callable with the signature void() noexcept.
Parameters
func The callable to invoke when the scope_guard goes out of scope.