indexunbounded_vector<T, Alloc>
Defined in header file: unbounded_vector.hh
Description
An unbounded_vector is similar to std::vector but overloads the operator[]
to change its behavior. In comparison to the std::vector the
unbounded_vector increases its size automatically if the element which
is accessed with the operator[] does not exist and initializes all new
elements with T().
Example
unbounded_vector<int> v;
assert(v.size() == 0);
v[5] = 1;
assert(v.size() == 6 && std::accumulate(v.begin(), v.end(), 0) == 1);
Public base classes
std::vector
Template parameters
| Parameter |
Description |
Default |
| T |
The value_type of an element of the unbounded_vector. |
|
| Alloc |
The allocator which is passed to the base class. |
std::allocator<T> |
Constructors
| Constructor |
Description |
| unbounded_vector() |
Creates an empty unbounded_vector. |
| unbounded_vector(size_type n) |
Creates an unbouned_vector of size n and initializes the elements with T(). |
| unbounded_vector(size_type n, const T& t) |
Creates an unbounded_vector of size n and initializes the elements with t. |
Members
| Types |
Description |
| Methods |
|
reference
operator[](size_type n) |
Returns a reference to the element at position n.
[1]
|
|
const_reference
operator[](size_type n)
const
|
Returns a reference to the element at position n.
[1]
|
Notes
[1]
The behavior for "operator[]" and "operator[] const" differ. While "operator[]" may change the size of the unbounded_vector the "operator[] const" returns a const reference to a member variable of type T which is initialized with T().
index