STL Containers

  1. Every container allocates and manages its own storage.
  2. Type definitions common to all containers:
  • C::value_type type of values held in container
  • C::reference value_type&
  • C::const_reference
  • C::iterator
  • C::const_iterator
  • C::reverse_iterator
  • C::const_reverse_iterator
  • C::difference_type difference between iterators
  • C::size_type size of container

3. Member functions common to all containers:

  • C( )default constructor
  • C(c), C c2(c1)copy constructor
  • ~C( )destructor
  • c.begin()returns an iterator to first element
  • c.end()returns an iterator after last element
  • c.rbegin()returns a reverse iterator to last elem.
  • c.rend()returns a reverse iterator before first elem.
  • c1 == c2equality comparison for same type cont.
  • c1 != c2inequality comparison for same type cont.
  • c.size()returns number of elements. in cont.
  • c.max_size()returns size() of largest number of elements.
  • c.empty() – returns true if cont. is empty
  • c1 < c2lexicographic comparison
  • c1 > c2same
  • c1 <= c2same
  • c1 >= c2same
  • c1 = c2 – assignment operation
  • c1.swap(c2)swaps two containers

4. Sequence containers

  • vectorsimulates an expandable array, occupying contiguous memory
  • listbased on doubly linked list
  • dequea double ended queue, which uses a directory managing blocks of contiguous memory

5. Member functions common to all sequence containers:

  • C(n,t)constructs a sequence of n copies of t
  • C(iter1,iter2)constructs a sequence equal to the range [iter1,iter2)
  • c.insert(iter,t)inserts a copy of t before iter. Returns an iter to t.
  • c.insert(iter,n,t)inserts n copies of t before iter.
  • c.insert(iter1,iter2,iter3)inserts the sequence [iter2,iter3) before iter1
  • c.erase(iter)erases the element pointed to by iter
  • c.erase(iter1,iter2)erases elements in range [iter1,iter2)

Scroll to Top