Loading...
Searching...
No Matches
iteratorfacades.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_ITERATORFACADES_HH
#define DUNE_ITERATORFACADES_HH
#include <iterator>
#include <type_traits>
#include <dune/common/typetraits.hh>
#include <dune/common/concept.hh>
namespace Dune
{
template<class T, class V, class R = V&, class D = std::ptrdiff_t>
class ForwardIteratorFacade
{
public:
/* type aliases required by C++ for iterators */
using iterator_category = std::forward_iterator_tag;
using value_type = typename std::remove_const<V>::type;
using difference_type = D;
using pointer = V*;
using reference = R;
typedef T DerivedType;
typedef V Value;
typedef V* Pointer;
typedef D DifferenceType;
typedef R Reference;
constexpr Reference operator*() const
{
return static_cast<DerivedType const*>(this)->dereference();
}
constexpr Pointer operator->() const
{
return &(static_cast<const DerivedType *>(this)->dereference());
}
constexpr DerivedType& operator++()
{
static_cast<DerivedType *>(this)->increment();
return *static_cast<DerivedType *>(this);
}
constexpr DerivedType operator++(int)
{
DerivedType tmp(static_cast<DerivedType const&>(*this));
this->operator++();
return tmp;
}
};
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename EnableIfInterOperable<T1,T2,bool>::type
operator==(const ForwardIteratorFacade<T1,V1,R1,D>& lhs,
const ForwardIteratorFacade<T2,V2,R2,D>& rhs)
{
if(std::is_convertible<T2,T1>::value)
return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
else
return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
}
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename EnableIfInterOperable<T1,T2,bool>::type
operator!=(const ForwardIteratorFacade<T1,V1,R1,D>& lhs,
const ForwardIteratorFacade<T2,V2,R2,D>& rhs)
{
if(std::is_convertible<T2,T1>::value)
return !static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
else
return !static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
}
template<class T, class V, class R = V&, class D = std::ptrdiff_t>
class BidirectionalIteratorFacade
{
public:
/* type aliases required by C++ for iterators */
using iterator_category = std::bidirectional_iterator_tag;
using value_type = typename std::remove_const<V>::type;
using difference_type = D;
using pointer = V*;
using reference = R;
typedef T DerivedType;
typedef V Value;
typedef V* Pointer;
typedef D DifferenceType;
typedef R Reference;
constexpr Reference operator*() const
{
return static_cast<DerivedType const*>(this)->dereference();
}
constexpr Pointer operator->() const
{
return &(static_cast<const DerivedType *>(this)->dereference());
}
constexpr DerivedType& operator++()
{
static_cast<DerivedType *>(this)->increment();
return *static_cast<DerivedType *>(this);
}
constexpr DerivedType operator++(int)
{
DerivedType tmp(static_cast<DerivedType const&>(*this));
this->operator++();
return tmp;
}
constexpr DerivedType& operator--()
{
static_cast<DerivedType *>(this)->decrement();
return *static_cast<DerivedType *>(this);
}
constexpr DerivedType operator--(int)
{
DerivedType tmp(static_cast<DerivedType const&>(*this));
this->operator--();
return tmp;
}
};
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename std::enable_if<std::is_convertible<T2,T1>::value,bool>::type
operator==(const BidirectionalIteratorFacade<T1,V1,R1,D>& lhs,
const BidirectionalIteratorFacade<T2,V2,R2,D>& rhs)
{
return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
}
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr
typename std::enable_if<std::is_convertible<T1,T2>::value && !std::is_convertible<T2,T1>::value,
bool>::type
operator==(const BidirectionalIteratorFacade<T1,V1,R1,D>& lhs,
const BidirectionalIteratorFacade<T2,V2,R2,D>& rhs)
{
return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
}
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename EnableIfInterOperable<T1,T2,bool>::type
operator!=(const BidirectionalIteratorFacade<T1,V1,R1,D>& lhs,
const BidirectionalIteratorFacade<T2,V2,R2,D>& rhs)
{
return !(lhs == rhs);
}
template<class T, class V, class R = V&, class D = std::ptrdiff_t>
class RandomAccessIteratorFacade
{
public:
/* type aliases required by C++ for iterators */
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;
typedef V Value;
typedef V* Pointer;
typedef D DifferenceType;
typedef R Reference;
constexpr Reference operator*() const
{
return static_cast<DerivedType const*>(this)->dereference();
}
constexpr Pointer operator->() const
{
return &(static_cast<const DerivedType *>(this)->dereference());
}
constexpr Reference operator[](DifferenceType n) const
{
return static_cast<const DerivedType *>(this)->elementAt(n);
}
constexpr DerivedType& operator++()
{
static_cast<DerivedType *>(this)->increment();
return *static_cast<DerivedType *>(this);
}
constexpr DerivedType operator++(int)
{
DerivedType tmp(static_cast<DerivedType const&>(*this));
this->operator++();
return tmp;
}
constexpr DerivedType& operator+=(DifferenceType n)
{
static_cast<DerivedType *>(this)->advance(n);
return *static_cast<DerivedType *>(this);
}
constexpr DerivedType operator+(DifferenceType n) const
{
DerivedType tmp(static_cast<DerivedType const&>(*this));
tmp.advance(n);
return tmp;
}
constexpr DerivedType& operator--()
{
static_cast<DerivedType *>(this)->decrement();
return *static_cast<DerivedType *>(this);
}
constexpr DerivedType operator--(int)
{
DerivedType tmp(static_cast<DerivedType const&>(*this));
this->operator--();
return tmp;
}
constexpr DerivedType& operator-=(DifferenceType n)
{
static_cast<DerivedType *>(this)->advance(-n);
return *static_cast<DerivedType *>(this);
}
constexpr DerivedType operator-(DifferenceType n) const
{
DerivedType tmp(static_cast<DerivedType const&>(*this));
tmp.advance(-n);
return tmp;
}
};
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename EnableIfInterOperable<T1,T2,bool>::type
operator==(const RandomAccessIteratorFacade<T1,V1,R1,D>& lhs,
const RandomAccessIteratorFacade<T2,V2,R2,D>& rhs)
{
if(std::is_convertible<T2,T1>::value)
return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
else
return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
}
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename EnableIfInterOperable<T1,T2,bool>::type
operator!=(const RandomAccessIteratorFacade<T1,V1,R1,D>& lhs,
const RandomAccessIteratorFacade<T2,V2,R2,D>& rhs)
{
if(std::is_convertible<T2,T1>::value)
return !static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
else
return !static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
}
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename EnableIfInterOperable<T1,T2,bool>::type
operator<(const RandomAccessIteratorFacade<T1,V1,R1,D>& lhs,
const RandomAccessIteratorFacade<T2,V2,R2,D>& rhs)
{
if(std::is_convertible<T2,T1>::value)
return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))>0;
else
return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))<0;
}
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename EnableIfInterOperable<T1,T2,bool>::type
operator<=(const RandomAccessIteratorFacade<T1,V1,R1,D>& lhs,
const RandomAccessIteratorFacade<T2,V2,R2,D>& rhs)
{
if(std::is_convertible<T2,T1>::value)
return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))>=0;
else
return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))<=0;
}
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename EnableIfInterOperable<T1,T2,bool>::type
operator>(const RandomAccessIteratorFacade<T1,V1,R1,D>& lhs,
const RandomAccessIteratorFacade<T2,V2,R2,D>& rhs)
{
if(std::is_convertible<T2,T1>::value)
return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))<0;
else
return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))>0;
}
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename EnableIfInterOperable<T1,T2,bool>::type
operator>=(const RandomAccessIteratorFacade<T1,V1,R1,D>& lhs,
const RandomAccessIteratorFacade<T2,V2,R2,D>& rhs)
{
if(std::is_convertible<T2,T1>::value)
return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))<=0;
else
return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))>=0;
}
template<class T1, class V1, class R1, class D,
class T2, class V2, class R2>
constexpr typename EnableIfInterOperable<T1,T2,D>::type
operator-(const RandomAccessIteratorFacade<T1,V1,R1,D>& lhs,
const RandomAccessIteratorFacade<T2,V2,R2,D>& rhs)
{
if(std::is_convertible<T2,T1>::value)
return -static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs));
else
return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs));
}
template<class ProxyType>
class ProxyArrowResult
{
public:
constexpr ProxyArrowResult(ProxyType&& p)
noexcept(std::is_nothrow_constructible_v<ProxyType, ProxyType&&>)
: p_(std::move(p))
{}
constexpr ProxyArrowResult(const ProxyType& p)
noexcept(std::is_nothrow_constructible_v<ProxyType, const ProxyType&>)
: p_(p)
{}
constexpr const ProxyType* operator->() const noexcept
{
return &p_;
}
constexpr ProxyType* operator->() noexcept
{
return &p_;
}
private:
ProxyType p_;
};
struct IteratorFacadeAccess
{
template<class It>
static constexpr auto baseIterator(It&& it) noexcept
-> decltype(it.baseIterator())
{
return it.baseIterator();
}
template<class It>
static constexpr auto derived(It&& it) noexcept
-> decltype(it.derived())
{
return it.derived();
}
};
namespace Impl::Concepts {
using namespace Dune::Concept;
template<class R>
struct BaseIterDereferenceOp
{
template<class It>
auto require(const It& it) -> decltype(
*(IteratorFacadeAccess::baseIterator(it)),
requireConvertible<decltype(*(IteratorFacadeAccess::baseIterator(it))), R>()
);
};
struct IterEqualsOp
{
template<class It1, class It2>
auto require(const It1& it1, const It2& it2) -> decltype(
requireConvertible<bool>(it1 == it2)
);
};
struct BaseIterEqualsOp
{
template<class It1, class It2>
auto require(const It1& it1, const It2& it2) -> decltype(
Dune::Concept::requireConvertible<bool>(IteratorFacadeAccess::baseIterator(it1) == IteratorFacadeAccess::baseIterator(it2))
);
};
struct BaseIterIncrementOp
{
template<class It>
auto require(It it) -> decltype(
++(IteratorFacadeAccess::baseIterator(it))
);
};
struct BaseIterDecrementOp
{
template<class It>
auto require(It it) -> decltype(
--(IteratorFacadeAccess::baseIterator(it))
);
};
template<class D>
struct IterAdvanceOp
{
template<class It>
auto require(It it) -> decltype(
it += std::declval<D>()
);
};
template<class D>
struct BaseIterAdvanceOp
{
template<class It>
auto require(It it) -> decltype(
IteratorFacadeAccess::baseIterator(it) += std::declval<D>()
);
};
template<class D>
struct IterDistanceOp
{
template<class It1, class It2>
auto require(const It1& it1, const It2& it2) -> decltype(
Dune::Concept::requireConvertible<D>(it1 - it2)
);
};
template<class D>
struct BaseIterDistanceOp
{
template<class It1, class It2>
auto require(const It1& it1, const It2& it2) -> decltype(
Dune::Concept::requireConvertible<D>(IteratorFacadeAccess::baseIterator(it1) - IteratorFacadeAccess::baseIterator(it2))
);
};
} // namespace Impl::Concept
template<class It, class C, class V, class R = V&, class P = V*, class D = std::ptrdiff_t>
class IteratorFacade
{
static constexpr bool isBidirectional = std::is_convertible_v<C, std::bidirectional_iterator_tag>;
static constexpr bool isRandomAccess = std::is_convertible_v<C, std::random_access_iterator_tag>;
// We make IteratorFacadeAccess a friend to allow forwarding of the derived()
// methods to the free operators instead of havin to do raw casts there.
// This allows to encapsulate all casts within IteratorFacade itself.
friend IteratorFacadeAccess;
protected:
using DerivedIterator = It;
constexpr const DerivedIterator& derived() const
{
return static_cast<const DerivedIterator&>(*this);
}
constexpr DerivedIterator& derived()
{
return static_cast<DerivedIterator&>(*this);
}
public:
// Standard types of of C++ iterators
using iterator_category = C;
using value_type = typename std::remove_const<V>::type;
using reference = R;
using pointer = P;
using difference_type = D;
// Corresponding Dune typedefs
using Value = value_type;
using Reference = reference;
using Pointer = pointer;
using DifferenceType = difference_type;
// Only defined to do static assertions.
IteratorFacade()
{
static_assert(std::is_signed_v<difference_type>,
"Type used as difference_type must be signed");
const DerivedIterator& constDerived = derived();
static_assert(std::is_convertible_v<decltype(*constDerived), reference>,
"Derived class does not implement `*it` or `*(it.baseIterator())` for const `it` required by IteratorFacade<..., std::forward_iterator_tag, ...>.");
static_assert(std::is_convertible_v<decltype(++derived()), DerivedIterator&>,
"Derived class does not implement `++it`, `++(it.baseIterator())`, or `it+=1` for mutable `it` required by IteratorFacade<..., std::forward_iterator_tag, ...>.");
static_assert(std::is_convertible_v<decltype(constDerived==constDerived), bool>,
"Derived class does not implement `it1==it2` or `it1.baseIterator()==it2.baseIterator()` for const `it1` and `it2` required by IteratorFacade<..., std::forward_iterator_tag, ...>.");
if constexpr (isBidirectional)
static_assert(std::is_convertible_v<decltype(--derived()), DerivedIterator&>,
"Derived class does not implement `--it`, `--(it.baseIterator())`, or `it-=1` for mutable `it` required by IteratorFacade<..., std::bidirectional_iterator_tag, ...>.");
if constexpr (isRandomAccess)
{
static_assert(std::is_convertible_v<decltype(derived()+=std::declval<difference_type>()), DerivedIterator&>,
"Derived class does not implement `it+=` or `it.baseIterator()+=` for mutable `it` required by IteratorFacade<..., std::random_access_iterator_tag, ...>.");
static_assert(std::is_convertible_v<decltype(constDerived-constDerived), difference_type>,
"Derived class does not implement `it1-it2` or `it1.baseIterator()-it2.baseIterator()` for const `it1` and `it2` required by IteratorFacade<..., std::random_access_iterator_tag, ...>.");
}
}
constexpr decltype(auto) operator*() const
{
if constexpr (Dune::models<Impl::Concepts::BaseIterDereferenceOp<reference>, DerivedIterator>())
return *(IteratorFacadeAccess::baseIterator(derived()));
else
static_assert(AlwaysFalse<It>::value,
"Derived class does not implement `*it` or `*(it.baseIterator())` for const `it` required by IteratorFacade<..., std::forward_iterator_tag, ...>.");
}
constexpr pointer operator->() const
{
if constexpr (std::is_pointer_v<pointer>)
return std::addressof(*derived());
else
return pointer(*derived());
}
constexpr decltype(auto) operator++()
{
if constexpr (Dune::models<Impl::Concepts::BaseIterIncrementOp, DerivedIterator>())
{
++(IteratorFacadeAccess::baseIterator(derived()));
return derived();
}
else if constexpr (Dune::models<Impl::Concepts::IterAdvanceOp<difference_type>, DerivedIterator>())
{
derived() += 1;
return derived();
}
else
static_assert(AlwaysFalse<It>::value,
"Derived class does not implement `++it`, `++(it.baseIterator())`, or `it+=1` for mutable `it` required by IteratorFacade<..., std::forward_iterator_tag, ...>.");
}
constexpr DerivedIterator operator++(int)
{
DerivedIterator tmp(derived());
++derived();
return tmp;
}
template<bool dummy=true, std::enable_if_t<isBidirectional and dummy, int> =0>
constexpr decltype(auto) operator--()
{
if constexpr (Dune::models<Impl::Concepts::BaseIterDecrementOp, DerivedIterator>())
{
--(IteratorFacadeAccess::baseIterator(derived()));
return derived();
}
else if constexpr (Dune::models<Impl::Concepts::IterAdvanceOp<difference_type>, DerivedIterator>())
{
derived() -= 1;
return derived();
}
else
static_assert(AlwaysFalse<It>::value,
"Derived class does not implement `--it`, `--(it.baseIterator())`, or `it-=1` for mutable `it` required by IteratorFacade<..., std::bidirectional_iterator_tag, ...>.");
}
template<bool dummy=true, std::enable_if_t<isBidirectional and dummy, int> =0>
constexpr DerivedIterator operator--(int)
{
DerivedIterator tmp(derived());
--derived();
return tmp;
}
template<bool dummy=true, std::enable_if_t<isRandomAccess and dummy, int> =0>
constexpr reference operator[](difference_type n) const
{
return *(derived()+n);
}
template<bool dummy=true, std::enable_if_t<isRandomAccess and dummy, int> =0>
constexpr decltype(auto) operator+=(difference_type n)
{
if constexpr (Dune::models<Impl::Concepts::BaseIterAdvanceOp<difference_type>, DerivedIterator>())
{
IteratorFacadeAccess::baseIterator(derived()) += n;
return derived();
}
else
static_assert(AlwaysFalse<It>::value,
"Derived class does not implement `it+=` or `it.baseIterator()+=` for mutable `it` required by IteratorFacade<..., std::random_access_iterator_tag, ...>.");
}
template<bool dummy=true, std::enable_if_t<isRandomAccess and dummy, int> =0>
constexpr DerivedIterator operator+(difference_type n) const
{
DerivedIterator tmp(derived());
tmp += n;
return tmp;
}
template<bool dummy=true, std::enable_if_t<isRandomAccess and dummy, int> =0>
friend constexpr DerivedIterator operator+(difference_type n, const IteratorFacade& it)
{
DerivedIterator tmp(it.derived());
tmp += n;
return tmp;
}
template<bool dummy=true, std::enable_if_t<isRandomAccess and dummy, int> =0>
constexpr DerivedIterator& operator-=(difference_type n)
{
derived() += (-n);
return derived();
}
template<bool dummy=true, std::enable_if_t<isRandomAccess and dummy, int> =0>
constexpr DerivedIterator operator-(difference_type n) const
{
DerivedIterator tmp(derived());
tmp -= n;
return tmp;
}
};
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 operator==(const IteratorFacade<T1,C,V1,R1,P1,D1>& it1, const IteratorFacade<T2,C,V2,R2,P2,D2>& it2)
{
const T1& derivedIt1 = IteratorFacadeAccess::derived(it1);
const T2& derivedIt2 = IteratorFacadeAccess::derived(it2);
if constexpr (Dune::models<Impl::Concepts::BaseIterEqualsOp, T1, T2>())
return IteratorFacadeAccess::baseIterator(derivedIt1) == IteratorFacadeAccess::baseIterator(derivedIt2);
else
static_assert(AlwaysFalse<T1>::value,
"Derived class does not implement `it1==it2` or `it1.baseIterator()==it2.baseIterator()` for const `it1` and `it2` required by IteratorFacade<..., std::forward_iterator_tag, ...>.");
}
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 operator!=(const IteratorFacade<T1,C,V1,R1,P1,D1>& it1, const IteratorFacade<T2,C,V2,R2,P2,D2>& it2)
{
const T1& derivedIt1 = IteratorFacadeAccess::derived(it1);
const T2& derivedIt2 = IteratorFacadeAccess::derived(it2);
return not(derivedIt1 == derivedIt2);
}
template<class T1, class T2, class C, class V1, class V2, class R1, class R2, class P1, class P2, class D>
constexpr auto operator-(const IteratorFacade<T1,C,V1,R1,P1,D>& it1, const IteratorFacade<T2,C,V2,R2,P2,D>& it2)
{
const T1& derivedIt1 = IteratorFacadeAccess::derived(it1);
const T2& derivedIt2 = IteratorFacadeAccess::derived(it2);
if constexpr (Dune::models<Impl::Concepts::BaseIterDistanceOp<D>,T1, T2>())
return D(IteratorFacadeAccess::baseIterator(derivedIt1) - IteratorFacadeAccess::baseIterator(derivedIt2));
else
static_assert(AlwaysFalse<T1>::value,
"Derived class does not implement `it1-it2` or `it1.baseIterator()-it2.baseIterator()` for const `it1` and `it2` required by IteratorFacade<..., std::random_access_iterator_tag, ...>.");
}
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 operator<(const IteratorFacade<T1,C,V1,R1,P1,D1>& it1, const IteratorFacade<T2,C,V2,R2,P2,D2>& it2)
{
const T1& derivedIt1 = IteratorFacadeAccess::derived(it1);
const T2& derivedIt2 = IteratorFacadeAccess::derived(it2);
return (derivedIt1 - derivedIt2) < D1(0);
}
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 operator<=(const IteratorFacade<T1,C,V1,R1,P1,D1>& it1, const IteratorFacade<T2,C,V2,R2,P2,D2>& it2)
{
const T1& derivedIt1 = IteratorFacadeAccess::derived(it1);
const T2& derivedIt2 = IteratorFacadeAccess::derived(it2);
return (derivedIt1 - derivedIt2) <= D1(0);
}
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 operator>(const IteratorFacade<T1,C,V1,R1,P1,D1>& it1, const IteratorFacade<T2,C,V2,R2,P2,D2>& it2)
{
const T1& derivedIt1 = IteratorFacadeAccess::derived(it1);
const T2& derivedIt2 = IteratorFacadeAccess::derived(it2);
return (derivedIt1 - derivedIt2) > D1(0);
}
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 operator>=(const IteratorFacade<T1,C,V1,R1,P1,D1>& it1, const IteratorFacade<T2,C,V2,R2,P2,D2>& it2)
{
const T1& derivedIt1 = IteratorFacadeAccess::derived(it1);
const T2& derivedIt2 = IteratorFacadeAccess::derived(it2);
return (derivedIt1 - derivedIt2) >= D1(0);
}
template<class IteratorImpl, class IteratorTraits>
using IteratorFacadeForTraits = Dune::IteratorFacade<
IteratorImpl,
typename IteratorTraits::iterator_category,
typename IteratorTraits::value_type,
typename IteratorTraits::reference,
typename IteratorTraits::pointer,
typename IteratorTraits::difference_type>;
template<class IteratorCategory, class Reference, class DifferenceType = std::ptrdiff_t>
struct DefaultIteratorTraits
{
using iterator_category = IteratorCategory;
using reference = Reference;
using value_type = Dune::AutonomousValue<reference>;
using pointer = std::conditional_t<std::is_lvalue_reference_v<reference>, value_type*, Dune::ProxyArrowResult<reference>>;
using difference_type = DifferenceType;
};
}
#endif
typetraits.hh
Traits for type conversions and type information.
concept.hh
Infrastructure for concepts.
Dune::AutonomousValue
typename AutonomousValueType< T >::type AutonomousValue
Type free of internal references that T can be converted to.
Definition typetraits.hh:566
Dune::models
constexpr auto models()
Check if concept is modeled by given types.
Definition concept.hh:183
Dune::operator-
bigunsignedint< k > operator-(const bigunsignedint< k > &x, std::uintmax_t y)
Definition bigunsignedint.hh:565
Dune::operator+
bigunsignedint< k > operator+(const bigunsignedint< k > &x, std::uintmax_t y)
Definition bigunsignedint.hh:558
Dune::operator++
constexpr decltype(auto) operator++()
Preincrement operator.
Definition iteratorfacades.hh:1138
Dune::operator>
constexpr EnableIfInterOperable< T1, T2, bool >::type operator>(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition iteratorfacades.hh:684
Dune::operator->
constexpr pointer operator->() const
Arrow access to members of referenced value.
Definition iteratorfacades.hh:1129
Dune::operator[]
constexpr reference operator[](difference_type n) const
Dereference element with given offset form this iterator.
Definition iteratorfacades.hh:1207
Dune::operator<
constexpr EnableIfInterOperable< T1, T2, bool >::type operator<(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition iteratorfacades.hh:638
Dune::operator<=
constexpr EnableIfInterOperable< T1, T2, bool >::type operator<=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition iteratorfacades.hh:661
Dune::operator--
constexpr decltype(auto) operator--()
Predecrement operator.
Definition iteratorfacades.hh:1169
Dune::IteratorFacadeForTraits
Dune::IteratorFacade< IteratorImpl, typename IteratorTraits::iterator_category, typename IteratorTraits::value_type, typename IteratorTraits::reference, typename IteratorTraits::pointer, typename IteratorTraits::difference_type > IteratorFacadeForTraits
Alias for the CRTP-Mixing class IteratorFacade.
Definition iteratorfacades.hh:1435
Dune::operator>=
constexpr EnableIfInterOperable< T1, T2, bool >::type operator>=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition iteratorfacades.hh:706
Dune::operator-=
constexpr DerivedIterator & operator-=(difference_type n)
Decrement iterator by given value.
Definition iteratorfacades.hh:1262
Dune::type
MPI_Datatype MPITraits< ParallelLocalIndex< T > >::type
Definition plocalindex.hh:317
std
STL namespace.
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::operator!=
constexpr auto operator!=(const HybridMultiIndex< S... > &lhs, const HybridMultiIndex< T... > &rhs)
Compare two HybridMultiIndexs for inequality.
Definition hybridmultiindex.hh:441
Dune::operator==
constexpr bool operator==(const HybridMultiIndex< S... > &lhs, const HybridMultiIndex< T... > &rhs)
Compare two HybridMultiIndexs for value equality.
Definition hybridmultiindex.hh:404
Dune::Concept
Namespace for concepts.
Definition concept.hh:33
Dune::Concept::requireConvertible
constexpr bool requireConvertible()
Definition concept.hh:246
Dune::ForwardIteratorFacade
Base class for stl conformant forward iterators.
Definition iteratorfacades.hh:142
Dune::ForwardIteratorFacade::iterator_category
std::forward_iterator_tag iterator_category
Definition iteratorfacades.hh:146
Dune::ForwardIteratorFacade::pointer
V * pointer
Definition iteratorfacades.hh:149
Dune::ForwardIteratorFacade::operator++
constexpr DerivedType & operator++()
Preincrement operator.
Definition iteratorfacades.hh:210
Dune::ForwardIteratorFacade::operator*
constexpr Reference operator*() const
Dereferencing operator.
Definition iteratorfacades.hh:199
Dune::ForwardIteratorFacade::DifferenceType
D DifferenceType
The type of the difference between two positions.
Definition iteratorfacades.hh:191
Dune::ForwardIteratorFacade::Reference
R Reference
The type of the reference to the values accessed.
Definition iteratorfacades.hh:196
Dune::ForwardIteratorFacade::operator++
constexpr DerivedType operator++(int)
Postincrement operator.
Definition iteratorfacades.hh:217
Dune::ForwardIteratorFacade::DerivedType
T DerivedType
The type of derived iterator.
Definition iteratorfacades.hh:176
Dune::ForwardIteratorFacade::Value
V Value
The type of value accessed through the iterator.
Definition iteratorfacades.hh:181
Dune::ForwardIteratorFacade::operator->
constexpr Pointer operator->() const
Definition iteratorfacades.hh:204
Dune::ForwardIteratorFacade::value_type
typename std::remove_const< V >::type value_type
Definition iteratorfacades.hh:147
Dune::ForwardIteratorFacade::Pointer
V * Pointer
The pointer to the Value.
Definition iteratorfacades.hh:186
Dune::ForwardIteratorFacade::difference_type
D difference_type
Definition iteratorfacades.hh:148
Dune::ForwardIteratorFacade::reference
R reference
Definition iteratorfacades.hh:150
Dune::BidirectionalIteratorFacade
Facade class for stl conformant bidirectional iterators.
Definition iteratorfacades.hh:275
Dune::BidirectionalIteratorFacade::pointer
V * pointer
Definition iteratorfacades.hh:282
Dune::BidirectionalIteratorFacade::value_type
typename std::remove_const< V >::type value_type
Definition iteratorfacades.hh:280
Dune::BidirectionalIteratorFacade::difference_type
D difference_type
Definition iteratorfacades.hh:281
Dune::BidirectionalIteratorFacade::operator*
constexpr Reference operator*() const
Dereferencing operator.
Definition iteratorfacades.hh:333
Dune::BidirectionalIteratorFacade::operator->
constexpr Pointer operator->() const
Definition iteratorfacades.hh:338
Dune::BidirectionalIteratorFacade::DerivedType
T DerivedType
The type of derived iterator.
Definition iteratorfacades.hh:310
Dune::BidirectionalIteratorFacade::operator++
constexpr DerivedType & operator++()
Preincrement operator.
Definition iteratorfacades.hh:344
Dune::BidirectionalIteratorFacade::Pointer
V * Pointer
The pointer to the Value.
Definition iteratorfacades.hh:320
Dune::BidirectionalIteratorFacade::Reference
R Reference
The type of the reference to the values accessed.
Definition iteratorfacades.hh:330
Dune::BidirectionalIteratorFacade::operator--
constexpr DerivedType operator--(int)
Postincrement operator.
Definition iteratorfacades.hh:367
Dune::BidirectionalIteratorFacade::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition iteratorfacades.hh:279
Dune::BidirectionalIteratorFacade::DifferenceType
D DifferenceType
The type of the difference between two positions.
Definition iteratorfacades.hh:325
Dune::BidirectionalIteratorFacade::reference
R reference
Definition iteratorfacades.hh:283
Dune::BidirectionalIteratorFacade::operator++
constexpr DerivedType operator++(int)
Postincrement operator.
Definition iteratorfacades.hh:351
Dune::BidirectionalIteratorFacade::operator--
constexpr DerivedType & operator--()
Preincrement operator.
Definition iteratorfacades.hh:360
Dune::BidirectionalIteratorFacade::Value
V Value
The type of value accessed through the iterator.
Definition iteratorfacades.hh:315
Dune::RandomAccessIteratorFacade
Base class for stl conformant forward iterators.
Definition iteratorfacades.hh:435
Dune::RandomAccessIteratorFacade::value_type
typename std::remove_const< V >::type value_type
Definition iteratorfacades.hh:440
Dune::RandomAccessIteratorFacade::difference_type
D difference_type
Definition iteratorfacades.hh:441
Dune::RandomAccessIteratorFacade::operator[]
constexpr Reference operator[](DifferenceType n) const
Get the element n positions from the current one.
Definition iteratorfacades.hh:516
Dune::RandomAccessIteratorFacade::operator->
constexpr Pointer operator->() const
Definition iteratorfacades.hh:506
Dune::RandomAccessIteratorFacade::pointer
V * pointer
Definition iteratorfacades.hh:442
Dune::RandomAccessIteratorFacade::iterator_category
std::random_access_iterator_tag iterator_category
Definition iteratorfacades.hh:439
Dune::RandomAccessIteratorFacade::operator--
constexpr DerivedType & operator--()
Predecrement operator.
Definition iteratorfacades.hh:551
Dune::RandomAccessIteratorFacade::reference
R reference
Definition iteratorfacades.hh:443
Dune::RandomAccessIteratorFacade::DifferenceType
D DifferenceType
The type of the difference between two positions.
Definition iteratorfacades.hh:493
Dune::RandomAccessIteratorFacade::operator++
constexpr DerivedType operator++(int)
Postincrement operator.
Definition iteratorfacades.hh:529
Dune::RandomAccessIteratorFacade::operator+=
constexpr DerivedType & operator+=(DifferenceType n)
Definition iteratorfacades.hh:536
Dune::RandomAccessIteratorFacade::operator--
constexpr DerivedType operator--(int)
Postdecrement operator.
Definition iteratorfacades.hh:558
Dune::RandomAccessIteratorFacade::operator-
constexpr DerivedType operator-(DifferenceType n) const
Definition iteratorfacades.hh:571
Dune::RandomAccessIteratorFacade::DerivedType
T DerivedType
The type of derived iterator.
Definition iteratorfacades.hh:478
Dune::RandomAccessIteratorFacade::Pointer
V * Pointer
The pointer to the Value.
Definition iteratorfacades.hh:488
Dune::RandomAccessIteratorFacade::Value
V Value
The type of value accessed through the iterator.
Definition iteratorfacades.hh:483
Dune::RandomAccessIteratorFacade::operator-=
constexpr DerivedType & operator-=(DifferenceType n)
Definition iteratorfacades.hh:565
Dune::RandomAccessIteratorFacade::operator*
constexpr Reference operator*() const
Dereferencing operator.
Definition iteratorfacades.hh:501
Dune::RandomAccessIteratorFacade::operator++
constexpr DerivedType & operator++()
Preincrement operator.
Definition iteratorfacades.hh:522
Dune::RandomAccessIteratorFacade::operator+
constexpr DerivedType operator+(DifferenceType n) const
Definition iteratorfacades.hh:542
Dune::RandomAccessIteratorFacade::Reference
R Reference
The type of the reference to the values accessed.
Definition iteratorfacades.hh:498
Dune::ProxyArrowResult
Helper to mimic a pointer for proxy objects.
Definition iteratorfacades.hh:750
Dune::ProxyArrowResult::ProxyArrowResult
constexpr ProxyArrowResult(const ProxyType &p) noexcept(std::is_nothrow_constructible_v< ProxyType, const ProxyType & >)
Definition iteratorfacades.hh:757
Dune::ProxyArrowResult::operator->
constexpr ProxyType * operator->() noexcept
Definition iteratorfacades.hh:767
Dune::ProxyArrowResult::operator->
constexpr const ProxyType * operator->() const noexcept
Definition iteratorfacades.hh:762
Dune::ProxyArrowResult::ProxyArrowResult
constexpr ProxyArrowResult(ProxyType &&p) noexcept(std::is_nothrow_constructible_v< ProxyType, ProxyType && >)
Definition iteratorfacades.hh:752
Dune::IteratorFacadeAccess
This class encapsulates access of IteratorFacade.
Definition iteratorfacades.hh:786
Dune::DefaultIteratorTraits
An iterator_traits class providing sensible defaults.
Definition iteratorfacades.hh:1460
Dune::DefaultIteratorTraits::iterator_category
IteratorCategory iterator_category
Definition iteratorfacades.hh:1461
Dune::DefaultIteratorTraits::reference
Reference reference
Definition iteratorfacades.hh:1462
Dune::DefaultIteratorTraits::value_type
Dune::AutonomousValue< reference > value_type
Definition iteratorfacades.hh:1463
Dune::DefaultIteratorTraits::difference_type
DifferenceType difference_type
Definition iteratorfacades.hh:1465
Dune::DefaultIteratorTraits::pointer
std::conditional_t< std::is_lvalue_reference_v< reference >, value_type *, Dune::ProxyArrowResult< reference > > pointer
Definition iteratorfacades.hh:1464
Dune::EnableIfInterOperable
Enable typedef if two types are interoperable.
Definition typetraits.hh:81
Dune::AlwaysFalse
template which always yields a false value
Definition typetraits.hh:124