Public Member Functions | |
VectorSlice (VECTOR &v) | |
VectorSlice (VECTOR &v, unsigned int start, unsigned int length) | |
unsigned int | size () const |
VECTOR::reference | operator[] (unsigned int i) |
VECTOR::const_reference | operator[] (unsigned int i) const |
VECTOR::iterator | begin () |
VECTOR::const_iterator | begin () const |
VECTOR::iterator | end () |
VECTOR::const_iterator | end () const |
Private Attributes | |
VECTOR & | v |
const unsigned int | start |
const unsigned int | length |
Related Functions | |
(Note that these are not member functions.) | |
template<class VECTOR > | |
const VectorSlice< const VECTOR > | make_slice (VECTOR &v) |
template<class VECTOR > | |
const VectorSlice< const VECTOR > | make_slice (VECTOR &v, unsigned int start, unsigned int length) |
operator[] (unsigned int)
and a function size() const
.
The use of this object is straightforward. It reduplicates the random access operator of the VECTOR
and adds an offset to every index.
Some precautions have to be taken if it is used for a constant vector: the VectorSlice object has to be constant, too. The appropriate initalization sequence is like this:
void f(const std::vector<int>& v) { const VectorSlice<const std::vector<int> > slice(v,...); ... }
VectorSlice< VECTOR >::VectorSlice | ( | VECTOR & | v | ) | [inline] |
Construct a vector slice containing the whole vector. Comes handy, if you did not want to have a slice at all, but the function you call wants it: just put in the vector itself as argument and let this constructor make a slice for you.
VectorSlice< VECTOR >::VectorSlice | ( | VECTOR & | v, | |
unsigned int | start, | |||
unsigned int | length | |||
) | [inline] |
The real constructor for a vector slice, allowing you to specify the start index and the length of the slice.
References Assert.
unsigned int VectorSlice< VECTOR >::size | ( | ) | const [inline] |
Return the length of the slice using the same interface as std::vector
.
References VectorSlice< VECTOR >::length.
VECTOR::reference VectorSlice< VECTOR >::operator[] | ( | unsigned int | i | ) | [inline] |
Access an element of the slice using the same interface as std::vector
.
References Assert, VectorSlice< VECTOR >::length, VectorSlice< VECTOR >::start, and VectorSlice< VECTOR >::v.
VECTOR::const_reference VectorSlice< VECTOR >::operator[] | ( | unsigned int | i | ) | const [inline] |
Access an element of a constant slice using the same interface as std::vector
.
References Assert, VectorSlice< VECTOR >::length, VectorSlice< VECTOR >::start, and VectorSlice< VECTOR >::v.
VECTOR::iterator VectorSlice< VECTOR >::begin | ( | ) | [inline] |
STL conforming iterator function.
References VectorSlice< VECTOR >::start, and VectorSlice< VECTOR >::v.
VECTOR::const_iterator VectorSlice< VECTOR >::begin | ( | ) | const [inline] |
STL conforming iterator function.
References VectorSlice< VECTOR >::start, and VectorSlice< VECTOR >::v.
VECTOR::iterator VectorSlice< VECTOR >::end | ( | ) | [inline] |
STL conforming iterator function.
References VectorSlice< VECTOR >::length, VectorSlice< VECTOR >::start, and VectorSlice< VECTOR >::v.
VECTOR::const_iterator VectorSlice< VECTOR >::end | ( | ) | const [inline] |
STL conforming iterator function.
References VectorSlice< VECTOR >::length, VectorSlice< VECTOR >::start, and VectorSlice< VECTOR >::v.
const VectorSlice< const VECTOR > make_slice | ( | VECTOR & | v | ) | [related] |
Helper function for creating temporary objects without typing template arguments.
const VectorSlice< const VECTOR > make_slice | ( | VECTOR & | v, | |
unsigned int | start, | |||
unsigned int | length | |||
) | [related] |
Helper function for creating temporary objects without typing template arguments.
VECTOR& VectorSlice< VECTOR >::v [private] |
The vector we extract from.
Referenced by VectorSlice< VECTOR >::begin(), VectorSlice< VECTOR >::end(), and VectorSlice< VECTOR >::operator[]().
const unsigned int VectorSlice< VECTOR >::start [private] |
The start index of the slice.
Referenced by VectorSlice< VECTOR >::begin(), VectorSlice< VECTOR >::end(), and VectorSlice< VECTOR >::operator[]().
const unsigned int VectorSlice< VECTOR >::length [private] |
The length of the slice.
Referenced by VectorSlice< VECTOR >::end(), VectorSlice< VECTOR >::operator[](), and VectorSlice< VECTOR >::size().