std::generator<Ref,V,Allocator>::promise_type::operator new
来自cppreference.com
< cpp | coroutine | generator | promise type
| void* operator new( std::size_t size ) requires std::same_as<Allocator, void> || |
(1) | (C++23 起) |
template< class Alloc, class... Args > void* operator new( std::size_t size, std::allocator_arg_t, |
(2) | (C++23 起) |
| template< class This, class Alloc, class... Args > void* operator new( std::size_t size, const This&, std::allocator_arg_t, |
(3) | (C++23 起) |
使用默认或用户提供的分配器分配 size 个字节的未初始化存储。
令 A 为
-
Allocator,若其并非 void, -
Alloc对于 (2,3), - 否则为 std::allocator<void>。
令 B 为 std::allocator_traits<A>::template rebind_alloc<U>,其中 U 为一种大小和对齐均为 __STDCPP_DEFAULT_NEW_ALIGNMENT__ 的未指明类型。
以如下方式初始化一个 B 类型的分配器 b:
1) A(),
2,3) A(alloc)。
使用 b 来分配足以为以下内容提供存储的最小的 U 数组的存储:大小为 size 的协程状态,和为确保 operator delete 可以于此后用等于 b 的分配器解分配此内存块所需的未指明的额外状态。
除非 std::allocator_traits<B>::pointer 是指针类型,且对于重载 (2,3),std::same_as<Allocator, void> || std::convertible_to<const Alloc&, Allocator> 得以实现,否则程序非良构。
目录 |
[编辑] 参数
| size | - | 要分配存储的大小 |
| alloc | - | 用户提供的 Alloc 类型的分配器
|
[编辑] 返回值
指向已分配存储的指针。
[编辑] 异常
1-3) 可能抛出。
[编辑] 缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| 缺陷报告 | 应用于 | 出版时的行为 | 正确行为 |
|---|---|---|---|
| LWG 3900 | C++23 | 重载 (2,3) 收到 Alloc 转换为 Allocator 的约束
|
强制要求 |