Loading...
Searching...
No Matches
Dune::GenericIterator< C, T, R, D, IteratorFacade > Class Template Reference
Common » Iterator facades » GenericIterator

Generic class for stl-conforming iterators for container classes with operator[]. More...

`#include <dune/common/genericiterator.hh>`

Inheritance diagram for Dune::GenericIterator< C, T, R, D, IteratorFacade >:

## Public Types

typedef C | Container
| The type of container we are an iterator for.
typedef T | Value
| The value type of the iterator.
typedef D | DifferenceType
| The type of the difference between two positions.
typedef R | Reference
| The type of the reference to the values accessed.
using | iterator_category = std::random_access_iterator_tag
using | value_type = typename std::remove_const<V>::type
using | difference_type = D
using | pointer = V*
using | reference = R
typedef T | DerivedType
| The type of derived iterator.
typedef V * | Pointer
| The pointer to the Value.

## Public Member Functions

| GenericIterator ()
| GenericIterator (Container &cont, DifferenceType pos)
| Constructor.
| GenericIterator (const MutableIterator &other)
| Copy constructor.
| GenericIterator (const ConstIterator &other)
| Copy constructor.
bool | equals (const MutableIterator &other) const
bool | equals (const ConstIterator &other) const
Reference | dereference () const
void | increment ()
void | decrement ()
Reference | elementAt (DifferenceType i) const
void | advance (DifferenceType n)
DifferenceType | distanceTo (const MutableIterator &other) const
DifferenceType | distanceTo (const ConstIterator &other) const
constexpr Reference | operator* () const
| Dereferencing operator.
constexpr Pointer | operator-> () const
constexpr Reference | operator[] (DifferenceType n) const
| Get the element n positions from the current one.
constexpr DerivedType & | operator++ ()
| Preincrement operator.
constexpr DerivedType | operator++ (int)
| Postincrement operator.
constexpr DerivedType & | operator+= (DifferenceType n)
constexpr DerivedType | operator+ (DifferenceType n) const
constexpr DerivedType & | operator-- ()
| Predecrement operator.
constexpr DerivedType | operator-- (int)
| Postdecrement operator.
constexpr DerivedType & | operator-= (DifferenceType n)
constexpr DerivedType | operator- (DifferenceType n) const

## Friends

class | GenericIterator< typename std::remove_const< C >::type, typename std::remove_const< T >::type, typename mutable_reference< R >::type, D, IteratorFacade >
class | GenericIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T >::type, typename const_reference< R >::type, D, IteratorFacade >

## Detailed Description

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>
class Dune::GenericIterator< C, T, R, D, IteratorFacade >

Generic class for stl-conforming iterators for container classes with operator[].

If template parameter C has a const qualifier we are a const iterator, otherwise we are a mutable iterator.

## Member Typedef Documentation

## Container

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

typedef C Dune::GenericIterator< C, T, R, D, IteratorFacade >::Container

The type of container we are an iterator for.

The container type must provide an operator[] method.

If C has a const qualifier we are a const iterator, otherwise we are a mutable iterator.

## DerivedType

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

typedef T Dune::RandomAccessIteratorFacade< T, V, R, D >::DerivedType

inherited

The type of derived iterator.

The iterator has to define following functions have to be present:

// Access the value referred to.
Reference dereference() const;
// Access the value at some other location
Reference elementAt(n) const;
// Compare for equality with j
bool equals(j);
// position the iterator at the next element.
void increment()
// position the iterator at the previous element.
void decrement()
// advance the iterator by a number of positions-
void advance(DifferenceType n);
// calculate the distance to another iterator.
// One should incorporate an assertion whether
// the same containers are referenced
DifferenceType distanceTo(j) const;
Dune::GenericIterator::equals
bool equals(const MutableIterator &other) const
Definition genericiterator.hh:227
Dune::GenericIterator::elementAt
Reference elementAt(DifferenceType i) const
Definition genericiterator.hh:251
Dune::GenericIterator::increment
void increment()
Definition genericiterator.hh:241
Dune::GenericIterator::advance
void advance(DifferenceType n)
Definition genericiterator.hh:255
Dune::GenericIterator::DifferenceType
D DifferenceType
The type of the difference between two positions.
Definition genericiterator.hh:182
Dune::GenericIterator::Reference
R Reference
The type of the reference to the values accessed.
Definition genericiterator.hh:187
Dune::GenericIterator::distanceTo
DifferenceType distanceTo(const MutableIterator &other) const
Definition genericiterator.hh:259
Dune::GenericIterator::decrement
void decrement()
Definition genericiterator.hh:246
Dune::GenericIterator::dereference
Reference dereference() const
Definition genericiterator.hh:237

