std::inout_ptr
定义于头文件 <memory>
。
C++23
template< class Pointer = void, class Smart, class... Args >
auto inout_ptr( Smart& s, Args&&... args );
返回一个具有推导模板参数的 inout_ptr_t,该 inout_ptr_t 以引用方式捕获重置参数。
如果返回值的构造(见下文)格式不正确,则程序格式不正确。
参数
s
- 要适配的对象(通常是智能指针)args...
- 要捕获的重置参数
返回值
std::inout_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*
的外部函数进行互操作。
由于所有重置参数都以引用方式捕获,因此返回的 inout_ptr_t 应该是一个在包含对外部函数的调用的完整表达式结束时销毁的临时对象,以避免悬空引用。
特性测试宏 | 值 | 标准 |
---|---|---|
__cpp_lib_inout_ptr | 202106L | (C++23) |