Namespaces
Variants

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

From cppreference.net

template < class Fn >
explicit scope_exit ( Fn && fn ) noexcept ( /*see below*/ ) ;
(1) (基础库TS v3)
scope_exit ( scope_exit && other ) noexcept ( /*see below*/ ) ;
(2) (基础库TS v3)
scope_exit ( const scope_exit & ) = delete ;
(3) (基础库TS v3)

从函数、函数对象或其他 scope_exit 创建一个 scope_exit 对象。

1) 使用函数或函数对象初始化退出函数。构造的 scope_exit 处于活动状态。
Fn 非左值引用类型且 std:: is_nothrow_constructible_v < EF, Fn > true ,则存储的 EF std:: forward < Fn > ( fn ) 初始化;否则以 fn 初始化。
如果存储的 EF 初始化过程抛出异常,则调用 fn ( )
此重载仅当 std:: is_same_v < std:: remove_cvref_t < Fn > , scope_exit > false std:: is_constructible_v < EF, Fn > true 时参与重载决议。
如果函数调用表达式 fn ( ) 不符合规范,则程序格式错误。
若调用 fn ( ) 抛出异常或导致未定义行为,则此行为是未定义的,即使 fn 尚未被调用。
2) 移动构造函数。使用 other 中的存储 EF 进行初始化。构造后的 scope_exit 是否处于活动状态,取决于构造前 other 是否处于活动状态。
std:: is_nothrow_move_constructible_v < EF > true ,则使用 std:: forward < EF > ( other. exitfun ) 初始化存储的 EF (记为 exitfun ),否则使用 other. exitfun 进行初始化。
成功进行移动构造后,将调用 other. release ( ) other 变为非活动状态。
此重载仅当 std:: is_nothrow_move_constructible_v < EF > true std:: is_copy_constructible_v < EF > true 时参与重载决议。
以下情况行为未定义:
3) scope_exit 不满足 CopyConstructible 要求。

目录

参数

fn - 用于初始化存储的 EF 的函数或函数对象
other - 要移动来源的 scope_exit 对象

异常

在存储的 EF 初始化期间抛出的任何异常。

示例

参见

使 scope_exit 变为非活动状态
(公开成员函数)