For an elaborate explanation see the STL Documentation

## difference_type

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

using Dune::RandomAccessIteratorFacade< T, V, R, D >::difference_type = D

inherited

## DifferenceType

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

typedef D Dune::GenericIterator< C, T, R, D, IteratorFacade >::DifferenceType

The type of the difference between two positions.

## iterator_category

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

using Dune::RandomAccessIteratorFacade< T, V, R, D >::iterator_category = std::random_access_iterator_tag

inherited

## Pointer

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

typedef V* Dune::RandomAccessIteratorFacade< T, V, R, D >::Pointer

inherited

The pointer to the Value.

## pointer

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

using Dune::RandomAccessIteratorFacade< T, V, R, D >::pointer = V*

inherited

## Reference

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

typedef R Dune::GenericIterator< C, T, R, D, IteratorFacade >::Reference

The type of the reference to the values accessed.

## reference

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

using Dune::RandomAccessIteratorFacade< T, V, R, D >::reference = R

inherited

## Value

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

typedef T Dune::GenericIterator< C, T, R, D, IteratorFacade >::Value

The value type of the iterator.

This is the return type when dereferencing the iterator.

## value_type

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

using Dune::RandomAccessIteratorFacade< T, V, R, D >::value_type = typename std::remove_const<V>::type

inherited

## Constructor & Destructor Documentation

## GenericIterator() [1/4]

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

Dune::GenericIterator< C, T, R, D, IteratorFacade >::GenericIterator | ( |  | ) |

inline

## GenericIterator() [2/4]

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

Dune::GenericIterator< C, T, R, D, IteratorFacade >::GenericIterator | ( | Container & | cont,
|  | DifferenceType | pos )

inline

Constructor.

