Using the standard allocator types

Let's talk about the allocator types provided by the standard library.

std::allocator<T> is the default allocator type; it is the default value of the template type parameter to every standard container. So for example when you write std::vector<T> in your code, that's secretly the exact same type as std::vector<T, std::allocator<T>>. As we've mentioned before in this chapter, std::allocator<T> is a stateless empty type; it is a "handle" to the global heap managed by new and delete. Because std::allocator is a stateless type, allocator_traits assumes (correctly) that it should be non-sticky. This means that operations such as std::vector<T>::swap and std::vector<T>::operator= are guaranteed to be very efficient ...

Get Mastering the C++17 STL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.