Special purpose containers

The containers described so far are flexible and can be used for all kinds of purposes. The Standard Library provides classes that have specific purposes, but, because they are implemented by wrapping other classes, they are called container adapters. For example, a deque object can be used as a first-in first-out (FIFO) queue, by pushing objects to the back of the deque (with push_back) and then accessing objects from the front of the queue using the front method (and removing them with pop_front). The Standard Library implements a container adapter called queue that has this FIFO behavior, and it is based on the deque class.

    queue<int> primes;     primes.push(1);     primes.push(2);     primes.push(3);  primes.push(5); ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.