[#BloombergLP-bdlb-ScopeExit-0e] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlb.adoc[bdlb]::ScopeExit :relfileprefix: ../../ :mrdocs: Scope proctor that invokes an exit function when destroyed. == Synopsis Declared in `<bdlb_scopeexit.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class EXIT_FUNC> class [[nodiscard]] ScopeExit; ---- == Description `ScopeExit` is a general‐purpose scope proctor class template that is intended to be used as an automatic (stack) variable that calls an exit function upon its destruction (when its scope is exited). The template argument `EXIT_FUNC` shall be a function object type, or a pointer to a function. If `EXIT_FUNC` is an object type, it shall satisfy the requirements of _Destructible_, _Callable_, and _MoveConstructible_ as specified by the ISO C++ standard. Note that to fulfill the _MoveConstructible_ constraint a type does not have to implement a move constructor. If it has a copy constructor, that will work fine as long at the move constructor is not deleted (or in case of C++03 emulated moves, `private`). The behavior is undefined if calling (the member instance of) `EXIT_FUNC` throws an exception (as it will be called from the destructor). == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlb/ScopeExit-0e/2constructor-0a.adoc[`ScopeExit`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bdlb/ScopeExit-0e/2destructor.adoc[`~ScopeExit`] [.small]#[destructor]# | Destroy this object. Execute the exit function unless `release()` has been called on this object. | xref:BloombergLP/bdlb/ScopeExit-0e/release.adoc[`release`] | Turn off the execution of the exit function of this object on destruction. |=== == Deduction Guides [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlb/ScopeExit-09.adoc[`ScopeExit<bsl::decay<EXIT_FUNC_PARAM>::type>`] | Deduce the template parameter `EXIT_FUNC` from the type of the callable passed to the constructor of `ScopeExit`. |=== == 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]#