Container adapters adapt existing containers to provide new containers. In simple terms, STL extension is done with composition instead of inheritance.
STL containers can't be extended by inheritance, as their constructors aren't virtual. Throughout the STL, you can observe that while static polymorphism is used both in terms of operator overloading and templates, dynamic polymorphism is consciously avoided for performance reasons. Hence, extending the STL by subclassing the existing containers isn't a good idea, as it would lead to memory leaks because container classes aren't designed to behave like base classes.
The STL supports the following container adapters:
- Stack
- Queue
- Priority Queue
Let's explore the container adapters in the following subsections.