Belle II Software
release-08-01-10
|
Generic iterator class for arrays, allowing use of STL algorithms, range-based for etc. More...
#include <ArrayIterator.h>
Public Member Functions | |
ArrayIterator () | |
Default constructor (not that you can dereference these). | |
ArrayIterator (const ArrayType *array, int index) | |
Constructor. | |
ArrayIterator< ArrayType, ValueType > & | operator++ () |
prefix increment. | |
ArrayIterator< ArrayType, ValueType > | operator++ (int) |
postfix increment. | |
bool | operator== (const ArrayIterator< ArrayType, ValueType > &rhs) const |
check equality. | |
bool | operator!= (const ArrayIterator< ArrayType, ValueType > &rhs) const |
check inequality. | |
ValueType & | operator* () const |
dereference. | |
ValueType * | operator-> () const |
dereference. | |
Static Private Member Functions | |
static ValueType & | deref_if_needed (ValueType &t) |
dereference if argument is a pointer to ValueType. | |
static ValueType & | deref_if_needed (ValueType *t) |
dereference if argument is a pointer to ValueType. | |
Private Attributes | |
const ArrayType * | m_array |
Array to iterate over. | |
int | m_index |
Current index. | |
Generic iterator class for arrays, allowing use of STL algorithms, range-based for etc.
Implements all operations required for a forward iterator. Note that wether objects can actually be added (i.e. extending the array) depends on the implementation of operator[].
It only requires that ArrayType provides operator[int] returning pointers or references to ValueType, you can then return ArrayIterator objects * with indices 0 and size() from begin() and end(). You should also define iterator and const_iterator typedefs as part of ArrayType. See StoreArray for examples.
Note that dereferencing an iterator via * returns a reference to ValueType, regardless of wether ArrayType::operator[] returns ValueType* or ValueType&.
Definition at line 86 of file ArrayIterator.h.