Namespaces
Variants

std::out_ptr_t<Smart,Pointer,Args...>:: out_ptr_t

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
explicit out_ptr_t ( Smart & sp, Args... args ) ;
(1) (自 C++23 起)
out_ptr_t ( const out_ptr_t & ) = delete ;
(2) (自 C++23 起)
1) 创建 out_ptr_t 对象。适配 sp 时将其绑定到 Smart & 成员,捕获 args... 中的每个参数 t 时,使用 std:: forward < T > ( t ) 初始化 Args... 中对应类型 T 的成员,然后对存储的 Pointer 进行值初始化。
随后若表达式合法则调用 sp. reset ( ) ;否则当 std:: is_default_constructible_v < Smart > true 时调用 sp = Smart ( ) 。若两种重置操作均不合法,则程序非良构。
2) 复制构造函数被显式删除。 out_ptr_t 既不可复制也不可移动。

目录

参数

sp - 要适配的对象(通常为智能指针)
args... - 用于重置捕获的参数

返回值

(无)

异常

可能抛出实现定义的异常。

注释

构造完成后,通过任一转换函数返回的 Pointer void * 对象所指向的值等于 nullptr

如果 args... 中的参数是对象类型,则会将其移动至所创建的 out_ptr_t 中;如果是引用类型,则会按原样转移至所创建的 out_ptr_t 中。

out_ptr_t 的构造函数允许抛出异常。例如,当 sp std::shared_ptr 时,新控制块的内存分配可能在构造函数内执行,而非在析构函数中执行。

示例