Namespaces
Variants

std:: inout_ptr

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)
定义于头文件 <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
(函数模板)
创建管理新对象的唯一指针
(函数模板)
创建管理新对象的共享指针
(函数模板)