Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

While looking at std::allocator, I see that members:
value_type, pointer, const_pointer, reference, const_reference, size_type, difference_type, and rebind have all been deprecated.

Allocators will also no longer have the members:
address, max_size, construct, or destroy.

Why did this happen? Did it have something to do with polymophic allocators?

like image 560
Trevor Hickey Avatar asked Jul 25 '16 10:07

Trevor Hickey


People also ask

What are the member functions associated with std :: allocator ()?

Member functions associated with std::allocator() : address: It is used for obtaining the address of an object although it is removed in C++20. construct: It is used to construct an object.It is also removed in C++20. destroy: It is used to destruct an object in allocated storage.It is also removed in C++20.

What is C++ default allocator?

Allocators are used by the C++ Standard LibraryC++ Standard LibraryThe C++ Standard Library provides several generic containers, functions to use and manipulate these containers, function objects, generic strings and streams (including interactive and file I/O), support for some language features, and functions for everyday tasks such as finding the square root of a number.https://en.wikipedia.org › wiki › C++_Standard_LibraryC++ Standard Library - Wikipedia to handle the allocation and deallocation of elements stored in containers. All C++ Standard Library containers except std::array have a template parameter of type allocator<Type> , where Type represents the type of the container element.


1 Answers

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

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

template<typename U> using other = allocator<U>; 

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.

like image 129
Ami Tavory Avatar answered Sep 19 '22 17:09

Ami Tavory