[#absl-Cleanup-0a] = xref:absl.adoc[absl]::Cleanup :relfileprefix: ../ :mrdocs: Scope guard that invokes a callback on scope exit. == Synopsis Declared in `<absl/cleanup/cleanup.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- 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 [cols="1,4"] |=== | Name| Description | xref:absl/Cleanup-0a/2constructor-0e.adoc[`Cleanup`] [.small]#[constructor]# | Constructors | xref:absl/Cleanup-0a/2destructor.adoc[`~Cleanup`] [.small]#[destructor]# | Invoke the callback, if still engaged, on scope exit. | xref:absl/Cleanup-0a/Cancel.adoc[`Cancel`] | Prevent the callback from executing. | xref:absl/Cleanup-0a/Invoke.adoc[`Invoke`] | Execute the callback early and prevent it from running on destruction. |=== == Deduction Guides [cols="1,4"] |=== | Name| Description | xref:absl/Cleanup-03.adoc[`Cleanup<cleanup_internal::Tag, Callback>`] | Deduction guide for creating an `absl::Cleanup` from a callback. |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/MakeCleanup.adoc[`MakeCleanup`] | Create an `absl::Cleanup` from a callback. |=== == Return Value [NOTE] ==== The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^]. ==== [.small]#Created with https://www.mrdocs.com[MrDocs]#