Loading...
Searching...
No Matches
GenericIterator
Common » Iterator facades

Generic Iterator class for writing stl conformant iterators for any container class with operator[]. More...

Collaboration diagram for GenericIterator:

## Classes

class | Dune::GenericIterator< C, T, R, D, IteratorFacade >
| Generic class for stl-conforming iterators for container classes with operator[]. More...

## Detailed Description

Generic Iterator class for writing stl conformant iterators for any container class with operator[].

Using this template class you can create an iterator and a const_iterator for any container class.

Imagine you have SimpleContainer and would like to have an iterator. All you have to do is provide operator[], begin() and end() (for const and for non-const).

template<class T>
class SimpleContainer{
public:
typedef GenericIterator<SimpleContainer<T>,T> iterator;
typedef GenericIterator<const SimpleContainer<T>,const T> const_iterator;
SimpleContainer(){
for(int i=0; i < 100; i++)
values_[i]=i;
}
iterator begin(){
return iterator(*this, 0);
}
const_iterator begin() const{
return const_iterator(*this, 0);
}
iterator end(){
return iterator(*this, 100);
}
const_iterator end() const{
return const_iterator(*this, 100);
}
T& operator[](int i){
return values_[i];
}
const T& operator[](int i) const{
return values_[i];
}
private:
T values_[100];
};
Dune::operator[]
constexpr reference operator[](difference_type n) const
Dereference element with given offset form this iterator.
Definition iteratorfacades.hh:1207

See dune/common/test/iteratorfacestest.hh for details or Dune::QuadratureDefault in dune/quadrature/quadrature.hh for a real example.