Dune Core Modules (unstable)

Iterator facades

Iterator facades for writing stl conformant iterators. More...

Modules

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

Classes

class  Dune::ForwardIteratorFacade< T, V, R, D >
 Base class for stl conformant forward iterators. More...
 
class  Dune::BidirectionalIteratorFacade< T, V, R, D >
 Facade class for stl conformant bidirectional iterators. More...
 
class  Dune::RandomAccessIteratorFacade< T, V, R, D >
 Base class for stl conformant forward iterators. More...
 
class  Dune::ProxyArrowResult< ProxyType >
 Helper to mimic a pointer for proxy objects. More...
 
struct  Dune::IteratorFacadeAccess
 This class encapsulates access of IteratorFacade. More...
 
class  Dune::IteratorFacade< It, C, V, R, P, D >
 CRTP-Mixing class for stl conformant iterators of given iterator category. More...
 

Functions

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator== (const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
 Checks for equality. More...
 
template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator!= (const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
 Checks for inequality. More...
 
template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
std::enable_if< std::is_convertible< T2, T1 >::value, bool >::type Dune::operator== (const BidirectionalIteratorFacade< T1, V1, R1, D > &lhs, const BidirectionalIteratorFacade< T2, V2, R2, D > &rhs)
 Checks for equality. More...
 
template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator!= (const BidirectionalIteratorFacade< T1, V1, R1, D > &lhs, const BidirectionalIteratorFacade< T2, V2, R2, D > &rhs)
 Checks for inequality. More...
 
template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator== (const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
 Checks for equality. More...
 
template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator!= (const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
 Checks for inequality. More...
 
template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator< (const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
 Comparison operator. More...
 
template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator<= (const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
 Comparison operator. More...
 
template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator> (const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
 Comparison operator. More...
 
template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator>= (const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
 Comparison operator. More...
 
template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, D >::type Dune::operator- (const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
 Calculates the difference between two pointers. More...
 
template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 >
constexpr auto Dune::operator== (const IteratorFacade< T1, C, V1, R1, P1, D1 > &it1, const IteratorFacade< T2, C, V2, R2, P2, D2 > &it2)
 Equality comparison for IteratorFacade. More...
 
template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 , std::enable_if_t< Dune::models< Impl::Concepts::IterEqualsOp, T1, T2 >(), int > = 0>
constexpr bool Dune::operator!= (const IteratorFacade< T1, C, V1, R1, P1, D1 > &it1, const IteratorFacade< T2, C, V2, R2, P2, D2 > &it2)
 Inequality comparison for IteratorFacade. More...
 
template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D >
constexpr auto Dune::operator- (const IteratorFacade< T1, C, V1, R1, P1, D > &it1, const IteratorFacade< T2, C, V2, R2, P2, D > &it2)
 Difference for two IteratorFacade objects. More...
 
template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 , std::enable_if_t< Dune::models< Impl::Concepts::IterDistanceOp< D1 >, T1, T2 >(), int > = 0>
constexpr bool Dune::operator< (const IteratorFacade< T1, C, V1, R1, P1, D1 > &it1, const IteratorFacade< T2, C, V2, R2, P2, D2 > &it2)
 Comparison for IteratorFacade. More...
 
template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 , std::enable_if_t< Dune::models< Impl::Concepts::IterDistanceOp< D1 >, T1, T2 >(), int > = 0>
constexpr bool Dune::operator<= (const IteratorFacade< T1, C, V1, R1, P1, D1 > &it1, const IteratorFacade< T2, C, V2, R2, P2, D2 > &it2)
 Comparison for IteratorFacade. More...
 
template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 , std::enable_if_t< Dune::models< Impl::Concepts::IterDistanceOp< D1 >, T1, T2 >(), int > = 0>
constexpr bool Dune::operator> (const IteratorFacade< T1, C, V1, R1, P1, D1 > &it1, const IteratorFacade< T2, C, V2, R2, P2, D2 > &it2)
 Comparison for IteratorFacade. More...
 
template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 , std::enable_if_t< Dune::models< Impl::Concepts::IterDistanceOp< D1 >, T1, T2 >(), int > = 0>
constexpr bool Dune::operator>= (const IteratorFacade< T1, C, V1, R1, P1, D1 > &it1, const IteratorFacade< T2, C, V2, R2, P2, D2 > &it2)
 Comparison for IteratorFacade. More...
 

Detailed Description

Iterator facades for writing stl conformant iterators.

With using these facades writing iterators for arbitrary containers becomes much less cumbersome as only few functions have to be implemented. All other functions needed by the stl are provided by the facades using the Barton-Nackman trick (also known as curiously recurring template pattern).

The following example illustrates how a random access iterator might be written:

...
template<class C, class T>
class TestIterator : public Dune::BidirectionalIteratorFacade<TestIterator<C,T>,T, T&, int>
{
friend class TestIterator<typename std::remove_const<C>::type, typename std::remove_const<T>::type >;
friend class TestIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type >;
public:
// Constructors needed by the facade iterators.
TestIterator(): container_(0), position_(0)
{ }
TestIterator(C& cont, int pos)
: container_(&cont), position_(pos)
{}
TestIterator(const TestIterator<typename std::remove_const<C>::type, typename std::remove_const<T>::type >& other)
: container_(other.container_), position_(other.position_)
{}
TestIterator(const TestIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type >& other)
: container_(other.container_), position_(other.position_)
{}
// Methods needed by the forward iterator
bool equals(const TestIterator<typename std::remove_const<C>::type,typename std::remove_const<T>::type>& other) const
{
return position_ == other.position_ && container_ == other.container_;
}
bool equals(const TestIterator<const typename std::remove_const<C>::type,const typename std::remove_const<T>::type>& other) const
{
return position_ == other.position_ && container_ == other.container_;
}
T& dereference() const
{
return container_->values_[position_];
}
void increment()
{
++position_;
}
// Additional function needed by BidirectionalIterator
void decrement()
{
--position_;
}
// Additional function needed by RandomAccessIterator
T& elementAt(int i)const
{
return container_->operator[](position_+i);
}
void advance(int n)
{
position_=position_+n;
}
std::ptrdiff_t distanceTo(TestIterator<const typename std::remove_const<C>::type,const typename std::remove_const<T>::type> other) const
{
assert(other.container_==container_);
return other.position_ - position_;
}
std::ptrdiff_t distanceTo(TestIterator<const typename std::remove_const<C>::type, typename std::remove_const<T>::type> other) const
{
assert(other.container_==container_);
return other.position_ - position_;
}
private:
C *container_;
size_t position_;
};
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:275
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:587
constexpr decltype(auto) elementAt(Container &&c, Index &&i)
Get element at given position from container.
Definition: hybridutilities.hh:126
This file implements iterator facade classes for writing stl conformant iterators.
STL namespace.

See dune/common/test/iteratorbase.hh for details.

Function Documentation

◆ operator!=() [1/4]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator!= ( const BidirectionalIteratorFacade< T1, V1, R1, D > &  lhs,
const BidirectionalIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Checks for inequality.

This operation is only defined if either D2 is convertible to D1 or vice versa. If that is not the case the compiler will report an error as EnableIfInterOperable<D1,D2,bool>::type is not defined.

◆ operator!=() [2/4]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator!= ( const ForwardIteratorFacade< T1, V1, R1, D > &  lhs,
const ForwardIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Checks for inequality.

This operation is only defined if either D2 is convertible to D1 or vice versa. If that is not the case the compiler will report an error as EnableIfInterOperable<D1,D2,bool>::type is not defined.

References Dune::Hybrid::equals().

◆ operator!=() [3/4]

template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 , std::enable_if_t< Dune::models< Impl::Concepts::IterEqualsOp, T1, T2 >(), int > = 0>
constexpr bool Dune::operator!= ( const IteratorFacade< T1, C, V1, R1, P1, D1 > &  it1,
const IteratorFacade< T2, C, V2, R2, P2, D2 > &  it2 
)
constexpr

Inequality comparison for IteratorFacade.

This operation is implemented as not(it1==it2) if the passed iterators support this operation (cf. documentation of operator==).

◆ operator!=() [4/4]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator!= ( const RandomAccessIteratorFacade< T1, V1, R1, D > &  lhs,
const RandomAccessIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Checks for inequality.

This operation is only defined if either D2 is convertible to D1 or vice versa. If that is not the case the compiler will report an error as EnableIfInterOperable<D1,D2,bool>::type is not defined.

References Dune::Hybrid::equals().

◆ operator-() [1/2]

template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D >
constexpr auto Dune::operator- ( const IteratorFacade< T1, C, V1, R1, P1, D > &  it1,
const IteratorFacade< T2, C, V2, R2, P2, D > &  it2 
)
constexpr

Difference for two IteratorFacade objects.

This operation is defined if the derived iterator classes T1 and T2 are interoperable, i.e. if T1 is convertible to T2 or vice versa and provide it1.distanceTo(t2) or it2.distanceTo(t1). Alternatively they may provide it1.baseIterator() - it2.baseIterator() for two const iterators.

◆ operator-() [2/2]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, D >::type Dune::operator- ( const RandomAccessIteratorFacade< T1, V1, R1, D > &  lhs,
const RandomAccessIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Calculates the difference between two pointers.

This operation is only defined if either D2 is convertible to D1 or vice versa. If that is not the case the compiler will report an error as EnableIfInterOperable<D1,D2,bool>::type is not defined.

◆ operator<() [1/2]

template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 , std::enable_if_t< Dune::models< Impl::Concepts::IterDistanceOp< D1 >, T1, T2 >(), int > = 0>
constexpr bool Dune::operator< ( const IteratorFacade< T1, C, V1, R1, P1, D1 > &  it1,
const IteratorFacade< T2, C, V2, R2, P2, D2 > &  it2 
)
constexpr

Comparison for IteratorFacade.

This operation is implemented as (it1-it2)<0 if the passed iterators support this operation (cf. documentation of operator-).

◆ operator<() [2/2]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator< ( const RandomAccessIteratorFacade< T1, V1, R1, D > &  lhs,
const RandomAccessIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Comparison operator.

This operation is only defined if either D2 is convertible to D1 or vice versa. If that is not the case the compiler will report an error as EnableIfInterOperable<D1,D2,bool>::type is not defined.

◆ operator<=() [1/2]

template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 , std::enable_if_t< Dune::models< Impl::Concepts::IterDistanceOp< D1 >, T1, T2 >(), int > = 0>
constexpr bool Dune::operator<= ( const IteratorFacade< T1, C, V1, R1, P1, D1 > &  it1,
const IteratorFacade< T2, C, V2, R2, P2, D2 > &  it2 
)
constexpr

Comparison for IteratorFacade.

This operation is implemented as (it1-it2)<=0 if the passed iterators support this operation (cf. documentation of operator-).

◆ operator<=() [2/2]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator<= ( const RandomAccessIteratorFacade< T1, V1, R1, D > &  lhs,
const RandomAccessIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Comparison operator.

This operation is only defined if either D2 is convertible to D1 or vice versa. If that is not the case the compiler will report an error as EnableIfInterOperable<D1,D2,bool>::type is not defined.

◆ operator==() [1/4]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
std::enable_if< std::is_convertible< T2, T1 >::value, bool >::type Dune::operator== ( const BidirectionalIteratorFacade< T1, V1, R1, D > &  lhs,
const BidirectionalIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Checks for equality.

This operation is only defined if T2 is convertible to T1, otherwise it is removed from the overload set since the enable_if for the return type yield an invalid type expression.

References Dune::Hybrid::equals().

◆ operator==() [2/4]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator== ( const ForwardIteratorFacade< T1, V1, R1, D > &  lhs,
const ForwardIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Checks for equality.

This operation is only defined if either D2 is convertible to D1 or vice versa. If that is not the case the compiler will report an error as EnableIfInterOperable<D1,D2,bool>::type is not defined.

References Dune::Hybrid::equals().

◆ operator==() [3/4]

template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 >
constexpr auto Dune::operator== ( const IteratorFacade< T1, C, V1, R1, P1, D1 > &  it1,
const IteratorFacade< T2, C, V2, R2, P2, D2 > &  it2 
)
constexpr

Equality comparison for IteratorFacade.

This operation is defined if the derived iterator classes T1 and T2 are interoperable, i.e. if T1 is convertible to T2 or vice versa and provide it1.equals(t2) or it2.equals(t1). Alternatively they may provide it1.baseIterator() == it2.baseIterator() for two const iterators.

◆ operator==() [4/4]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator== ( const RandomAccessIteratorFacade< T1, V1, R1, D > &  lhs,
const RandomAccessIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Checks for equality.

This operation is only defined if either D2 is convertible to D1 or vice versa. If that is not the case the compiler will report an error as EnableIfInterOperable<D1,D2,bool>::type is not defined.

References Dune::Hybrid::equals().

◆ operator>() [1/2]

template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 , std::enable_if_t< Dune::models< Impl::Concepts::IterDistanceOp< D1 >, T1, T2 >(), int > = 0>
constexpr bool Dune::operator> ( const IteratorFacade< T1, C, V1, R1, P1, D1 > &  it1,
const IteratorFacade< T2, C, V2, R2, P2, D2 > &  it2 
)
constexpr

Comparison for IteratorFacade.

This operation is implemented as (it1-it2)>0 if the passed iterators support this operation (cf. documentation of operator-).

◆ operator>() [2/2]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator> ( const RandomAccessIteratorFacade< T1, V1, R1, D > &  lhs,
const RandomAccessIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Comparison operator.

This operation is only defined if either D2 is convertible to D1 or vice versa. If that is not the case the compiler will report an error as EnableIfInterOperable<D1,D2,bool>::type is not defined.

◆ operator>=() [1/2]

template<class T1 , class T2 , class C , class V1 , class V2 , class R1 , class R2 , class P1 , class P2 , class D1 , class D2 , std::enable_if_t< Dune::models< Impl::Concepts::IterDistanceOp< D1 >, T1, T2 >(), int > = 0>
constexpr bool Dune::operator>= ( const IteratorFacade< T1, C, V1, R1, P1, D1 > &  it1,
const IteratorFacade< T2, C, V2, R2, P2, D2 > &  it2 
)
constexpr

Comparison for IteratorFacade.

This operation is implemented as (it1-it2)>=0 if the passed iterators support this operation (cf. documentation of operator-).

◆ operator>=() [2/2]

template<class T1 , class V1 , class R1 , class D , class T2 , class V2 , class R2 >
EnableIfInterOperable< T1, T2, bool >::type Dune::operator>= ( const RandomAccessIteratorFacade< T1, V1, R1, D > &  lhs,
const RandomAccessIteratorFacade< T2, V2, R2, D > &  rhs 
)
inline

Comparison operator.

This operation is only defined if either D2 is convertible to D1 or vice versa. If that is not the case the compiler will report an error as EnableIfInterOperable<D1,D2,bool>::type is not defined.

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