Namespaces
Variants

std:: allocation_result

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, class SizeType = std:: size_t >
struct allocation_result ;
(C++23 起)

allocation_result 特化由相应 Allocator 类型(例如 std::allocator::allocate_at_least )及 std::allocator_traits::allocate_at_least allocate_at_least 成员函数返回。

每个 allocation_result 的特化版本除了 ptr count 外没有基类或声明其他成员,因此它适用于 聚合初始化 结构化绑定

目录

模板参数

Pointer - 通常为 std:: allocator_traits < Alloc > :: pointer ,其中 Alloc Allocator 类型
SizeType - 通常为 std:: allocator_traits < Alloc > :: size_type ,其中 Alloc Allocator 类型

数据成员

成员名称 定义
ptr
类型为 Pointer 的指针,通常指向由 allocate_at_least 分配的存储空间中首个元素的地址
(公开成员对象)
count
类型为 SizeType 的值,通常表示由 allocate_at_least 分配的存储空间中实际元素数量
(公开成员对象)

注释

Pointer SizeType 分别默认为对象类型的指针和 std:: make_unsigned_t < std:: ptrdiff_t > (该类型几乎总是与 std::size_t 相同)。

功能测试 标准 功能特性
__cpp_lib_allocate_at_least 202302L (C++23) 分配器接口中的尺寸反馈机制

示例

另请参阅

分配至少与请求大小相等的未初始化存储
( std::allocator<T> 的公开成员函数)
[静态] (C++23)
通过分配器分配至少与请求大小相等的存储
( std::allocator_traits<Alloc> 的公开静态成员函数)