Parameters

  cont | Reference to the container we are an iterator for
  pos | The position the iterator will be positioned to (e.g. 0 for an iterator returned by Container::begin() or the size of the container for an iterator returned by Container::end()

## GenericIterator() [3/4]

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

Dune::GenericIterator< C, T, R, D, IteratorFacade >::GenericIterator | ( | const MutableIterator & | other | ) |

inline

Copy constructor.

This is somehow hard to understand, therefore play with the cases:

1. if we are mutable this is the only valid copy constructor, as the argument is a mutable iterator
2. if we are a const iterator the argument is a mutable iterator => This is the needed conversion to initialize a const iterator from a mutable one.

## GenericIterator() [4/4]

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

Dune::GenericIterator< C, T, R, D, IteratorFacade >::GenericIterator | ( | const ConstIterator & | other | ) |

inline

Copy constructor.

Warning
  Calling this method results in a compiler error, if this is a mutable iterator.

This is somehow hard to understand, therefore play with the cases:

1. if we are mutable the arguments is a const iterator and therefore calling this method is mistake in the user's code and results in a (probably not understandable) compiler error
2. If we are a const iterator this is the default copy constructor as the argument is a const iterator too.

## Member Function Documentation

## advance()

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

void Dune::GenericIterator< C, T, R, D, IteratorFacade >::advance | ( | DifferenceType | n | ) |

inline

## decrement()

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

void Dune::GenericIterator< C, T, R, D, IteratorFacade >::decrement | ( |  | ) |

inline

## dereference()

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

Reference Dune::GenericIterator< C, T, R, D, IteratorFacade >::dereference | ( |  | ) | const

inline

## distanceTo() [1/2]

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

DifferenceType Dune::GenericIterator< C, T, R, D, IteratorFacade >::distanceTo | ( | const ConstIterator & | other | ) | const

inline

## distanceTo() [2/2]

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

DifferenceType Dune::GenericIterator< C, T, R, D, IteratorFacade >::distanceTo | ( | const MutableIterator & | other | ) | const

inline

## elementAt()

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

Reference Dune::GenericIterator< C, T, R, D, IteratorFacade >::elementAt | ( | DifferenceType | i | ) | const

inline

## equals() [1/2]

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

bool Dune::GenericIterator< C, T, R, D, IteratorFacade >::equals | ( | const ConstIterator & | other | ) | const

inline

## equals() [2/2]

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

bool Dune::GenericIterator< C, T, R, D, IteratorFacade >::equals | ( | const MutableIterator & | other | ) | const

inline

## increment()

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

void Dune::GenericIterator< C, T, R, D, IteratorFacade >::increment | ( |  | ) |

inline

## operator*()

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

Reference Dune::RandomAccessIteratorFacade< T, V, R, D >::operator* | ( |  | ) | const

inline constexpr inherited

Dereferencing operator.

## operator+()

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

DerivedType Dune::RandomAccessIteratorFacade< T, V, R, D >::operator+ | ( | DifferenceType | n | ) | const

inline constexpr inherited

## operator++() [1/2]

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

DerivedType & Dune::RandomAccessIteratorFacade< T, V, R, D >::operator++ | ( |  | ) |

inline constexpr inherited

Preincrement operator.

## operator++() [2/2]

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

DerivedType Dune::RandomAccessIteratorFacade< T, V, R, D >::operator++ | ( | int |  | ) |

inline constexpr inherited

Postincrement operator.

## operator+=()

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

DerivedType & Dune::RandomAccessIteratorFacade< T, V, R, D >::operator+= | ( | DifferenceType | n | ) |

inline constexpr inherited

## operator-()

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

DerivedType Dune::RandomAccessIteratorFacade< T, V, R, D >::operator- | ( | DifferenceType | n | ) | const

inline constexpr inherited

## operator--() [1/2]

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

DerivedType & Dune::RandomAccessIteratorFacade< T, V, R, D >::operator-- | ( |  | ) |

inline constexpr inherited

Predecrement operator.

## operator--() [2/2]

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

DerivedType Dune::RandomAccessIteratorFacade< T, V, R, D >::operator-- | ( | int |  | ) |

inline constexpr inherited

Postdecrement operator.

## operator-=()

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

DerivedType & Dune::RandomAccessIteratorFacade< T, V, R, D >::operator-= | ( | DifferenceType | n | ) |

inline constexpr inherited

## operator->()

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

Pointer Dune::RandomAccessIteratorFacade< T, V, R, D >::operator-> | ( |  | ) | const

inline constexpr inherited

## operator[]()

template<class T, class V, class R = V&, class D = std::ptrdiff_t>

Reference Dune::RandomAccessIteratorFacade< T, V, R, D >::operator[] | ( | DifferenceType | n | ) | const

inline constexpr inherited

Get the element n positions from the current one.

Parameters

  n | The distance to the element.

Returns
  The element at that distance.

## Friends And Related Symbol Documentation

## GenericIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T >::type, typename const_reference< R >::type, D, IteratorFacade >

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

friend class GenericIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T >::type, typename const_reference< R >::type, D, IteratorFacade >

friend

## GenericIterator< typename std::remove_const< C >::type, typename std::remove_const< T >::type, typename mutable_reference< R >::type, D, IteratorFacade >

template<class C, class T, class R = T&, class D = std::ptrdiff_t, template< class, class, class, class > class IteratorFacade = RandomAccessIteratorFacade>

friend class GenericIterator< typename std::remove_const< C >::type, typename std::remove_const< T >::type, typename mutable_reference< R >::type, D, IteratorFacade >

friend

The documentation for this class was generated from the following file:

- genericiterator.hh