Belle II Software development
|
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.
using difference_type = std::ptrdiff_t |
Difference type.
Definition at line 110 of file ArrayIterator.h.
using iterator_category = std::forward_iterator_tag |
Iterator category.
Definition at line 107 of file ArrayIterator.h.
using pointer = ValueType* |
Pointer.
Definition at line 116 of file ArrayIterator.h.
using reference = ValueType& |
Reference.
Definition at line 119 of file ArrayIterator.h.
using value_type = ValueType |
Value type.
Definition at line 113 of file ArrayIterator.h.
|
inline |
Default constructor (not that you can dereference these).
Definition at line 124 of file ArrayIterator.h.
|
inlineexplicit |
Constructor.
Definition at line 129 of file ArrayIterator.h.
|
inlinestaticprivate |
Dereference if argument is a pointer to ValueType.
Definition at line 176 of file ArrayIterator.h.
|
inlinestaticprivate |
Dereference if argument is a pointer to ValueType.
Definition at line 182 of file ArrayIterator.h.
|
inline |
Check inequality.
Definition at line 156 of file ArrayIterator.h.
|
inline |
Dereference.
Definition at line 162 of file ArrayIterator.h.
|
inline |
Prefix increment.
Definition at line 135 of file ArrayIterator.h.
|
inline |
Postfix increment.
Definition at line 142 of file ArrayIterator.h.
|
inline |
Dereference.
Definition at line 168 of file ArrayIterator.h.
|
inline |
Check equality.
Definition at line 150 of file ArrayIterator.h.
|
private |
Array to iterate over.
Definition at line 188 of file ArrayIterator.h.
|
private |
Current index.
Definition at line 191 of file ArrayIterator.h.