Containers
sequence containers
provides access to sequences of elements. includes:
std::vector<T>
elements stored in continueous memorystd::deque<T>
elements don't stored in continueous memorystd::list<T>
std::array<T>
std::forward_list<T>
deques support fast push_front
operations. However, for other common operations like element access, vector will always outperform a deque.
deque slower to access middle elements, however.
vector is the type of sequence that should be used by default... deque is the data structure of choice when most insertions and deletions take place at the beginning or at the end of the sequences.
Uniform initialization.
container adaptors
associative containers & iterators
have no idea of a sequence
data is accessed using the key instead of indexes.
includes:
std::map<T1, T2>
std::set<T>
std::unordered_map<T1, T2>
std::unordered_set<T>
Iterators let us view a non-linear colleciton in a linear manner
auto elems.end()
does not point anything in the elems, it point to the last element + 1, so it out of the container
container adaptors
-
std::queue
the class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The queue pushes the elements on the back of the underlying container and pops them from the front.
-
std::stack
the class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The stack pushes and pops the element from the back of the underlying container, known as the top of the stack.