Writing Generic Containers with Implicit Memory Management
In the previous chapter, we wrote a working (if simple) implementation of a std::vector<T>-like type in Vector<T>, as well as a working (if, again, simple) implementation of a std::forward_list<T>-like type in ForwardList<T>. Not bad!
In the case of our Vector<T> type, after an initial effort that led to a working but sometimes inefficient implementation, we made the effort to separate allocation from construction, something that reduced the amount of redundant effort required at runtime but came at the cost of a more subtle implementation. In this more sophisticated implementation, we distinguished parts of the underlying storage that are initialized from those that are not and, of course, operated on both parts appropriately (treating objects as objects and raw memory as such). For example, we used assignment (and algorithms that use the assignment operator) to replace the contents of existing...