Marc Wäckerlin
Für eine libertäre Gesellschaft

C++ Container Overview

Juni 14, 2020

Views: 649

This is an overview of the C++ containers and their most important functions. It should help chosing the right container.

type name description content access iterators modifiers operations lookup
key value at [] front back forward reverse insert erase insert_after erase_after push_back pop_back push_front pop_front resize merge splice_after remove remove_if reverse unique sort count find contains equal_range lower_bound upper_bound
sequence array static contiguous array x x x x x x
vector dynamic contiguous array x x x x x x x x x x x
deque double-ended queue x x x x x x x x x x x x x
forward_list singly-linked list x x x x x x x x x x x x x x
list doubly-linked list x x x x x x x x x x x x x x x x x x
associative set collection of unique keys, sorted by keys x x x x x x x x x x x
map collection of key-value pairs, sorted by keys, keys are unique x x x x x x x x x x x x
multiset collection of keys, sorted by keys x x x x x x x x x x x
multimap collection of key-value pairs, sorted by keys x x x x x x x x x x x x
unordered associative unordered_set collection of unique keys, hashed by keys x x x x x x x x
unordered_map collection of key-value pairs, hashed by keys, keys are unique x x x x x x x x x
unordered_multiset collection of keys, hashed by keys x x x x x x x x
unordered_multimap collection of key-value pairs, hashed by keys x x x x x x x x x

Queues and Stacks

Queues ans stacks are special interfaces to other containers. They offer the methods top, push, pop:

stack
LIFO based on deque
queue
FIFO based on deque
prioritiy_queue
queue that returns highest element first, based on vector

comments title