Next : , Previous : Allocators, Top : Table of Contents


Containers

value_type Typedef on containers
reference Typedef on containers
const_reference Typedef on containers
pointer Typedef on containers
iterator Typedef on containers
const_iterator Typedef on containers
difference_type Typedef on containers
size_type Typedef on containers

Containers are objects that store other objects. They control allocation and deallocation of these objects through constructors, destructors, insert and erase operations.

X () Constructor on containers
X (const X& a) Constructor on containers
~X () Destructor on containers
== Operator on containers
!= Operator on containers
< Operator on containers
> Operator on containers
<= Operator on containers
>= Operator on containers

size_type max_size () Method on containers
bool empty () Method on containers
void swap () Method on containers

In the following table, assume X is a container class containing objects of type T, a and b are values of X, u is an identifier and r is a value of X&.

Table 8: Container requirements

Expression Return type Operational semantics Assertion/note pre/post-condition Complexity
X::value_type T compile time
X::reference compile time
X::const_reference compile time
X::pointer a pointer type pointing to X::reference pointer to T in the memory model used by the container compile time
X::iterator iterator type pointing to X::reference an iterator of any iterator category except output iterator. compile time
X::const_iterator iterator type pointing to X::const_reference a constant iterator of any iterator category except output iterator. compile time
X::difference_type signed integral type is identical to the distance type of X::iterator and X::const_iterator compile time
X::size_type unsigned integral type size_type can represent any non-negative value of difference_type compile time
X u; post: u.size() == 0. constant
X() X().size() == 0. constant
X(a) a == X(a). linear
X u(a);
X u = a;
X u; u = a; post: u == a. linear
(&a)->~X() result is not used post: a.size() == 0.
note: the destructor is applied to every element of a and all the memory is returned.
linear
a.begin() iterator; const_iterator for constant a constant
a.end() iterator; const_iterator for constant a constant
a == b convertible to bool a.size() == b.size() && equal(a.begin(), a.end(), b.begin()) == is an equivalence relation. See Equal. linear
a != b convertible to bool !(a == b) linear
r = a X&  if (&r != &a) {
  (&r)->X::~X();
  new (&r) X(a);
  return r; }
post: r == a. linear
a.size() size_type size_type n = 0; distance(a.begin(), a.end(), n); return n; constant
a.max_size() size_type size() of the largest possible container. constant
a.empty() convertible to bool a.size() == 0 constant
a < b convertible to bool lexicographical_compare(a.begin(), a.end(), b.begin(), b.end()) pre: < is defined for values of T. < is a total ordering relation. See Lexicographical comparison. linear
a > b convertible to bool b < a linear
a <= b convertible to bool !(a > b) linear
a >= b convertible to bool !(a < b) linear
a.swap(b) void swap(a,b) constant

size () Method on containers

The member function size() returns the number of elements in the container. Its semantics is defined by the rules of constructors, inserts, and erases.

begin () Method on containers
end () Method on containers

begin() returns an iterator referring to the first element in the container. end() returns an iterator which is the past-the-end value.

reverse_iterator Typedef on reversible containers
const_reverse_iterator Typedef on reversible containers

( const_)reverse_iterator rbegin () Method on reversible containers
( const_)reverse_iterator rend () Method on reversible containers

If the iterator type of a container belongs to the bidirectional or random access iterator categories, the container is called reversible and satisfies the following additional requirements:

Table 9: Reversible container requirements (in addition to container)

Expression Return type Operational semantics Complexity
X::reverse_iterator reverse_iterator<iterator, value_type, reference, difference_type> for random access iterator reverse_bidirectional_iterator<iterator, value_type, reference, difference_type> for bidirectional iterator compile time
X::const_reverse_iterator reverse_iterator<const_iterator, value_type, const_reference, difference_type> for random access iterator

reverse_bidirectional_iterator< const_iterator, value_type, const_reference, difference_type> for bidirectional iterator

compile time
a.rbegin() reverse_iterator; const_reverse_iterator for constant a reverse_iterator(end()) constant
a.rend() reverse_iterator; const_reverse_iterator for constant a reverse_iterator(begin()) constant


 

Top