std::experi...::scope_fail(3)
β¨ NAME β¨
okay so this page is for std::experimental::scope_fail, and the manual name up top is std::experi...::scope_fail(3). Bestie, we're getting into scope-guard territory π
πΈ Synopsis πΈ
Defined in header <experimental/scope>
template< class EF > (library fundamentals TS v3)
class scope_fail;
The class template scope_fail is a general-purpose scope guard intended to call its exit function when a scope is exited via an exception. Itβs giving βI have one job, and that job happens when things go sidewaysβ energy π
scope_fail is not CopyConstructible, CopyAssignable or MoveAssignable, however, it may be MoveConstructible if EF meets some requirements, which permits wrapping a scope_fail into another object.
A scope_fail may be either active β i.e. it calls its exit function on destruction β or inactive β i.e. it does nothing on destruction. A scope_fail is active after itβs constructed from an exit function.
A scope_fail can become inactive by calling release() on it either manually or automatically (by the move constructor). An inactive scope_fail may also be obtained by initializing with another inactive scope_fail. Once a scope_fail is inactive, it cannot become active again. No take-backs, no encore, periodt π€
A scope_fail effectively holds an EF and a bool flag indicating if it is active, along with a counter of uncaught exceptions used for detecting whether the destructor is called during stack unwinding.
π Template parameters π
EFβ type of stored exit function.
π Type requirements π
EFshall be either:- a
DestructibleFunctionObjecttype, - an lvalue reference to
FunctionObject, - an lvalue reference to function.
- a
- Calling an lvalue of
std::remove_reference_t<EF>with no argument shall be well-formed.
π¦ Member functions π¦
- constructor β constructs a new
scope_fail(public member function). - destructor β calls the exit function when the scope is exited via an exception if the
scope_failis active, then destroys thescope_fail(public member function). operator=βscope_failis not assignable β[deleted](public member function).
π Modifiers π
releaseβ makes thescope_failinactive (public member function).
π§ Deduction guides π§
The page says Deduction guides and then just leaves it there β mysterious, lowkey iconic, no extra details listed here β¨
π Notes π
Constructing a scope_fail of dynamic storage duration might lead to unexpected behavior.
Constructing a scope_fail from another scope_fail created in a different thread might also lead to unexpected behavior, since the count of uncaught exceptions obtained in different threads may be compared during the destruction.
π Example π
This section is incomplete.
Reason: no example.
π See also π
scope_exitβ wraps a function object and invokes it on exiting the scope (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
footer vibe, folded into a cute sign-off: source/version ishttp://cppreference.com, dated2024.06.10β bye bestie, stay scoped and stay slaying π«Άπ
π¦ 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