std::experimental::scope_fail<EF>:: scope_fail
From cppreference.net
<
cpp
|
experimental
|
scope fail
|
template
<
class
Fn
>
explicit scope_fail ( Fn && fn ) noexcept ( /*see below*/ ) ; |
(1) | (基础库TS v3) |
|
scope_fail
(
scope_fail
&&
other
)
noexcept
(
/*see below*/
)
;
|
(2) | (基础库TS v3) |
|
scope_fail
(
const
scope_fail
&
)
=
delete
;
|
(3) | (基础库TS v3) |
从函数、函数对象或其他
scope_fail
创建
scope_fail
对象。
若
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_fail
>
为
false
且
std::
is_constructible_v
<
EF, Fn
>
为
true
时参与重载决议。
如果函数调用表达式
fn
(
(
)
的格式不正确,则程序是非良构的。
若调用
fn
(
)
抛出异常或导致未定义行为,则此行为是未定义的,即使
fn
尚未被调用。
2)
移动构造函数。使用
other
中的存储
EF
进行初始化,并使用
other
中的未捕获异常计数器进行初始化。构造的
scope_fail
在且仅在
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
时参与重载决议。
以下情况行为未定义:
-
当
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 & > )
std:: is_nothrow_constructible_v < EF, Fn & > )
2)
noexcept
规范:
noexcept
(
std::
is_nothrow_move_constructible_v
<
EF
>
||
std:: is_nothrow_copy_constructible_v < EF > )
std:: is_nothrow_copy_constructible_v < EF > )
示例
|
本节内容不完整
原因:缺少示例 |
参见
|
(
C++17中弃用*
)
(C++17)
|
检查异常处理是否正在进行中
(函数) |
使
scope_fail
变为非活跃状态
(公开成员函数) |