std::inout_ptr
来自cppreference.com
< 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 应为在含有外来函数调用的全表达式结尾销毁的临时对象,以避免悬垂引用。
| 功能特性测试宏 | 值 | 标准 | 功能特性 |
|---|---|---|---|
__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) |
创建管理一个新对象的独占指针 (函数模板) |
| 创建管理一个新对象的共享指针 (函数模板) |