为什么 std::allocator_traits 没有函数 `address`
Why does std::allocator_traits not have function `address`
std::allocator_traits
有 allocate
、deallocate
、construct
、destroy
和 max_size
,但没有 address
。
- 为什么不呢?
- 如果始终使用
std::addressof
是安全的,为什么 std::allocator
支持 address
?
std::allocator::address
已成为 std::allocator
的一部分,因为该类型已存在于标准中,但在 C++17 中已弃用并在 C++20 中删除。 allocator_traits
由 N2982: "Allocators post Removal of C++ Concepts (Rev 1) 添加到 C++11。该论文从分配器要求中删除了 address
并指出:
The functionality of address
is now provided by the pointer_to
function in pointer_traits
.
std::allocator_traits
有 allocate
、deallocate
、construct
、destroy
和 max_size
,但没有 address
。
- 为什么不呢?
- 如果始终使用
std::addressof
是安全的,为什么std::allocator
支持address
?
std::allocator::address
已成为 std::allocator
的一部分,因为该类型已存在于标准中,但在 C++17 中已弃用并在 C++20 中删除。 allocator_traits
由 N2982: "Allocators post Removal of C++ Concepts (Rev 1) 添加到 C++11。该论文从分配器要求中删除了 address
并指出:
The functionality of
address
is now provided by thepointer_to
function inpointer_traits
.