std::experimental::unique_resource<R, D>:: unique_resource
|
unique_resource
(
)
;
|
(1) | (库基础技术规范 v3) |
|
template
<
class
RR,
class
DD
>
unique_resource ( RR && r, DD && d ) noexcept ( /*见下文*/ ) |
(2) | (库基础技术规范 v3) |
|
unique_resource
(
unique_resource
&&
other
)
;
|
(3) | (库基础技术规范 v3) |
以下项目用于说明目的:
-
RS是存储资源句柄的类型。 - 表达式 res_ 指向底层资源句柄。
-
del_指向删除器对象。
unique_resource
不拥有该资源。
随后,删除器将使用 std:: forward < DD > ( d ) 进行初始化(当 std:: is_nothrow_constructible_v < D, DD > 为 true 时),否则使用 d 。若删除器的初始化抛出异常,则调用 d ( res_ ) 。
构造完成的
unique_resource
拥有该资源的所有权。
std::move
从
other
的句柄初始化(当
std::
is_nothrow_move_constructible_v
<
RS
>
为
true
时)。若存储资源句柄的初始化抛出异常,则
other
保持不变。
随后,删除器使用
std::move
从
other
的删除器初始化(当
std::
is_nothrow_move_constructible_v
<
D
>
为
true
时)。若删除器初始化抛出异常,且
std::
is_nothrow_move_constructible_v
<
RS
>
为
true
且
other
拥有资源,则调用
other
的删除器并传入
res_
以释放资源,随后调用
other.
release
(
)
。
构造完成后,若 other 在构造前拥有资源,则构造的
unique_resource
拥有该资源,同时
other
被设置为不拥有资源。
目录 |
参数
| r | - | 资源句柄 |
| d | - | 用于释放资源的删除器 |
| other | - |
要从中获取所有权的另一个
unique_resource
|
异常
在存储资源句柄或删除器初始化期间抛出的任何异常。
std::
is_nothrow_constructible_v
<
RS, RR
>
||
std::
is_nothrow_constructible_v
<
RS, RR
&
>
)
&&
(
std::
is_nothrow_constructible_v
<
D, DD
>
||
std::
is_nothrow_constructible_v
<
D, DD
&
>
std::
is_nothrow_move_constructible_v
<
R1
>
&&
std::
is_nothrow_move_constructible_v
<
D
>
注释
这些构造函数的机制确保资源不会泄漏。
示例
|
本节内容不完整
原因:缺少示例 |
参见
构造新的
unique_ptr
(
std::unique_ptr<T,Deleter>
的公开成员函数)
|