std::experi...::scope_exit(3)
πΈ NAME πΈ
std::experimental::scope_exit::scope_exit β the constructors, bestie. This page lives in the C++ Standard Libary manual under the very abbreviated title std::experi...::scope_exit(3) (and yes, βLibaryβ is literally spelled like that there π keep it).
β¨ Synopsis β¨
template< class Fn >
explicit scope_exit( Fn&& fn ) noexcept(/*see below*/); (1) (library fundamentals TS v3)
scope_exit( scope_exit&& other ) noexcept(/*see below*/); (2) (library fundamentals TS v3)
scope_exit( const scope_exit& ) = delete; (3) (library fundamentals TS v3)
Okay so this is all about creating a scope_exit from a function, a function object, or another scope_exit. Thatβs the whole plot π
scope_exit( Fn&& fn )β Initializes the exit function with a function or function object. The constructedscope_exitis active. IfFnis not an lvalue reference type andstd::is_nothrow_constructible_v<EF, Fn>istrue, the storedEFis initialized withstd::forward<Fn>(fn); otherwise it is initialized withfn. If initialization of the storedEFthrows an exception, callsfn(). This overload participates in overload resolution only ifstd::is_same_v<std::remove_cvref_t<Fn>, scope_exit>isfalseandstd::is_constructible_v<EF, Fn>istrue. The program is ill-formed if function call expressionfn()is ill-formed. The behavior is undefined if callingfn()throws an exception or results in undefined behavior, even iffnhas not been called.- Move constructor β Initializes the stored
EFwith the one inother. The constructedscope_exitis active if and only ifotheris active before the construction. Ifstd::is_nothrow_move_constructible_v<EF>istrue, initializes storedEF(denoted byexitfun) withstd::forward<EF>(other.exitfun), otherwise initializes it withother.exitfun. After successful move construction,other.release()is called andotherbecomes inactive. This overload participates in overload resolution only ifstd::is_nothrow_move_constructible_v<EF>istrueorstd::is_copy_constructible_v<EF>istrue. The behavior is undefined if:std::is_nothrow_move_constructible_v<EF>istrueandEFdoes not meet the requirements ofMoveConstructible, orstd::is_nothrow_move_constructible_v<EF>isfalseandEFdoes not meet the requirements ofCopyConstructible.
- Copy constructor is deleted β
scope_exitis notCopyConstructible. Periodt π
π Parameters π
fnβ function or function object used for initializing the storedEFotherβscope_exitto move from
π Exceptions π
Any exception thrown during the initialization of the stored EF. Thatβs the exception mood, no cap π
1) noexcept specification:
noexcept(std::is_nothrow_constructible_v<EF, Fn> ||
std::is_nothrow_constructible_v<EF, Fn&>)
2) noexcept specification:
noexcept(std::is_nothrow_move_constructible_v<EF> ||
std::is_nothrow_copy_constructible_v<EF>)
π¦ Example π¦
This section is incomplete Reason: no example
Not me being left with no example to vibe with π
π See also π
releaseβ makes thescope_exitinactive (public member function)
π Categories π
- conditionally noexcept
- Todo no example
okay thatβs the whole page, bestie π source/version + date time: http://cppreference.com Β· 2024.06.10 Β· this page: std::experi...::scope_exit(3) β slay and goodbye β¨π«Ά
π¦ 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