std::experimental::scope_fail<EF>::scope_fail
来自cppreference.com
<tbody>
</tbody>
template< class Fn > explicit scope_fail( Fn&& fn ) noexcept(/* 见下文 */); |
(1) | (库基础 TS v3) |
scope_fail( scope_fail&& other ) noexcept(/* 见下文 */); |
(2) | (库基础 TS v3) |
scope_fail( const scope_fail& ) = delete; |
(3) | (库基础 TS v3) |
从函数、函数对象或另一 scope_fail 创建 scope_fail。
1) 以函数或函数对象初始化退出函数,并如同以
std::uncaught_exceptions() 初始化未捕捉异常计数。构造的 scope_fail 为活跃。 若
Fn 不是左值引用类型且 std::is_nothrow_constructible_v<EF, Fn> 为 true,则以 std::forward<Fn>(fn),否则以 fn 初始化存储的 EF。 若初始化存储的
EF 时抛出了异常,则调用 fn()。 此重载只有在
std::is_same_v<std::remove_cvref_t<Fn>, scope_fail> 为 false 且 std::is_constructible_v<EF, Fn> 为 true 时才会参与重载决议。 若函数调用表达式
fn() 非良构,则程序非良构。 若调用
fn() 抛出异常或导致未定义行为,则行为未定义,即使未调用 fn。2) 移动构造函数。以
other 的存储的 EF 初始化存储的 EF,并以 other 的未捕捉异常计数初始化未捕捉异常计数。当且仅当 other 在构造前活跃,构造的 scope_fail 活跃。 若
std::is_nothrow_move_constructible_v<EF> 为 true,则以 std::forward<EF>(other.exitfun),否则以 other.exitfun 初始化存储的 EF(以 exitfun 代表)。 在成功移动构造后调用
other.release() 而 other 变为不活跃。 此重载只有在
std::is_nothrow_move_constructible_v<EF> 为 true 或 std::is_copy_constructible_v<EF> 为 true 时才会参与重载决议。 若有下列情况则行为未定义
std::is_nothrow_move_constructible_v<EF>为true而EF不满足可移动构造 (MoveConstructible) 的要求,或std::is_nothrow_move_constructible_v<EF>为false而EF不满足可复制构造 (CopyConstructible) 的要求。
参数
| fn | - | 用于初始化存储的 EF 的函数或函数对象
|
| other | - | 要移动的 scope_fail
|
异常
初始化存储的 EF 期间抛出的任何异常。
1)
noexcept 说明:
noexcept(std::is_nothrow_constructible_v<EF, Fn> || std::is_nothrow_constructible_v<EF, Fn&>)2)
noexcept 说明:
noexcept(std::is_nothrow_move_constructible_v<EF> || std::is_nothrow_copy_constructible_v<EF>)示例
| 本节未完成 原因:暂无示例 |
参阅
(C++20 中移除*)(C++17) |
检查当前是否正在进行异常处理 (函数) |
使 scope_fail 不活跃 (公开成员函数) |