June 2025
Intermediate to advanced
1093 pages
33h 24m
English
The container adapters are not standalone containers, but rather contain one of the actual containers to hold their data. Externally, they offer methods to perform specialized tasks.
For example, you can choose what the underlying container should be for stack.
// https://godbolt.org/z/6MKMj3Pxv#include <stack>void run(auto data) { /* ... */ } // C++20, abbreviated function templaterun(stack<int>{}); // Default: uses vector<int>run(stack<int,vector<int>>{}); // like the defaultrun(stack<int,list<int>>{}); // uses list<int>
Listing 24.88 Adapters work with interchangeable implementations.
|
Container |
Description |
|---|---|
|
stack |
Last in, first out |
|
queue |
First in, first out |
|
priority_queue |
Remove the ... |
Read now
Unlock full access