\documentclass[11pt,twocolumn]{article}
\usepackage{graphicx}
\usepackage{color}
\usepackage{epstopdf}
\usepackage{alltt}
\usepackage{hyperref}

\hypersetup{colorlinks=true}

\textheight = 10.5 in
\linewidth = 8.0in
\oddsidemargin = 0.0 in
\evensidemargin = 0.0 in
\marginparwidth=0.0in
\marginparsep=0.0in
\topmargin = 0.0 in
\headheight = 0.0 in
\headsep = 0.0 in
\parskip = 1pt
\parindent = 0.0in

\setlength{\hoffset}{-24pt}
\setlength{\voffset}{-50pt}
\newcommand{\ttnrbf}[1]{\textnormal{\textbf{#1}}}
\newcommand{\ttnr}[1]{\textnormal{#1}}
\newcommand{\ttitbf}[1]{\textnormal{\textbf{#1}}}
\newcommand{\ttit}[1]{\textit{#1}}
\newcommand{\sSecBox}[1]{\begin{minipage}{3in}\begin{alltt}{\small\textrm{\textbf{#1}}}}
\newcommand{\eSecBox}{\end{alltt}\end{minipage}\\\rule{0pt}{0pt}\hrule}

\newcommand{\blt}{\makebox[2ex]{\(\bullet\)}}
\newcommand{\bsp}{\makebox[2ex]{}}

\newcommand{\ifa}{\(\Rightarrow\)}
\newcommand{\iffa}{\(\Leftrightarrow\)}
\newcommand{\dfa}{\makebox[2ex]{\(\mapsto\)}}    % Define Arrow

\newcommand{\E}{\makebox[0ex]{\(\cal{E}\)}{\scshape{y}}\ttnrbf{:}}
\newcommand{\T}{\makebox[0ex]{\(\cal{T}\)}{\scshape{x}}\ttnrbf{:}}
\newcommand{\F}{\makebox[0ex]{\(\cal{F}\)}{{n}}\ttnrbf{:}}
\newcommand{\C}{\makebox[0ex]{\(\cal{C}\)}{\scshape{t}}\ttnrbf{:}}
\newcommand{\M}{\makebox[1ex]{\makebox[0pt]{\scalebox{0.50}[1.0]{\(\cal{M}\)}}{\(_f\)}}\ttnrbf{:}}

\definecolor{grey50}{gray}{0.50}
%\colorbox{grey50}{}
%\textcolor{blue}{}

\begin{document}

\pagestyle{empty}

\fbox{{\parbox[b]{2in}{\huge \bf C++ STL \\ \tiny \copyright 1997-2016 Mitch Richling \url{https://www.mitchr.me}  \\ Last Updated 2016-07-09}}}
\tiny

\sloppy

\sSecBox{Notation}
  \blt X        \dfa A container          \blt a, b   \dfa Objects of type X
  \blt T        \dfa X::value_type        \blt t      \dfa Object of type T  
  \blt K        \dfa X::key_type          \blt k      \dfa Object of type K  
  \blt C        \dfa X::key_compare       \blt c      \dfa Object of type C
  \blt p        \dfa Iterators to a.      \blt q      \dfa Iterators to b.
  \blt p1, p2   \dfa Iterator rng to a.   \blt q1, q2 \dfa Iterator rng to b.
  \blt i,i2,i3  \dfa Integral index       \blt ch     \dfa A char (charT)
  \blt NTS      \dfa Null term string     \blt st     \dfa Simple string
  \blt o1,o2,o3 \dfa Random objects       \blt N      \dfa Number of elements
  \blt pU       \dfa 1 arg predicate      \blt bU     \dfa binary predicate
  \blt fU       \dfa 1 arg function
  \blt CMP      \dfa Binary compare  (-1 for <, 0 for ==, 1 for >)
  \blt n,n1,n2  \dfa Object of type X::size_type
\eSecBox

\sSecBox{Basic Attributes}
  \blt Assignable: o1 = o2  is a valid expression
  \blt Default Constructible: A no-arg constructor exists
  \blt Equality Comparable : o1 == o2 is a valid boolean-like expression
       Derived operator: o1 != o2 equivalent to !(o1 == o2)
       Invariants: \blt Identity:      &o1==&o2 \ifa o1==o2
                   \blt Reflexitivity: o1 == o2
                   \blt Symmetry       o1==o2 \iffa o2==o1
                   \blt Transitivity:  o1==o2 && o2==o3 \ifa o1==o3
  \blt LessThan Comparable: o1<o2 is a valid boolean-like expression
      Derived binary operators:   \blt o1>o2 equivalent to (o2<o1)
                                  \blt o1<=o2  equivalent to !(o2<o1)
                                  \blt o1>=o2  equivalent to !(o1<o2)
      Invariants:  \blt Irreflexivity: o1<o2 must be false
                   \blt Antisymmetry:  o1<o2 \ifa !(o2<o1)
                   \blt Transitivity:  o1<o2 && o2<o3 \ifa o1<o3
\eSecBox

\sSecBox{Container}
  \T X::allocator_type    \T X::value_type        \T X::difference_type
  \T X::iterator          \T X::const_iterator    \T X::size_type
  \T X::pointer           \T X::const_pointer
  \T X::reference         \T X::const_reference
  \C X(b)      \dfa Copy all elements from b. O(b.size())
  \E a.begin() \dfa O(1)        \E a.end()      \dfa O(1)   
  \E a.size()  \dfa O(N)        \E a.max_size() \dfa O(N)
  \E a.empty() \dfa O(1)        \E a.swap(b)    \dfa O(N)
\eSecBox

\sSecBox{Forward Container}
  \blt If T is Equality Comparable, then X is too (elementwise, O(N)).
  \bsp Note: a==b \ifa (a.size()==b.size())
  \blt If T is LessThan Comparable, then X is too (elementwise, O(N)).
  \bsp Note:  a<b == lexicographical_compare(a,b).
  \blt Iterators for X are Forward Iterators.
\eSecBox

\sSecBox{Reversible Container}
  \T reverse_iterator           \T const_reverse_iterator
  \E a.rbegin()  \dfa same as X::reverse_iterator(a.end())
  \E a.rend()    \dfa same as X::reverse_iterator(a.begin())
  \blt Iterators for X are Bidirectional Iterators.
\eSecBox

\sSecBox{Random Access Container}
  \E a[n]    \dfa Access to element n, 0<=n<N [reference if a is mutable]
  \E a.at(n) \dfa Access to element at n.
  \blt Iterators for X are Random Access Iterators
\eSecBox 

\sSecBox{Sequence}
  \C X(n, t)             \dfa Construct X with n copies of t O(n) 
  \C X(q1, q2)           \dfa Copy range [q1, q2) into new object. O(q2-q1)
  \E a.front()           \dfa Same as *(a.first())  AO(1)
  \E a.insert(p, t)      \dfa Insert a copy of t before p.
  \E a.insert(p, n, t)   \dfa Insert n copies of t before p.
  \E a.insert(p, q1, q2) \dfa Inserts stuff from [q1, q2) before p
  \E a.erase(p)          \dfa Erases element at p, returns ++p
  \E a.erase(p1, p2)     \dfa Erases [p1, p2).  returns ++p
  \E a.clear()           \dfa Same as a.erase(a.begin(), a.end())
  \E a.resize(n, t=T())  \dfa Resize adding copies of t if required
\eSecBox

\sSecBox{Front Insertion Sequence}
  \E a.push_front(t) \dfa same as a.insert(a.begin(), t)  AO(1)
  \E a.pop_front()   \dfa same as a.erase(a.begin()).     AO(1)
\eSecBox

\sSecBox{Back Insertion Sequence}
  \E a.back()       \dfa same as *(--a.end())            AO(1)
  \E a.push_back(t) \dfa same as a.insert(a.begin(), t)  AO(1)
  \E a.pop_back()   \dfa same as a.erase(--a.end())      AO(1)
\eSecBox

\sSecBox{Associative Container}
  \C X(c)             \dfa Construct with c as compare
  \C X(q1, q2, c)     \dfa Copy from [q1, q2) and use c as compare
  \T key_type         \T value_compare         \T compare_type
  \E a.erase(k)       \dfa Destroy elements with key k (returns nothing)
  \E a.erase(p)       \dfa Destroy element at p (returns nothing) AO(1)
  \E a.erase(p1, p2)  \dfa Destroy elements in [p, q) (returns nothing)
  \E a.clear()        \dfa Same as a.erase(a.begin(), a.end())
  \E a.find(k)
  \E a.count(k)       \dfa Return number of elements with key equal to k 
  \E a.equal_range(k)
\eSecBox

\sSecBox{Simple Associative Container}
  \blt X::key_type and X::value_type must be the same
  \blt X::iterator is the same as X::const_iterator (i.e. not mutable)
\eSecBox

\sSecBox{Pair Associative Container}
  \T X::mapped_type \dfa Same as T    \T X::value_type  \dfa pair<const Key, T>
\eSecBox

\sSecBox{Unique Associative Container}
  \blt No two elements can have equivalent key.  
  \blt Equality is based on the order for sorted UACs.
\eSecBox

\sSecBox{Sorted Associative Container}
  \T X::key_compare   \T X::value_compare
  \E a.lower_bound(k)  Return iterator to first key not less than k.     O(logN)
  \E a.upper_bound(k)  Return iterator to first key greater less than k. O(logN)
  \E a.equal_range(k)  Return pair(lower_bound(k), upper_bound(k)).      O(logN)
  \blt The keys must be LessThan Comparable.  
  \blt Iterators are bidirectional (ordered induced by key order)
  \blt find and count members are O(logN)
  \blt The keys are const -- (or at least no order changing modifications)
\eSecBox

\sSecBox{vector} #include <vector>
  \textcolor{blue}{vector<typename T, typename Allocator=allocator<T> >}
  \E a.capacity()  \dfa Return the current storage capacity.               O(1)
  \E a.reserve(n)  \dfa Make space for n elements (invalidating iterators) O(N)
  \blt Insert at the end is AO(1), while insert beginning is AO(N).  
  \blt Iterators can be invalidated by most any insert.
  \blt Element access is O(1).  
\eSecBox

\sSecBox{deque (pronounced DECK)} #include <deque>
  \textcolor{blue}{deque<typename T, typename Allocator=allocator<T> >}
  \blt Insert at the beginning or end is AO(1), others as bad as AO(N).  
  \blt Iterators can be invalidated by most any insert.
  \blt Element access is O(1).  
\eSecBox

\sSecBox{list} #include <list>
  \textcolor{blue}{list<typename T, typename Allocator=allocator<T> >}
  \E a.splice(p, &b)
  \E a.splice(p, &b, q)
  \E a.splice(p, &b, q1, q2)
  \E a.remove(t)             \dfa Remove all occurrences of t.   O(N)
  \E a.remote_if(pU)         \dfa Remove if f(*i) is true
  \E a.unique()              \dfa Keep first element of equal subsequences
  \E a.unique(pB)
  \E a.merge(b)
  \E a.merge(b, pB)
  \E a.reverse()             \dfa Reverse the list.  O(N)
  \E a.sort()                \dfa Sort the list.     O(NlogN)
  \E a.sort(pB)
  \blt Inserting an element ANYPLACE is O(1).  
  \blt Insertion and removal do not invalidate iterators.
\eSecBox

\sSecBox{set} #include <set>
  \textcolor{blue}{set<Key, Compare=less<>, typename Allocator=allocator<T> >}
  \blt A map with, logically, key==value for every element.
\eSecBox

\sSecBox{map} #include <map>
  \textcolor{blue}{map<typename Key, typename T, Compare=less<>, typename Allocator=allocator<T> >}
  \E a[k] \dfa Access the reference to data part of elements.  Insert pair(k,T()) if missing.
  \blt Inserts do not invalidate iterators, pointers, or references.  
  \blt Element erasure invalidates iterators-like things pointing to the thing being eliminated.
\eSecBox

\sSecBox{multiset} #include <multiset>
  \textcolor{blue}{multiset<typename Key, Compare=less<>, typename Allocator=allocator<T> >}
  \blt Just like a set, except that keys do not have to be unique.
\eSecBox

\sSecBox{multimap} #include <multimap>
  \textcolor{blue}{map<typename Key, typename T, Compare=less<>, typename Allocator=allocator<T> >}
  \blt Just like a map, except that keys do not have to be unique.
\eSecBox

\sSecBox{}
      \includegraphics[width=3in]{STLcontainers.pdf}
\eSecBox

\sSecBox{stack (LIFO)} #include <stack>
  \textcolor{blue}{stack<T, Container=dqueue<T> >}  -- Container adapter
  \E stack(X a=X())  \dfa Copy content of a into stack O(a.size())
  \T value_type    \bsp         \T size_type   \bsp          \T container_type
  \M empty() \dfa               \M top()  \dfa the back O(1)
  \M pop()   \dfa on back O(1)  \M push() \dfa off back O(1)
  \M size()  \dfa This one can be O(1), but can be as bad as O(N)
\eSecBox

\sSecBox{priority queue} #include <queue>
  \textcolor{blue}{priority_queue<T, Container=dqueue<T>, Compare=less<T> >}  -- Container adapter
  \C priority_queue(X a=X()) \dfa Copy content of a into stack
  \T value_type    \bsp            \T size_type   \bsp        \T container_type
  \M empty() \dfa O(1)             \M top()  \dfa O(1)
  \M pop()   \dfa from back O(?)   \M push() \dfa sorted O(?)
  \M size()  \dfa This one can be O(1), but can be as bad as O(N)
\eSecBox

\sSecBox{queue (FIFO)}
  \textcolor{blue}{queue<T, Container=dqueue<T> >}  -- Container adapter
  \C queue(X a=X())  \dfa Copy content of a into stack O(a.size())
  \T value_type       \bsp        \T size_type  \bsp             \T container_type
  \M back() \dfa O(1)             \M empty() \dfa O(1)           \M top() \dfa O(1)
  \M pop()  \dfa from back O(1)   \M push()  \dfa on front O(1)
  \M size() \dfa This one can be O(1), but can be as bad as O(N)
\eSecBox

\sSecBox{pair} #include <utility>
  \textcolor{blue}{pair<K, T>}  -- Contain a pair of objects
  \C pair(k, t)      \C pair()          \C pair(pair<K,T>)
  \T first_type      \T second_type
  \M first()         \M second()        \M make_pair(k, t)
  \blt If K and T are equality comparable then so is the pair
  \blt If K and T are LessThan comparable then so is the pair
\eSecBox

\sSecBox{Input Iterator}
  \ttnrbf{Expressions:}
   \E ++p        \dfa Preincrement
   \E (void)p++  \dfa Postincrement
   \E *p++       \dfa Postincrement and dereference
   \E *p         \dfa deference.  Can't read any element more than once.
   \E p->m       \dfa member access
\eSecBox

\sSecBox{Output Iterator}
   \E ++p        \dfa Preincrement
   \E (void)p++  \dfa Postincrement
   \E *p=t       \dfa Dereference assignment.  Only one time per element.
\eSecBox

\sSecBox{Forward Iterator}
  \blt Elements may be dereferenced multiple times and they can
  \bsp be be assigned to (via a dereference assignment) multiple times.
  \blt May be used any place an Output iterator or Input iterator can.
\eSecBox

\sSecBox{Bidirectional Iterator}
  \E p--  \dfa Postdecrement
  \E --p  \dfa Predecrement
\eSecBox

\sSecBox{Random Access Iterator}
  \E p += n  \dfa Increment n times
  \E p -= n  \dfa Decrement n times
  \E p+n     \dfa same as p+=n (n+p is OK too)
  \E p - n   \dfa same as p-=n
  \E p1 - p2 \dfa Returns integral distance
  \E p[n]    \dfa Get n-th value
  \E p[n]=t  \dfa Set the n-th value
  \blt A pointer IS a random access iterator and may be used in just
  \bsp about any place a RAI can be used.
\eSecBox 

\sSecBox{Iterator Adapters}
  \blt front_insert_iterator
  \blt back_insert_iterator
  \blt insert_iterator
  \blt reverse_iterator
  \blt reverse_bidirectional_iterator
\eSecBox

\sSecBox{Iterator Diagram}
    \includegraphics[width=3in]{STLiterators.pdf}
\eSecBox

\sSecBox{Algorithms: Non-modifying}
  \F count(p1, p2, t)     \dfa Number of times in [p1, p2) element ==t
  \F count_if(p1, p2, pU) \dfa Number of times in [p1, p2) pU is true
  \F for_each(p1, p2, fU) \dfa Evaluates fU on each thing in [p1, p2)
  \F find(p1, p2, t)
  \F find_if(p1, p2, pB)
  \blt (*) \dfa (o1, o2), (o1, o2, c)
  \bsp     \F min(*)               \F max(*)
  \blt (*) \dfa (p1, p2), (p1, p2, c)
  \bsp     \F min_element(*)       \F max_element(*)
  \blt (*) \dfa (p1, p2, t), (p1, p2, t, c)
  \bsp     \F equal_reverse(*)     \F lower_bound(*)    \F upper_bound(*)
  \blt (*) \dfa (p1, p2, q), (p1, p2, q, pB)
  \bsp     \F equal(*)             \F mismatch(*)
  \blt (*) \dfa (p1, p2, q1, q2), (p1, p2, q1, q2, pB)
  \bsp     \F find_end(*)          \F find_first_of(*)  \F search(*)
  \blt (*) \dfa (p1, p2), (p1, p2, pB)
  \bsp     \F adjacent_find(*)
  \blt (*) \dfa (p1, p2, n, t), (p1, p2, n, pB)
  \bsp     \F search_n(*)
  \blt (*) \dfa (p1, p2, t), (p1, p2, c)
  \bsp     \F binary_search(*)
  \blt (*) \dfa (p1, p2, q1, q2), (p1, p2, q1, q2, c)
  \bsp     \F lexicographical_compare(*)
\eSecBox

\sSecBox{Algorithms: Modifying}
  \blt (*) \dfa (p1, p2, q)
  \bsp     \F copy(*)              \F copy_backward(*)  \F uninitialized_copy(*)
  \bsp     \F swap_ranges(*)
  \bsp     \F reverse_copy(*)      \F unique_copy(*)    
  \blt (*) \dfa (p1, p2)
  \bsp     \F stable_sort(*)       \F unique(*)         \F sort(*)
  \bsp     \F iter_swap(*)         \F random_shuffle(*) \F reverse(*)
  \blt (*) \dfa (p1, p2, pB)
  \bsp     \F partition(*)         \F unique(*)         \F stable_partition(*)
  \blt (*) \dfa (p1, p2, c)
  \bsp     \F sort(*)              \F stable_sort(*)
  \blt (*) \dfa (p1, p2, t)
  \bsp     \F fill                 \F remove(*)         \F uninitialized_fill(*)
  \blt (*) \dfa (p1, p2, pU, t)
  \bsp     \F replace_copy_if(*)   \F replace_if(*)
  \blt (*) \dfa (first, middle, last), (first, middle, last, q)
  \bsp     \F rotate(*)            \F rotate_copy(*)
  \blt (*) \dfa (p1, p2, q, unryOp), (p1, p2, p3, q, binOp)
  \bsp     \F transform(*)         \F transform(*)
  \blt (*) \dfa (first, middle, last), (first, middle, last, c)
  \bsp     \F partial_sort(*)
  \F partial_sort_copy(first, last, result_first, result_last)
  \F partial_sort_copy(first, last, result_first, result_last, c)
  \F remove_copy(p1, p2, q, t)
  \F remove_copy_if(p1, p2, q, pU)
  \F generate(p1, p2, gen), 
  \F generate_n(p1, n, gen)
  \F fill_n(p1, n, t)
  \F random_shuffle(p1, p2, rand)
  \F remove_if(p1, p2, pU)
  \F replace(p1, p2, old_val, new_val)
  \F replace_copy(p1, p2, q, old_val, new_val)
  \F unique_copy(p1, p2, q, pB)
  \F uninitialized_copy(p1, n, t)
\eSecBox

\sSecBox{Algorithms: Set Stuff}
  \blt includes(p1, p2, q1, q2, c=less<>) \dfa true if [q1,q2) is a subset of [p1, p2)
  \blt (*) \dfa (p1, p2, q1, q2, w) (p1, p2, q1, q2, w, c) [output is placed at w]
  \bsp  \F set_difference              \F set_intersection
  \bsp  \F set_symmetric_difference    \F set_union
\eSecBox

\sSecBox{Algorithms: Random Stuff}
  \blt (*) \dfa (p1, p2, init_val), (p1, p2, init_val, binOp)
  \bsp  \F accumulate
  \blt (*) \dfa (p1, p2, p3, init_val), (p1, p2, p3, init_val, binOp1, binOp2)
  \bsp  \F inner_product
  \blt (*) \dfa (p1, p2, q), (p1, p2, q, binOp)
  \bsp  \F adjacent_difference         \F partial_sum
  \blt (*) \dfa (p1, p2), (p1, p2, c)
  \bsp  \F next_permutation            \F prev_permutation
  \F swapI(t1, t2)
\eSecBox

\sSecBox{Strings}
  \blt typedefs:  \blt typedef basic_string<char> string
  \bsp            \blt typedef basic_string<wchar_t> wstring
  \blt Strings are ALMOST containers!
  \bsp \blt The string name behaves like a random access iterator
  \bsp \blt Don't support pop_back, back, front
  \E a = o1                     \dfa Construct out of o1 (a charT or NTS)
  \E a += o1                    \dfa call append with o1 as argument
  \E a.c_str()                  \dfa Return pointer null terminated, c-style, string
  \E a.data()                   \dfa Return pointer array of charT (not null terminated)
  \M copy(charT* dst, n, pos=0) \dfa Copy n chrs of a starting at pos to dst.  
  \M length()                   \dfa returns size()
  \M reserve(n=0)
  \M resize(n, ch=charT())                       
  \blt (*) \dfa (pos=0, n=npos)
  \bsp  \M substr(*)   \M erase(*)
  \blt (*) \dfa (bs, pos=0), (nts, pos, n), (nts, pos=0), (ch, pos=0)
  \bsp  \M find(*)     \M find_first_not_of(*)   \M find_first_of(*)    
  \bsp  \M rfind(*)    \M find_last_not_of(*)    \M find_last_of(*)     
  \blt (*) \dfa (bs), (bs, pos, n), (nts), (nts, n), (n, ch), (q1, q2)
  \bsp  \M assign(*)   \M append(*)
  \blt (*) \dfa (pos1,n2,bs,pos2,n2), (pos1,n1,bs), (pos1,n1,nts), (pos1,n1,nts,n2), (pos1,n1,n2,ch)
  \bsp     \bsp (p1,p2,q1,q2),        (p1,p2,bs),   (p1,p2,nts),   (p1,p2,nts,n),    (p1,p2,n,ch)
  \bsp  \M replace(*)
  \blt (*) \dfa (pos, bs), (pos, bs, pos2, n), (pos, nts), (pos, nts, n), (pos, n, ch)
  \bsp  \M insert(*)
  \blt (*) \dfa (bs), (pos1,n,bs), (nts), (pos1,n1,bs,pos2,n2), (pos1,n1,nts,n2), (pos1,n1,nts)
  \bsp  \M compare(*)
\eSecBox

\end{document}