Why did std::allocator lose member types/functions in C++17?

前端 未结 1 1446
暖寄归人
暖寄归人 2021-02-18 15:48

While looking at std::allocator, I see that members:
value_type, pointer, const_pointer, reference, const_reference

1条回答
  •  失恋的感觉
    2021-02-18 16:27

    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.

    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
         struct rebind { using other = allocator;};
    

    Bjarne Stroustupr writes this : "The curious rebind template is an archaic alias. It should have been:

    template
    using other = allocator;
    

    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.

    0 讨论(0)
提交回复
热议问题