Writing Generic Containers with Allocator Support
We have come a long way since the beginning of this book. Recent chapters examined how one can write memory-efficient containers, describing how to do so when memory management is done explicitly (in Chapter 12) and when it is done implicitly, through smart pointers (in Chapter 13). Choosing a memory management approach is not an either/or proposition; each one is useful in its own way and solves real-life use cases depending on one’s application domain.
However, none of the approaches we have covered so far match what standard library containers do. Indeed, standard library containers (as well as many other standard library types that can dynamically allocate memory) are allocator-aware and delegate low-level memory management tasks to specialized objects that can be supplied by client code. There is merit to this idea as it allows one to pick a container based on the way it organizes objects in memory and couple said container...