Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::scope_exit<EF>::scope_exit

      From cppreference.com
      <cpp‎ |experimental‎ |scope exit

      [edit template]
       
       
       
       
       
      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)

      Creates ascope_exit from a function, a function object or anotherscope_exit.

      1) Initializes the exit function with a function or function object. The constructedscope_exit is active.
      IfFn is not an lvalue reference type andstd::is_nothrow_constructible_v<EF, Fn> istrue, the storedEF is initialized withstd::forward<Fn>(fn); otherwise it is initialized withfn.
      If initialization of the storedEF throws an exception, callsfn().
      This overload participates in overload resolution only ifstd::is_same_v<std::remove_cvref_t<Fn>, scope_exit> isfalse andstd::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 iffn has not been called.
      2) Move constructor. Initializes the storedEF with the one inother. The constructedscope_exit is active if and only ifother is 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 andother becomes inactive.
      This overload participates in overload resolution only ifstd::is_nothrow_move_constructible_v<EF> istrue orstd::is_copy_constructible_v<EF> istrue.
      The behavior is undefined if
      3)scope_exit is notCopyConstructible.

      Contents

      [edit]Parameters

      fn - function or function object used for initializing the storedEF
      other -scope_exit to move from

      [edit]Exceptions

      Any exception thrown during the initialization of the storedEF.

      1)
      noexcept specification:  
      noexcept(std::is_nothrow_constructible_v<EF, Fn>||
               std::is_nothrow_constructible_v<EF, Fn&>)
      2)

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      makes thescope_exit inactive
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/scope_exit/scope_exit&oldid=115129"

      [8]ページ先頭

      ©2009-2026 Movatter.jp