|
| | IteratorFacade () |
| |
| decltype(auto) constexpr | operator* () const |
| | Dereferencing operator. More...
|
| |
| constexpr pointer | operator-> () const |
| | Arrow access to members of referenced value. More...
|
| |
| decltype(auto) constexpr | operator++ () |
| | Preincrement operator. More...
|
| |
| constexpr DerivedIterator | operator++ (int) |
| | Postincrement operator. More...
|
| |
| template<bool dummy = true, std::enable_if_t< isBidirectional and dummy, int > = 0> |
| decltype(auto) constexpr | operator-- () |
| | Predecrement operator. More...
|
| |
| template<bool dummy = true, std::enable_if_t< isBidirectional and dummy, int > = 0> |
| constexpr DerivedIterator | operator-- (int) |
| | Postdecrement operator. More...
|
| |
| template<bool dummy = true, std::enable_if_t< isRandomAccess and dummy, int > = 0> |
| constexpr reference | operator[] (difference_type n) const |
| | Dereference element with given offset form this iterator. More...
|
| |
| template<bool dummy = true, std::enable_if_t< isRandomAccess and dummy, int > = 0> |
| decltype(auto) constexpr | operator+= (difference_type n) |
| | Increment iterator by given value. More...
|
| |
| template<bool dummy = true, std::enable_if_t< isRandomAccess and dummy, int > = 0> |
| constexpr DerivedIterator | operator+ (difference_type n) const |
| | Create iterator incremented by given value. More...
|
| |
| template<bool dummy = true, std::enable_if_t< isRandomAccess and dummy, int > = 0> |
| constexpr DerivedIterator & | operator-= (difference_type n) |
| | Decrement iterator by given value. More...
|
| |
| template<bool dummy = true, std::enable_if_t< isRandomAccess and dummy, int > = 0> |
| constexpr DerivedIterator | operator- (difference_type n) const |
| | Create iterator decremented by given value. More...
|
| |
template<class It, class C, class V, class R = V&, class P = V*, class D = std::ptrdiff_t>
class Dune::IteratorFacade< It, C, V, R, P, D >
CRTP-Mixing class for stl conformant iterators of given iterator category.
The iterator category is given by the corresponding tag class. Currently supported tags are std::forward_iterator_tag, std::bidirectional_iterator_tag, std::random_access_iterator_tag.
For proxy iterators (i.e. iterator that don't return a real reference but a so called proxy-value that behaves like a reference), the template parameter R should be the type of the proxy-value and no reference. In the latter case one should also use P=ProxyArrowResult<R> as pointer type used as return value of operator->. If P is not a raw pointer type, then it must be constructable from V.
The derived class should implement methods as documented in the following. Notice that, if the iterator provides multiple of the possible implementations for a certain feature, then precedence for the different implementation follows the order given below.
For a forward iterator the derived class It must provide:
- Dereferencing a const iterator using any of the following approaches:
- implement
*it
- implement
*(it.baseIterator())
- Incrementing a non-const iterator using any of the following approaches:
- implement
++it and declare using IteratorFacade::operator++
- implement
++(it.baseIterator())
- implement
it+=1
- Equality comparison of two const iterators using any of the following approaches:
- implement
it1==it2
- implement
it1.baseIterator()==it2.baseIterator()
For a bidirectional iterator it must additionally provide:
- Decrementing a non-const iterator using any of the following approaches:
- implement
--it and declare using IteratorFacade::operator--
- implement
--(it.baseIterator())
- implement
it-=1
For a random access iterator it must additionally provide:
- Advacing a non-const iterator by an offset using any of the following approaches:
- implement
it+=n
- implement
it.baseIterator()+=n
- Computing the distance between two const iterators using any of the following approaches:
- implement
it1-it2
- implement
it1.baseIterator()-it2.baseIterator()
When relying on option 2 for any of those features, the it.baseIterator() method can be made private to hide it from the user. Then the derived class must declare IteratorFacadeAccess as friend. Notice that depending on the feature it is used for, it.baseIterator() must be a const or non-const method. Thus the derived class must provide both versions if it wants to implement const and non-const operation in terms of `it.baseIterator().
For example a forward iterator for values of type V could be implemented by providing the core operations manually (option 1 above):
class FooIterator
{
public:
{ return [implement dereferencing here]; }
{ [implement incrementing here]; return *this; }
friend bool operator==(
const FooIterator& it1,
const FooIterator& it2)
{ return [implement comparison here]; }
};
Alternatively the iterator can delegate arithmetic operations and comparisons to an underlying iterator/pointer/number (option 2 above). E.g. a random access iterator where the iterator position is identified by a consecutive number can be implemented as:
class BarIterator
{
public:
{ return [implement dereferencing at current position p_ here]; }
private:
};
When providing baseIterator() individual method can still be overloaded by implementing them manually. E.g. a random access iterator for values of type V that returns reference-like proxy objects of type R instead of plain V& references and relies on an underlying iterator except for equality comparison can be implemented as:
class ProxyIterator
:
public Dune::IteratorFacade<ProxyIterator, std::random_access_iterator_tag, V, R, Dune::ProxyArrowResult<R>>
{
public:
{ return [implement dereferencing at current position it_ here]; }
friend bool operator==(
const ProxyIterator& it1,
const ProxyIterator& it2)
{ return [implement custom comparison here]; }
private:
BaseIterator& baseIterator() { return it_; }
const BaseIterator& baseIterator() const { return it_; }
BaseIterator it_;
};
- Template Parameters
-
| It | The derived iterator class |
| C | Tag class of iterator category |
| V | The value type |
| R | The reference type, defaults to V& |
| P | Pointer type, defaults to V* |
| D | The type for differences between two iterators, defaults to std::ptrdiff_t |