There are requirements for elements added to an STL container:

There are two types of containers:

Another way to classify containers:


For vectors, difference between subscript and .at(int index) is that .at(int index) will throw if subscript is out of range.

If reallocation occurs, all pointers and iterators are invalidated.

vector<type> v(n) will create n elements set to the default value, but vector<type> v(n, value) will create them AND set them to value.

vector<type> v(beg, end) will also create a vector from the specified range of elements. Both beg and end in this case are InputIterators.

swap(vector & x) - Exchanges the content of the container by the content of x, which is another vector object of the same type. Sizes may differ.

reserve(vector<typename>::size_type), of course, only increases the capacity, not the size. So it is different from using vector<type> v(n).

calling resize(vector<typename>::size_type n) will resize the container so it contains n elements. It destroys the back part of the vector.

Remember to check for empty() because empty vectors may contain invalid pointers to data

Swap/Shrink-to-Fit "trick":


Deques are also array-based structures, and act much like vectors.

However, it can grow in both directions, as well as shrink in both directions (adds push_front and pop_front).

Very importantly, you have no control over when a reallocation of memory occurs.

There is no reserve or capacity function.

Insertion and deletion, like usual, invalide pointers or iterators to other elements. The exception is that when an element is added to the end or the front.


Regular lists are, by default, doubly linked-lists.

Node-based, of course.

Insertion and deletion, obviously, do not invalidate pointers or iterators to other elements.

No reserve or capacity, since they're not necessary. There is push_front and pop_front since those are cheap.

THERE IS NO SUBSCRIPT (OPERATOR[]) OPERATOR!!!!! For good reason too. You really wanna iterate through the whole damn thing every time you need a variable?

NOTE: The following additional methods can only be operated on lists of the same type.

Additional methods are: