相关:Deprecation of std::allocator<void> .
以下关于模板参数 Allocator
的描述可以在 std::vector
中找到和 std::list
(强调我的):
An allocator that is used to acquire/release memory and to construct/destroy the elements in that memory. The type must meet the requirements of Allocator. The behavior is undefined if
Allocator::value_type
is not the same asT
.
最后一句对我来说没有意义。如果需要特定的 value_type
,难道它不能重新绑定(bind)分配器吗?
最佳答案
原因主要是历史原因——在 C++11 添加 allocator_traits
之前,重新绑定(bind)更加复杂。 Networking TS定义了一个“proto-allocator”概念([async.reqmts.proto.allocator]),其中在任何使用之前总是应用重新绑定(bind),因此似乎有一天这一要求可能会放宽。
关于c++ - 为什么标准容器要求 allocator_type::value_type 是元素类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50245277/