std::indirect
来自cppreference.com
| 在标头 <memory> 定义
|
||
| template< class T, class Allocator = std::allocator<T> > class indirect; |
(1) | |
| namespace pmr { template< class T > |
(2) | |
1)
std::indirect 是包含动态分配的对象的具有类值语义的包装器。std::indirect 对象管理拥有的对象的生存期。std::indirect 对象只有在被移动后才会不拥有对象,此时该 std::indirect 对象无值。
每个 std::indirect<T, Allocator> 类型对象都会使用一个 Allocator 对象来分配和释放拥有的对象所需的存储。
如果程序声明了 std::indirect 的显式特化或部分特化,那么行为未定义。
模板形参
| T | - | 拥有的对象的类型 |
| Allocator | - | 关联的分配器的类型 |
| 类型要求 | ||
-T 可以是不完整类型。
| ||
-如果 T 是以下类型之一,那么程序非良构:
| ||
-如果 Allocator 不满足分配器 (Allocator) 的要求,那么程序非良构。
| ||
-如果 std::allocator_traits<Allocator>::value_type 与 T 不同,那么程序非良构。
| ||
嵌套类型
| 类型 | 定义 |
value_type
|
T
|
allocator_type
|
Allocator
|
pointer
|
typename std::allocator_traits<Allocator>::pointer |
const_pointer
|
typename std::allocator_traits<Allocator>::const_pointer |
数据成员
| 成员 | 描述 |
pointer p
|
指向拥有的值的指针 (仅用于阐述的成员对象*) |
Allocator alloc
|
关联的分配器 (仅用于阐述的成员对象*) |
成员函数
构造 indirect 对象 (公开成员函数) | |
| 销毁拥有的值(如果存在) (公开成员函数) | |
| 对内容赋值 (公开成员函数) | |
观察器 | |
| 访问拥有的值 (公开成员函数) | |
检查 indirect 是否无值 (公开成员函数) | |
| 返回关联的分配器 (公开成员函数) | |
修改器 | |
| 交换内容 (公开成员函数) | |
非成员函数
| (C++26)(C++26) |
比较 indirect 对象 (函数模板) |
| (C++26) |
特化 std::swap 算法 (函数模板) |
辅助类
| (C++26) |
std::indirect 的散列支持 (类模板特化) |
推导指引
注解
| 功能特性测试宏 | 值 | 标准 | 功能特性 |
|---|---|---|---|
__cpp_lib_indirect |
202502L |
(C++26) | std::indirect
|
示例
| 本节未完成 原因:暂无示例 |
参阅
| (C++26) |
包含动态分配对象的带有类似值语义的多态包装器 (类模板) |