Standard Library Containers Standard Containers std:: Containers

    Sequence Containers Sequence

    array<T,size>
    standard library sequence container 'array

    fixed-size contiguous array

    vector<T>
    standard library sequence container 'vector

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

    deque<T>
    standard library sequence container 'deque

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

    list<T>
    standard library sequence container 'list

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

    forward_list<T>
    standard library sequence container 'forward_list

    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

    standard library associative container 'set
    map<Key,Value>

    stores unique key→value-pairs; sorted by keys

    standard library associative container 'map
    unordered_set<Key>

    stores unique keys; hashed by keys

    standard library associative container 'unordered_set
    unordered_map<Key,Value>

    stores unique key→value-pairs; hashed by keys

    standard library associative container 'unordered_map
    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

    standard library special container 'pair
    tuple<A,B,C,…>

    contains many values of same or different type

    standard library special container 'tuple
    optional<T>

    contains either one value of type T or no value

    standard library special container 'optional
    variant<A,B,C,…>

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

    standard library special container 'variant
    any

    contains one value of any

    standard library special container 'any

    Views

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