Namespaces
Variants

std:: indirect

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 T, class Allocator = std:: allocator < T > >
class indirect ;
(1) (C++26 起)
namespace pmr {

template < class T >
using indirect = std :: indirect < T, std:: pmr :: polymorphic_allocator < T >> ;

}
(2) (C++26 起)
1) std::indirect 是一个包装器,包含具有类值语义的动态分配对象。
2) std::pmr::indirect 是一个使用 多态分配器 的别名模板。

一个 std::indirect 对象管理其所拥有对象的 生命周期 。只有在被移动后, std::indirect 对象才可能不拥有任何对象,此时它处于 无值状态

每个 std::indirect<T, Allocator> 类型的对象都会使用一个 Allocator 类型的对象,根据需要为所拥有的对象分配和释放存储空间。

如果程序声明了 std::indirect 的显式特化或部分特化,则行为是未定义的。

目录

模板参数

T - 所拥有对象的类型
Allocator - 关联分配器的类型
类型要求
-
T 可以是 不完整类型
-
T 为下列类型之一,则程序非良构:
-
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 对象
(函数模板)
特化 std::swap 算法
(函数模板)

辅助类

std::indirect 的哈希支持
(类模板特化)

推导指引

注释

功能测试 标准 功能
__cpp_lib_indirect 202502L (C++26) std::indirect

示例

另请参阅

包含具有值语义的动态分配对象的多态包装器
(类模板)
(C++11)
具有唯一对象所有权语义的智能指针
(类模板)