Here is the complete list of methods available for containers (where
<E> denotes that the type of data contained within the container is of
type E):
Constructors
container<E> c
Create a container with no elements
container<E> c(n)
Create a container with n elements
container<E> c1(c2)
Create a container which is a copy of container c2
container<E> c(n, elem)
Create a container with n elements with value elem
Size and capacity operations
size_type size() const
Returns the number of elements in this container
size_type max_size() const
Returns the maximum number of elements that this container may contain
size_type capacity() const
Returns how many elements this container can possess without reallocation
bool empty() const
Returns true if this container contains no elements
void reserve(size_type num)
Reserves internal memory for at least num elements
Special associative container operations
These operations are only available to set, multiset, map
and multimap.
size_type count(const T& val)
Returns the number of elements equal to val. For set and
multiset, T is the type of the elements; for map and
multimap, it is the type of the key. This method has linear time
complexity
iterator find(const T& val)
Returns the position of the first element with value val; if
it's not found, end() is returned. This method has logarithmic time
complexity
iterator lower_bound(const T& val)
Returns the first position where a copy of val would be
inserted; if val is not found, end is returned. This method
has logarithmic time complexity
iterator upper_bound(const T& val)
Returns the last position where val would get inserted. This
method has logarithmic time complexity
pair<iterator, iterator> equal_range(const T& val)
Returns the first and last positions where val would get
inserted. This method has logarithmic time complexity
key_compare key_comp()
Returns the comparison criteria
value_compare value_comp()
Returns the object used for comparison criteria
Assignment operations
container& operator=(const container& c)
All elements of the container are assigned the elements of c
void assign(size_type num, const T& val)
Replace all elements of the container with num copies of
val; this method is only available to vector, deque,
list and string
void assign(InputIterator beg, InputIterator end)
Replace all elements of the container with the elements in the range
beg - end; this method is only available to vector,
deque, list and string
void swap(container& c)
Swap the contents of this container with container c
void swap(container& c1, container& c2)
Swaps the elements of c1 and c2
Element access operations
reference at(size_type index)
Returns the element at index; modifications to the container after
using this method can invalidate the reference. This method is only available
to vector, deque, list and string
reference operator[](size_type index)
Return the element with index index; the first element is index
0. This method is only available to vector, deque, list
and string
T& operator[](const key_type& key)
Retuns the value of key in a map. Used for associative arrays with
map and multimap
reference front()
Returns the first element. This method is only available to
vector, deque and list
reference back()
Returns the last element. This method is only available to
Insertion and deletion operations
iterator insert(const T& val)
Insert a copy of val into an associative multiset or
multimap.
pair<iterator, bool> insert(const T& val)
Insert a copy of val
iterator insert(iterator pos, const T& val)
Inserts val at position pos
void insert(iterator pos, size_type num, const T& val)
Insert num copies of value val starting at position pos
void insert(InputIterator beg, InputIterator end
Insert copies of all elements in the range beg - end into a set,
multiset, map or multimap.
void void(iterator pos, iterator beg, InputIterator end
Insert at position pos copies of all elements in the range beg -
end. Only provided for vectors, deques, lists and strings.
void push_front(const T& val)
Inserts val as the first element. Only provided by lists and deques.
void push_back(const T& val)
Inserts val as the last element of the container.
void remove(const T& val)
Remove all elements with value val. Provided by lists.
size_type erase(const T& val)
Remove all elements with value val from a set, multiset, map or
multimap; it returns how many elements were deleted from the container. For
maps and multimaps, T must be the key
void erase(iterator pos)
Removes the element at position pos; only available to set, multiset,
map and multimap
iterator erase(iterator pos)
Removes the element at position pos; only available to vectors, deques,
lists and strings
void erase(iterator beg, iterator end)
Removes the elements in the range beg end; only available to
set, multiset, map and multimap
iterator erase(iterator beg, iterator end)
Removes the elements in the range beg end; only available to
vectors, deques, lists and strings
void pop_front()
Removes the first element of the container; only available to deques and lists
void pop_back()
Removes the last element of the container; provided by vectors, deques and lists
void resize(size_type num)
Changes the number of elements in this container to num. Only provided
by vectors, deques, lists and strings
size_type resize(size_type num, T val)
? Only provided by vectors, deques, lists and strings
void clear()
Removes all elements from the container
List operations
Iterator methods
iterator begin()
Return an iterator to the first element of the container
iterator end()
Return an iterator to the point past the last element of the container