CMPU-235: Software Development Methodology

C++ Standard Library Containers

The C++ standard library includes several container classes and iterators for them. This page provides a brief overview. These libraries were created with the primary goal of being as efficient as possible, and with the secondary goal of being as general as possible. These are the standard C++ container templates:
vector
list A doubly-linked list
(More will be added as time permits)

Lists

For the list template class (there is an example here), the following methods are defined (T is the type used to create the template, i.e. list, and I is an iterator):
Typename/argsDescription
Iteratorsbegin()Points to the first element
end()Points past (after) the last element
rbegin()Points to the last element (the first element of the reverse sequence)
rend()Points past (before) the first element (the end of a reverse sequence)
Stack/Queue Opspush_back(T)Append an element to the end.
pop_back()Removes (does not return) the last element.
push_front(T)Insert a new first element
pop_front()Removes (does not return) the first element.
List Opsinsert(I,T)Insert an element before I.
insert(n,I,T)Insert n copies of the element before I.
insert(I, I1, I2)Insert elements from a sequence bounded by I1 (inclusive) and I2 (exclusive) before I (may be the same or a different sequence than I points to, but must be of the same type).
erase(I)Delete/remove element.
erase(I1, I2)Delete/remove elements between I1 and I2.
clear()Delete/remove all elements.
Other Opssize()Number of elements.
empty()Is the list empty?
==Are the contents of two containers the same?
=Copy one container into another.
Algorithmsfind(I1,I2,T)Find an element (first occurence) in a sequence, returns an iterator.
count(I1,I2,T)Count the number of times the element occurs in the sequence.
search(I1,I2,I3,I4)Find the first occurrence of the sequence [I3,I4) within the sequence [I1,I2). Returns an iterator.