An iterator dereferencing to a counter value. More...
#include <counter.h>
Public Types | |
Traits and data types | |
using | iterator_type = count_iterator< T > |
Type of this iterator. More... | |
using | difference_type = std::ptrdiff_t |
using | value_type = T |
Type of index returned by this iterator. More... | |
using | reference = T const & |
Type returned by dereference operator. More... | |
using | pointer = T * |
using | iterator_category = std::bidirectional_iterator_tag |
Public Member Functions | |
Construction | |
count_iterator ()=default | |
Initializes the iterator. More... | |
count_iterator (value_type count) | |
Initializes the iterator with the specified loop count. More... | |
Data access | |
reference | operator* () const |
Returns the current loop count. More... | |
Modification | |
iterator_type & | operator++ () |
Increments the loop count of this iterator, which is then returned. More... | |
iterator_type | operator++ (int) const |
iterator_type & | operator-- () |
Decrements the loop count of this iterator, which is then returned. More... | |
iterator_type | operator-- (int) const |
Comparisons | |
template<typename U > | |
bool | operator== (count_iterator< U > const &other) const |
Iterators are equal if their loop counts compare equal. More... | |
template<typename U > | |
bool | operator!= (count_iterator< U > const &other) const |
Iterators are equal if their loop counts compare different. More... | |
Private Attributes | |
value_type | fCount {} |
Internal counter. More... | |
An iterator dereferencing to a counter value.
T | the type of counter returned on dereferenciation |
util::counter()
This iterator returns on dereferencing the net count of how many times it has been incremented. So for example:
this infinite loop will push the value 0
into data
on the first iteration, 1
on the second and so forth, until at the eleventh iteration, just before it can push 10
, the loop is forcibly broken leaving 10 elements in data
.
The iterator can be made to start from an index n
different than 0
, in which case it behaves like it had already been incremented n
times. End iterators can be build in that way too; see also util::counter()
.
using util::count_iterator< T >::difference_type = std::ptrdiff_t |
using util::count_iterator< T >::iterator_category = std::bidirectional_iterator_tag |
using util::count_iterator< T >::iterator_type = count_iterator<T> |
using util::count_iterator< T >::pointer = T* |
using util::count_iterator< T >::reference = T const& |
using util::count_iterator< T >::value_type = T |
|
default |
Initializes the iterator.
The initial loop count is the default-constructed value of the counter type, which is usually some variation on the concept of 0
.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Increments the loop count of this iterator, returning a copy with the value before the increment.
Definition at line 116 of file counter.h.
|
inline |
|
inline |
Decrements the loop count of this iterator, returning a copy with the value before the decrement.
Definition at line 124 of file counter.h.
|
inline |
|
private |