Dune Core Modules (2.6.0)

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

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

#include <dune/common/genericiterator.hh>

Public Types

typedef C Container
 The type of container we are an iterator for. More...
 
typedef T Value
 The value type of the iterator. More...
 
typedef D DifferenceType
 The type of the difference between two positions.
 
typedef R Reference
 The type of the reference to the values accessed.
 
typedef GenericIterator< C, T, T &, std::ptrdiff_t, RandomAccessIteratorFacadeDerivedType
 The type of derived iterator. More...
 
typedef T * Pointer
 The pointer to the Value.
 

Public Member Functions

 GenericIterator (Container &cont, DifferenceType pos)
 Constructor. More...
 
 GenericIterator (const MutableIterator &other)
 Copy constructor. More...
 
 GenericIterator (const ConstIterator &other)
 Copy constructor. More...
 
Reference operator* () const
 Dereferencing operator.
 
Reference operator[] (DifferenceType n) const
 Get the element n positions from the current one. More...
 
DerivedTypeoperator++ ()
 Preincrement operator.
 
DerivedType operator++ (int)
 Postincrement operator.
 
DerivedTypeoperator-- ()
 Predecrement operator.
 
DerivedType operator-- (int)
 Postdecrement operator.
 

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

typedef GenericIterator< C, T, T &, std::ptrdiff_t, RandomAccessIteratorFacade > Dune::RandomAccessIteratorFacade< GenericIterator< C, T, T &, std::ptrdiff_t, RandomAccessIteratorFacade > , T , T & , std::ptrdiff_t >::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;
D DifferenceType
The type of the difference between two positions.
Definition: genericiterator.hh:180
R Reference
The type of the reference to the values accessed.
Definition: genericiterator.hh:185

For an elaborate explanation see the STL Documentation

◆ 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.

Constructor & Destructor Documentation

◆ GenericIterator() [1/3]

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
contReference to the container we are an iterator for
posThe 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() [2/3]

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() [3/3]

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

◆ operator[]()

Reference Dune::RandomAccessIteratorFacade< GenericIterator< C, T, T &, std::ptrdiff_t, RandomAccessIteratorFacade > , T , T & , std::ptrdiff_t >::operator[] ( DifferenceType  n) const
inlineinherited

Get the element n positions from the current one.

Parameters
nThe distance to the element.
Returns
The element at that distance.

The documentation for this class was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)