STL Quick Reference – Version 1.29 [A4] April 20, 2007 1
1 Notations
• The symbol
const
for const.
• The symbol x for function returned value.
• Template class parameters lead by outlined
character. For example: T, K
ey
, C
ompare
.
Interpreted in template definition context.
• Sometimes class, typename dropped.
• Template class parameters dropped,
thus C sometimes used instead of ChTi.
• “See example” by +, its output by '
à
.
2 Containers
2.1 Pair
#include <utility>
templatehclass T1, class T2i
struct pair {
T1 first; T2 second;
pair() {}
pair(
const
T1& a,
const
T2& b):
first(a), second(b) {} };
2.1.1 Types
pair::first type
pair::second type
2.1.2 Functions & Operators
See also 2.2.3.
pairhT1,T2i
make pair(
const
T1&,
const
T2&);
2.2 Containers — Common
Here X is any of
{vector, deque, li st,
set, multiset, map, multimap}
2.2.1 Types
X::value type
X::reference
X::const reference
X::iterator
X::const
iterator
X::reverse iterator
X::const reverse iterator
X::difference type
X::size type
Iterators reference value type (See 6).
2.2.2 Members & Operators
X::X();
X::X(
const
X&);
X::~X();
X& X::operator=(
const
X&);
X::iterator X::begin();
X::const iterator X::begin()
const
;
X::iterator X::end();
X::const
iterator X::end()
const
;
X::reverse ite rator X::rbegin();
X::const reverse iterator X::rbegin()
const
;
X::reverse ite rator X::rend();
X::const reverse iterator X::rend()
const
;
X::size type X::size()
const
;
X::size type X::max size()
const
;
bool X::empty()
const
;
void X::swap(X& x);
void X::clear();
2.2.3 Comparison Operators
Let, X v, w. X may also be pair (2.1).
v == w v != w
v < w v > w
v <= w v >= w
All d one lexicog raphi cally and xbool.
2.3 Sequence Containers
S is a ny o f {vector, deque, list}
2.3.1 Constructors
S::S(S::size type n,
const
S::value type& t);
S::S(S::const iterator first,
S::const iterator las t); +7.2, 7.3
2.3.2 Members
S::iterator // inserted copy
S::insert(S::iterator before,
const
S::value type& val);
S::iterator // inserted copy
S::insert(S::iterator before,
S::size
type nVal,
const
S::value type& val);
S::iterator // inserted copy
S::insert(S::iterator before,
S::const iterator first ,
S::const iterator last);
S:iterator S::erase(S::iterator position);
S:iterator S::erase(S::const ite rator first,
x post erased S::const iterator las t);
void S::push back(
const
S::value type& x );
void S::pop back();
S::reference S::front();
S::const reference S::front()
const
;
S::reference S::back();
S::const reference S::back()
const
;
2.4 Vector
#include <vector>
templatehclass T,
class A
lloc
=allocato ri
class vector;
See also 2.2 and 2.3.
size
type vector::capacity()
const
;
void vector::reserve(size type n);
vector::reference
vector::operator[ ](size type i );
vector::const reference
vector::operator[ ](size type i )
const
;
+ 7.1 .
2.5 Deque
#include <deque>
templatehclass T,
class A
lloc
=allocato ri
class deque;
Has a ll of vector functionality (see 2.4).
void deque::push front(
const
T& x );
void deque::pop front();
2.6 List
#include <list>
templatehclass T,
class A
lloc
=allocato ri
class list;
See also 2.2 and 2.3.
void list::pop front();
void list::push front(
const
T& x );
void // move all x (&x 6= this) before pos
list::splice(iterator pos, listhTi& x ); +7.2
void // move x’s xElemPos before pos
list::splice (it erato r pos,
listhTi& x,
iterator xElemPos); +7.2
void // move x’s [xFirst,xLast) before pos
list::splice (it erato r pos,
listhTi& x,
iterator xFirst,
iterator xLast); +7.2
void list::remove(
const
T& value);
void list::remove if(P
redicate
pred );
// after call: ∀ this ite rator p, ∗p 6= ∗(p + 1)
void list::unique(); // remove repeats
void // as before but, ¬binPred(∗p, ∗(p + 1))
list::unique(B
inaryPredicate
binPred );
// Assuming both this and x sorted
void list::merge(listhTi& x );
// merge and assume sorted by cmp
void list::merge(listhTi& x, C
ompare
cmp);
void list::reverse();
void list::sort();
void list::sort(C
ompare
cmp);
2.7 Sorted Associative
Here A any of
{set, multiset, map, multimap}.
2.7.1 Types
For A=[multi]set, columns are the same
A::key type A::value type
A::keycompare A::value compare
2.7.2 Constructors
A::A(C
ompare
c=C
ompare
())
A::A(A::const ite rator first ,
A::const
iterator last,
C
ompare
c=C
ompare
());
2.7.3 Members
A::keycompare A::key comp()
const
;
A::value compare A::value comp()
const
;
A::iterator
A::insert(A::iterator hint,
const
A::value type& val);
void A::insert(A::iterator first,
A::iterator last);
A::size type // # erased
A::erase(
const
A::key type& k );
void A::erase(A::iterator p);
void A::erase(A::iterator first,
A::iterator last);
A::size
type
A::count(
const
A::key type& k )
const
;
A::iterator A::find(
const
A::key type& k )
const
;
Yotam Medini
c
1998-2007 d http://www.medini.org/stl/stl.html
)
yotam.medini@gmail.com