C++17 STL Cookbook
上QQ阅读APP看书,第一时间看更新

Container adapters

Arrays, lists, trees, and hash tables are not the only way to store and access data, as there are also stacks, queues, and so on. Similar, more sophisticated structures, however, can be implemented using the more primitive ones, and the STL does that with the following ones in the form of container adapters: std::stack, std::queue, and std::priority_queue.

The cool thing is that whenever we need such a data structure, we can just pick such an adapter. Then, when we realize that they do not work out well regarding their performance, we can just change a template parameter in order to let the adapter use a different container implementation, and that's it. In practice, this means, for example, that we can switch the implementation of an std::stack instance from std::vector to std::deque.