:relfileprefix: ../../
[#AE7FFB38E948E416C21171D6D5E3C29218BAF15E]

= Class scope_exit

pass:v,q[Scope exit guard that conditionally invokes a function upon leaving the scope.]


== Synopsis

Declared in header `<https://github.com/Lastique/scope/blob/develop/include/boost/scope/scope_exit.hpp#L151[boost/scope/scope_exit.hpp,window=blank_]>`

[source,cpp,subs="verbatim,macros,-callouts"]
----
template<
    typename Func,
    typename Cond = xref:boost/scope/always_true.adoc[always_true]>
class scope_exit;
----

==  Member Functions
[,cols=2]
|===
|Name |Description
|xref:boost/scope/scope_exit-0a/active.adoc[`pass:v[active]`] |
pass:v,q[Returns] `true` pass:v,q[if the scope guard is active, otherwise] `false.`

|xref:boost/scope/scope_exit-0a/operator_assign.adoc[`pass:v[operator=]`] |
|xref:boost/scope/scope_exit-0a/release.adoc[`pass:v[release]`] |
pass:v,q[Deactivates the scope guard.]

|xref:boost/scope/scope_exit-0a/2constructor.adoc[`pass:v[scope_exit]`] |
|xref:boost/scope/scope_exit-0a/set_active.adoc[`pass:v[set_active]`] |
pass:v,q[Activates or deactivates the scope guard.]

|xref:boost/scope/scope_exit-0a/2destructor.adoc[`pass:v[~scope_exit]`] |
pass:v,q[If `active() == true`, and invoking the condition function object returns]
`true,`
pass:v,q[invokes]
pass:v,q[the wrapped callable action function object. Destroys the function objects.]

|===

== Description

pass:v,q[The scope guard wraps two function objects: the scope guard action and]
pass:v,q[a condition for invoking the action. Both function objects must be]
pass:v,q[callable with no arguments and can be one of:]

* pass:v,q[A user-defined class with a public `operator()`.]

* pass:v,q[An lvalue reference to such class.]

* pass:v,q[An lvalue reference or pointer to function taking no arguments.]
pass:v,q[The condition function object `operator()` must return a value]
pass:v,q[contextually convertible to]
`true,`
pass:v,q[if the action function object]
pass:v,q[is allowed to be executed, and]
`false`
pass:v,q[otherwise. Additionally,]
pass:v,q[the condition function object `operator()` must not throw, as]
pass:v,q[otherwise the action function object may not be called.]
pass:v,q[The condition function object is optional, and if not specified in]
pass:v,q[template parameters, the scope guard will operate as if the condition]
pass:v,q[always returns]
`true.`
pass:v,q[The scope guard can be in either active or inactive state. By default,]
pass:v,q[the constructed scope guard is active. When active, and condition]
pass:v,q[function object returns]
`true,`
pass:v,q[the scope guard invokes the wrapped]
pass:v,q[action function object on destruction. Otherwise, the scope guard]
pass:v,q[does not call the wrapped action function object.]
pass:v,q[The scope guard can be made inactive by moving-from the scope guard]
pass:v,q[or calling `set_active(false)` or `release()`. An inactive]
pass:v,q[scope guard can be made active by calling `set_active(true)`.]
pass:v,q[If a moved-from scope guard is active on destruction, the behavior]
pass:v,q[is undefined.]



