Dune Core Modules (2.10.0)

GenericIterator

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

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];
};

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

Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 26, 23:30, 2024)