Namespaces
Variants

std::experimental::scope_exit

From cppreference.com
 
 
Experimental
Technical Specification
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
Experimental Non-TS
Pattern Matching
Linear Algebra
std::execution
Contracts
2D Graphics
 
 
 
Defined in header <experimental/scope>
template< class EF >
class scope_exit;
(library fundamentals TS v3)

The class template scope_exit is a general-purpose scope guard intended to call its exit function when a scope is exited.

scope_exit is not CopyConstructible, CopyAssignable or MoveAssignable, however, it may be MoveConstructible if EF meets some requirements, which permits wrapping a scope_exit into another object.

A scope_exit may be either active, i.e. calls its exit function on destruction, or inactive, i.e. does nothing on destruction. A scope_exit is active after constructed from an exit function.

A scope_exit can become inactive by calling release() on it either manually or automatically (by the move constructor). An inactive scope_exit may also be obtained by initializing with another inactive scope_exit. Once a scope_exit is inactive, it cannot become active again.

A scope_exit effectively holds an EF and a bool flag indicating if it is active.

Template parameters

EF - type of stored exit function
Type requirements
-
EF shall be either:
-
Calling an lvalue of std::remove_reference_t<EF> with no argument shall be well-formed.

Member functions

constructs a new scope_exit
(public member function) [edit]
calls the exit function when the scope is exited if the scope_exit is active, then destroys the scope_exit