std::inout_ptr
来自 cppreference.cn
< cpp | memory | inout ptr t
定义于头文件 <memory> |
||
template< class Pointer = void, class Smart, class... Args > auto inout_ptr( Smart& s, Args&&... args ); |
(自 C++23 起) | |
返回一个 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
应当是临时对象,在包含对外函数的调用的完整表达式的末尾销毁,以避免悬垂引用。
特性测试 宏 | 值 | Std | 特性 |
---|---|---|---|
__cpp_lib_out_ptr |
202106L |
(C++23) | std::out_ptr , std::inout_ptr |
202311L |
(C++26) | 独立式 std::out_ptr 和 std::inout_ptr |
[编辑] 示例
此章节不完整 原因:没有示例 |
[编辑] 参见
(C++23) |
创建具有关联智能指针和重置实参的 out_ptr_t (函数模板) |
(C++14)(C++20) |
创建管理新对象的 unique 指针 (函数模板) |
创建管理新对象的 shared 指针 (函数模板) |