![]() |
Belle II Software
light-2403-persian
|
Generic iterator class for arrays, allowing use of STL algorithms, range-based for etc. More...
#include <ArrayIterator.h>
Public Types | |
using | iterator_category = std::forward_iterator_tag |
Iterator category. | |
using | difference_type = std::ptrdiff_t |
Difference type. | |
using | value_type = ValueType |
Value type. | |
using | pointer = ValueType * |
Pointer. | |
using | reference = ValueType & |
Reference. | |
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 102 of file ArrayIterator.h.