absl::Cleanup

Scope guard that invokes a callback on scope exit.

Synopsis

Declared in <absl/cleanup/cleanup.h>

template<
    typename Arg,
    typename Callback = void()>
class [[nodiscard]] Cleanup final

Description

absl::Cleanup implements the scope guard idiom, invoking the contained callback's operator()() && on scope exit.

This class doesn't allocate or take any locks, and is safe to use in a signal handler. Of course the callback with which it is constructed also must be signal safe in order for this to be useful.

Member Functions

NameDescription
Cleanup [constructor]Constructors
~Cleanup [destructor]Invoke the callback, if still engaged, on scope exit.
Cancel Prevent the callback from executing.
Invoke Execute the callback early and prevent it from running on destruction.

Deduction Guides

NameDescription
Cleanup<cleanup_internal::Tag, Callback> Deduction guide for creating an absl::Cleanup from a callback.

Non-Member Functions

NameDescription
MakeCleanupCreate an absl::Cleanup from a callback.

Return Value

NOTE

The return value should not be discarded.