std::experi...::scope_exit(3)
π std::experimental::scope_exit π
Okay bestie, this is the std::experi...::scope_exit(3) page from the C++ Standard Libary (that's how the header spells it, keeping the lore π) β and it's giving tiny scope guard with main character energy β¨.
πΈ NAME πΈ
std::experimental::scope_exit β std::experimental::scope_exit
β¨ Synopsis β¨
Defined in header <experimental/scope>.
template< class EF > (library fundamentals TS v3)
class scope_exit;
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 π
EFshall be either:- a Destructible FunctionObject type,
- an lvalue reference to FunctionObject,
- an lvalue reference to function.
- Calling an lvalue of
std::remove_reference_t<EF>with no argument shall be well-formed.
π Member functions π
- constructor β constructs a new
scope_exit(public member function) - destructor β calls the exit function when the scope is exited if the
scope_exitis active, then destroys thescope_exit(public member function) operator=βscope_exitis not assignable[deleted](public member function)
π Modifiers π
releaseβ makes thescope_exitinactive (public member function)
π§ Deduction guides π§
π₯ Notes π₯
Constructing a scope_exit of dynamic storage duration might lead to unexpected behavior.
If the EF stored in a scope_exit object refers to a local variable of the function where it is defined, e.g., as a lambda capturing the variable by reference, and that variable is used as a return operand in that function, that variable might have already been returned when the scope_exit's destructor executes, calling the exit function. This can lead to surprising behavior. π
π Example π
This section is incomplete Reason: no example
β See also β
scope_failβ wraps a function object and invokes it on exiting the scope through an exception (class template)scope_successβ wraps a function object and invokes it on exiting the scope normally (class template)default_deleteβ default deleter forunique_ptr(C++11) (class template)
π¦ Category π¦
- Todo no example
And that's the whole page, bestie! π«Ά Source: http://cppreference.com, version/date: 2024.06.10, page: std::experi...::scope_exit(3). Periodt. π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms