[英]Why do standard containers require allocator_type::value_type to be the element type?
Related: Deprecation of std::allocator<void> . 相关: std :: allocator <void>的弃用 。
The following description about template parameter Allocator
is found for both std::vector
and std::list
(emphasis mine): 对于std::vector
和std::list
(强调我的),可以找到关于模板参数Allocator
的以下描述:
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
. 如果Allocator::value_type
与T
不同,则行为未定义 。
The last sentence does not make sense to me. 最后一句话对我没有意义。 If a specific value_type
is required, couldn't it just do an allocator rebind? 如果需要特定的value_type
,那么它不能只重新分配一个分配器吗?
The reason is mostly historical—rebinding was more complicated before C++11 added allocator_traits
. 原因主要是历史 - 重新绑定在C ++ 11添加allocator_traits
之前更加复杂。 The Networking TS defines a “proto-allocator” concept ([async.reqmts.proto.allocator]) where rebinding is always applied before any use, so it seems likely that the requirement will be relaxed someday. Networking TS定义了一个“proto-allocator”概念([async.reqmts.proto.allocator]),其中重新绑定总是在任何使用之前应用,因此似乎有一天需要放宽该要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.