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

Create a `ScopeExit` that will invoke `function` on destruction&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class EXIT&lowbar;FUNC&lowbar;PARAM&gt;
explicit
ScopeExit(EXIT&lowbar;FUNC&lowbar;PARAM&& function)
requires bsl&colon;&colon;is&lowbar;constructible&lt;  &sol;&sol; Copy construct
            EXIT&lowbar;FUNC,
            const typename MoveUtil&colon;&colon;Decay&lt;EXIT&lowbar;FUNC&lowbar;PARAM&gt;&colon;&colon;type&amp;
        &gt;&colon;&colon;value                                                             &verbar;&verbar;
        bsl&colon;&colon;is&lowbar;constructible&lt;  &sol;&sol; Move construct
            EXIT&lowbar;FUNC,
            bslmf&colon;&colon;MovableRef&lt;typename MoveUtil&colon;&colon;Decay&lt;EXIT&lowbar;FUNC&lowbar;PARAM&gt;&colon;&colon;type&gt;
        &gt;&colon;&colon;value;
----

== Description

Create a `ScopeExit` object, which, upon its destruction will invoke the specified `function` (or functor) unless its `release` method was called&period; If `function` is copied into the `EXIT&lowbar;FUNC` member, and that copy throws an exception, invoke `function` and rethrow the exception&period; If `EXIT&lowbar;FUNC&lowbar;PARAM` cannot be move converted to `EXIT&lowbar;FUNC` via no&hyphen;throw means (either because such conversion does not exist or it is not marked as non&hyphen;throwing), `function` will always be copied into the member&period; This constructor participates in overload resolution only if `EXIT&lowbar;FUNC&lowbar;PARAM` is neither `EXIT&lowbar;FUNC` nor `bdlb&colon;&colon;ScopeExit&lt;EXIT&lowbar;FUNC&gt;` and `EXIT&lowbar;FUNC&lowbar;PARAM` is convertible to `EXIT&lowbar;FUNC`&period; The behavior is undefined if `function` or the member instance of `EXIT&lowbar;FUNC` throws an exception upon invocation&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *function*
| exit function or functor invoked on destruction unless `release` is called
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
