std::experi...::scope_exit(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 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 πŸŽ€

  1. scope_exit( Fn&& fn ) β€” Initializes the exit function with a function or function object. The constructed scope_exit is active. If Fn is not an lvalue reference type and std::is_nothrow_constructible_v<EF, Fn> is true, the stored EF is initialized with std::forward<Fn>(fn); otherwise it is initialized with fn. If initialization of the stored EF throws an exception, calls fn(). This overload participates in overload resolution only if std::is_same_v<std::remove_cvref_t<Fn>, scope_exit> is false and std::is_constructible_v<EF, Fn> is true. The program is ill-formed if function call expression fn() is ill-formed. The behavior is undefined if calling fn() throws an exception or results in undefined behavior, even if fn has not been called.
  2. Move constructor β€” Initializes the stored EF with the one in other. The constructed scope_exit is active if and only if other is active before the construction. If std::is_nothrow_move_constructible_v<EF> is true, initializes stored EF (denoted by exitfun) with std::forward<EF>(other.exitfun), otherwise initializes it with other.exitfun. After successful move construction, other.release() is called and other becomes inactive. This overload participates in overload resolution only if std::is_nothrow_move_constructible_v<EF> is true or std::is_copy_constructible_v<EF> is true. The behavior is undefined if:
    • std::is_nothrow_move_constructible_v<EF> is true and EF does not meet the requirements of MoveConstructible, or
    • std::is_nothrow_move_constructible_v<EF> is false and EF does not meet the requirements of CopyConstructible.
  3. Copy constructor is deleted β€” scope_exit is not CopyConstructible. Periodt πŸ’…

πŸŽ€ Parameters πŸŽ€

  • fn β€” function or function object used for initializing the stored EF
  • other β€” scope_exit to 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 the scope_exit inactive (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