[#BloombergLP-bdlb-ScopeExit-0e]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlb.adoc[bdlb]::ScopeExit
:relfileprefix: ../../
:mrdocs:

`ScopeExit` is a general&hyphen;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)&period;

== Synopsis

Declared in `&lt;bdlb&lowbar;scopeexit&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class EXIT&lowbar;FUNC&gt;
class &lsqb;&lsqb;nodiscard&rsqb;&rsqb; ScopeExit;
----

== Description

The template argument `EXIT&lowbar;FUNC` shall be a function object type, or a pointer to a function&period; If `EXIT&lowbar;FUNC` is an object type, it shall satisfy the requirements of _Destructible_, _Callable_, and _MoveConstructible_ as specified by the ISO C&plus;&plus; standard&period; Note that to fulfill the _MoveConstructible_ constraint a type does not have to implement a move constructor&period; If it has a copy constructor, that will work fine as long at the move constructor is not deleted (or in case of C&plus;&plus;03 emulated moves, `private`)&period; The behavior is undefined if calling (the member instance of) `EXIT&lowbar;FUNC` throws an exception (as it will be called from the destructor)&period;

== 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[`&#126;ScopeExit`] [.small]#[destructor]#
| Destroy this object&period; Execute the exit function unless `release()` has been called on this object&period;
| xref:BloombergLP/bdlb/ScopeExit-0e/release.adoc[`release`] 
| Turn off the execution of the exit function of this object on destruction&period;
|===


== Deduction Guides

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlb/ScopeExit-09.adoc[`ScopeExit&lt;bsl::decay&lt;EXIT&lowbar;FUNC&lowbar;PARAM&gt;::type&gt;`] 
| Deduce the template parameter `EXIT&lowbar;FUNC` from the type of the callable passed to the constructor of `ScopeExit`&period;
|===


== 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]#
