一边看着std::分配器 http://en.cppreference.com/w/cpp/memory/allocator,我看到成员:
value_type
,
pointer
,
const_pointer
,
reference
,
const_reference
,
size_type
,
difference_type
, and
rebind
已全部被弃用。
分配者也将不再拥有以下成员:
address
, max_size
, construct
, or destroy
.
为什么会发生这种情况?它与多态分配器有关吗?
如果你看相关的 isocpp 论文 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0174r1.html#2.2您可以看到您提到的第一组现在被认为更适合放置在std::allocator_traits http://en.cppreference.com/w/cpp/memory/allocator_traits。自从 STL(甚至不是标准库)问世以来,使用特征的转变发生了更多。
rebind
也是遗迹。当STL刚出来的时候,不支持别名和模板-模板参数。有了这些语言特征的存在,rebind
看起来相当复杂。例如,正如您所见这个问题的答案 https://stackoverflow.com/questions/12362363/why-is-allocatorrebind-necessary-when-we-have-template-template-parameters,《C++ 编程语言》,第 4 版,第 34.4.1 节,第 14 页。 998,评论默认分配器类中的“经典”重新绑定成员:
template<typename U>
struct rebind { using other = allocator<U>;};
Bjarne Stroustupr 写道:“奇怪的重新绑定模板是一个古老的别名。它应该是:
template<typename U>
using other = allocator<U>;
然而,分配器是在 C++ 支持此类别名之前定义的。”
因此,总的来说,标准库正在赶上语言和范式的转变。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)