Navigation: Up, Table of Contents, Bibliography, Index, Title Page

vector (vector)

Definition

An object of the class vector is a sequence that supports random access iterators. In addition it supports (amortized) constant time insert and erase operations at the end. Insert and erase in the middle take linear time.

#include <vector.h >

Types

vector<T>::iterator
A mutable random access iterator.

vector<T>::const_iterator
A const random access iterator.

Creation

vector<T> V;
Introduces an empty vector.

vector<T> V ( vector<T> q);
Copy constructor.

vector<T> V ( int n, T t = T());
Introduces a vector with n items, all initialized to t.

Operations

vector<T> & V = vector<T> V1 Assignment.
bool V == vector<T> V1 Test for equality: Two vectors are equal, iff they have the same size and if their corresponding elements are equal.
bool V != vector<T> V1 Test for inequality.
bool V < vector<T> V1 Test for lexicographically smaller.
iterator V.begin () Returns a mutable iterator referring to the first element in vector V.
const_iterator V.begin () const Returns a constant iterator referring to the first element in vector V.
iterator V.end () Returns a mutable iterator which is the past-end-value of vector V.
const_iterator V.end () const Returns a constant iterator which is the past-end-value of vector V.
bool V.empty () Returns true if V is empty.
int V.size () Returns the number of items in vector V.
T& V [ int pos] Random access operator.
T V [ int pos] Random access operator.
T& V.front () Returns a reference to the first item in vector V.
T V.front () const Returns a const reference to the first item in vector V.
T& V.back () Returns a reference to the last item in vector V.
T V.back () const Returns a const reference to the last item in vector V.

Insert and Erase

void V.push_back ( T) Inserts an item at the back of vector V.
iterator V.insert ( iterator pos, T t)
Inserts a copy of t in front of iterator pos. The return value points to the inserted item.
void V.insert ( iterator pos, int n, T t = T())
Inserts n copy of t in front of iterator pos.
void
V.insert ( iterator pos,
const_iterator first,
const_iterator last)
Inserts a copy of the range [.first, last.) in front of iterator pos.
void V.pop_back () Removes the last item from vector V.
void V.erase ( iterator pos) Removes the item from vector V, where pos refers to.
void V.erase ( iterator first, iterator last)
Removes the items in the range[.first, last.) from vector V.

Next: Class declaration of deque<T>
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. Mon, June 30, 1997.