STXXL
1.4.0
|
This section introduces into the STXXL vector container (to learn more about the structure of stxxl::vector, see section Vector).
Before we can use a STXXL vector, we first have to define and then to instantiate a vector object. To manage the configuration of the vector type we use the generator template. A minimal configuration is shown below - as one can see the value_type (integer in our case) is the only only stricly neccessary parameter. See stxxl::VECTOR_GENERATOR for additional configuration parameters and information.
We can fill the vector by calling push_back() which appends a new value at the end:
To read and/or modify the values of a STXXL vector, simply use the []-operator:
In addition, the STXXL vector provides different iterators to advance the vector which can be used as follows:
Alongside with the many advantages of iterators, there are several things which need to bear in mind when using them. Details are described in More Notes.
The operation pop_back() removes the last element of the vector (without returning it). The following code snippet is emptying my_vector:
To determine the number of elements a vector currently stores, call size():
To check if the vector is empty, call the empty() function which returns true in that case:
(See examples/containers/vector1.cpp for the sourcecode of the following example).
See examples/containers/vector2.cpp for the sourcecode of a more comprehensive example.