Standard Library ContainersStandard Containersstd:: Containers

    Sequence Containers Sequence

    array<T,size>

    fixed-size contiguous array

    vector<T>

    dynamic contiguous array; armortized O(1) growth strategy;
    C++'s default container

    deque<T>

    double-ended queue; fast insert/erase at both ends

    list<T>

    doubly-linked list; O(1) insert, erase & splicing; in practice often slower than vector

    forward_list<T>

    singly-linked list; O(1) insert, erase & splicing; needs less memory than list; in practice often slower than vector

    Associative Containers Associative

    set<Key>

    stores unique keys; sorted by keys

    map<Key,Value>

    stores unique key→value-pairs; sorted by keys

    unordered_set<Key>

    stores unique keys; hashed by keys

    unordered_map<Key,Value>

    stores unique key→value-pairs; hashed by keys

    Containers that allow non-unique keys:
    • multiset
    • multimap
    • unordered_multiset
    • unordered_multimap

    Special Containers Special

    pair<A,B>

    contains 2 values of same or different type

    tuple<A,B,C,…>

    contains many values of same or different type

    optional<T>

    contains either one value of type T or no value

    variant<A,B,C,…>

    contains one value of either type A or type B or type C, …

    any

    contains one value of any

    Views

    • lightweight (= cheap to copy, can be passed by value)
    • non-owning (= not responsible for allocating or deleting memory)