std::out_ptr
定义于头文件 <memory>
。
C++23
template< class Pointer = void, class Smart, class... Args >
auto out_ptr( Smart& s, Args&&... args );
返回一个具有推导出的模板参数的 out_ptr_t,它会捕获用于通过引用重置的参数。
如果返回值(见下文)的构造是格式错误的,则程序格式错误。
参数
s
- 要适配的对象(通常是智能指针)args...
- 用于重置以捕获的参数
返回值
std::out_ptr_t<Smart, P, Args&&>(s, std::forward<Args>(args)...)
,其中 P
是
Pointer
,如果Pointer
与void
不同,- 否则,
Smart::pointer
,如果它是有效的并表示一个类型, - 否则,
Smart::element_type*
,如果Smart::element_type
是有效的并表示一个类型, - 否则,
std::pointer_traits<Smart>::element_type*
。
备注
用户可以为模板参数 Pointer
指定模板参数,以便与接受 Pointer*
的外部函数进行互操作。
由于所有用于重置的参数都是通过引用捕获的,因此返回的 out_ptr_t 应该是临时对象,在包含外部函数调用的完整表达式结束时销毁,以避免悬空引用。
特性测试宏 | 值 | 标准 |
---|---|---|
__cpp_lib_out_ptr | 202106L | (C++23) |