本文介绍了为什么std :: allocator在C ++ 17中丢失成员类型/函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在查看 std :: allocator 时,我看到了以下成员: value_type , 指针, const_pointer , 引用, const_reference , size_type , difference_type 和 rebind 已全部弃用。 While looking at std::allocator, I see that members:value_type,pointer,const_pointer,reference,const_reference,size_type,difference_type, andrebind have all been deprecated. 分配者也将不再具有成员: 地址, max_size ,构造或破坏。 Allocators will also no longer have the members: address, max_size, construct, or destroy. 为什么会这样? 推荐答案如果您查看相关的isocpp论文,您会发现现在想到的是您提到的第一个论文集最好放在 std :: allocator_traits 。自从STL(甚至不是标准库)问世以来,使用特征的转移就更多了。If you look at the relevant isocpp paper you can see that the first set you mention is now thought to be better placed in std::allocator_traits. Since the STL (not even standard library) came out, there's been more of a shift to use traits. 重新绑定也是遗物。首次发布STL时,不支持别名和模板模板参数。有了这些语言功能, rebind 似乎相当复杂。例如,如您在中看到的那样,在《 The C ++ Programming Language》,第4版,第34.4.1节,p 998,注释默认分配程序类中的经典重新绑定成员:rebind is also a relic. When the STL first came out, aliases and template-template parameters were not supported. With these language features in existence, rebind seems fairly convoluted. E.g., as you can see in an answer to this question, in The C++ Programming Language, 4th edition, section 34.4.1, p. 998, commenting the 'classical' rebind member in default allocator class :template<typename U> struct rebind { using other = allocator<U>;}; Bjarne Stroustupr写道:好奇的重新绑定模板是一个古老的别名。应该是:Bjarne Stroustupr writes this : "The curious rebind template is an archaic alias. It should have been:template<typename U>using other = allocator<U>;但是,分配器是在C ++支持此类别名之前定义的。 However, allocator was defined before such aliases were supported by C++."总的来说,这是赶上语言和范式转变的标准库。So, altogether, it's the standard library catching up with the language and paradigm shifts. 这篇关于为什么std :: allocator在C ++ 17中丢失成员类型/函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-10 21:53