3 #ifndef DUNE_COMMON_RANGE_UTILITIES_HH 4 #define DUNE_COMMON_RANGE_UTILITIES_HH 31 typename std::enable_if<is_range<T>::value,
int>::type = 0>
32 typename T::value_type
34 using std::max_element;
35 return *max_element(v.begin(), v.end());
39 typename std::enable_if<!is_range<T>::value,
int>::type = 0>
48 typename std::enable_if<is_range<T>::value,
int>::type = 0>
49 typename T::value_type
51 using std::min_element;
52 return *min_element(v.begin(), v.end());
56 typename std::enable_if<!is_range<T>::value,
int>::type = 0>
65 typename std::enable_if<is_range<T>::value,
int>::type = 0>
68 for (
const auto & e : v)
74 typename std::enable_if<!is_range<T>::value,
int>::type = 0>
75 bool any_true(
const T & v) {
return v; }
77 template<std::
size_t N>
89 typename std::enable_if<is_range<T>::value,
int>::type = 0>
92 for (
const auto & e : v)
98 typename std::enable_if<!is_range<T>::value,
int>::type = 0>
99 bool all_true(
const T & v) {
return v; }
101 template<std::
size_t N>
113 class IntegralRangeIterator
116 typedef std::random_access_iterator_tag iterator_category;
117 typedef T value_type;
118 typedef std::make_signed_t<T> difference_type;
119 typedef const T *pointer;
122 constexpr IntegralRangeIterator() noexcept =
default;
123 constexpr
explicit IntegralRangeIterator(value_type value) noexcept : value_(value) {}
125 pointer operator->()
const noexcept {
return &value_; }
126 constexpr reference
operator*()
const noexcept {
return value_; }
128 constexpr reference operator[]( difference_type n )
const noexcept {
return (value_ + n); }
130 constexpr
bool operator==(
const IntegralRangeIterator & other)
const noexcept {
return (value_ == other.value_); }
131 constexpr
bool operator!=(
const IntegralRangeIterator & other)
const noexcept {
return (value_ != other.value_); }
133 constexpr
bool operator<(
const IntegralRangeIterator & other)
const noexcept {
return (value_ <= other.value_); }
134 constexpr
bool operator<=(
const IntegralRangeIterator & other)
const noexcept {
return (value_ <= other.value_); }
135 constexpr
bool operator>(
const IntegralRangeIterator & other)
const noexcept {
return (value_ >= other.value_); }
136 constexpr
bool operator>=(
const IntegralRangeIterator & other)
const noexcept {
return (value_ >= other.value_); }
138 IntegralRangeIterator& operator++() noexcept { ++value_;
return *
this; }
139 IntegralRangeIterator operator++(
int) noexcept { IntegralRangeIterator copy( *
this ); ++(*this);
return copy; }
141 IntegralRangeIterator& operator--() noexcept { --value_;
return *
this; }
142 IntegralRangeIterator operator--(
int) noexcept { IntegralRangeIterator copy( *
this ); --(*this);
return copy; }
144 IntegralRangeIterator& operator+=(difference_type n) noexcept { value_ += n;
return *
this; }
145 IntegralRangeIterator& operator-=(difference_type n) noexcept { value_ -= n;
return *
this; }
147 friend constexpr IntegralRangeIterator
operator+(
const IntegralRangeIterator &a, difference_type n) noexcept {
return IntegralRangeIterator(a.value_ + n); }
148 friend constexpr IntegralRangeIterator
operator+(difference_type n,
const IntegralRangeIterator &a) noexcept {
return IntegralRangeIterator(a.value_ + n); }
149 friend constexpr IntegralRangeIterator
operator-(
const IntegralRangeIterator &a, difference_type n) noexcept {
return IntegralRangeIterator(a.value_ - n); }
151 constexpr difference_type
operator-(
const IntegralRangeIterator &other)
const noexcept {
return (static_cast<difference_type>(value_) - static_cast<difference_type>(other.value_)); }
181 constexpr
IntegralRange(value_type from, value_type to) noexcept : from_(from), to_(to) {}
183 constexpr
explicit IntegralRange(value_type to) noexcept : from_(0), to_(to) {}
188 constexpr iterator
begin() const noexcept {
return iterator(from_); }
190 constexpr iterator
end() const noexcept {
return iterator(to_); }
193 constexpr value_type
operator[](
const value_type &i)
const noexcept {
return (from_ + i); }
196 constexpr
bool empty() const noexcept {
return (from_ == to_); }
198 constexpr size_type
size() const noexcept {
return (static_cast<size_type>(to_) - static_cast<size_type>(from_)); }
201 value_type from_, to_;
219 template <
class T, T to, T from = 0>
222 template <T ofs, T... i>
223 static std::integer_sequence<T, (i+ofs)...> shift_integer_sequence(std::integer_sequence<T, i...>);
234 typedef decltype(shift_integer_sequence<from>(std::make_integer_sequence<T, to-from>())) integer_sequence;
242 constexpr
operator integer_sequence() const noexcept {
return {}; }
245 static constexpr iterator
begin() noexcept {
return iterator(from); }
247 static constexpr iterator
end() noexcept {
return iterator(to); }
250 template <
class U, U i>
251 constexpr
auto operator[](
const std::integral_constant<U, i> &)
const noexcept
252 -> std::integral_constant<value_type, from + static_cast<value_type>(i)>
258 constexpr value_type
operator[](
const size_type &i)
const noexcept {
return (from + static_cast<value_type>(i)); }
261 static constexpr std::integral_constant<bool, from == to>
empty() noexcept {
return {}; }
263 static constexpr std::integral_constant<size_type, static_cast<size_type>(to) - static_cast<size_type>(from) >
size() noexcept {
return {}; }
275 template<
class T,
class U,
276 std::enable_if_t<std::is_same<std::decay_t<T>, std::decay_t<U>>::value,
int> = 0,
277 std::enable_if_t<std::is_integral<std::decay_t<T>>::value,
int> = 0>
283 template<
class T, std::enable_if_t<std::is_
integral<std::decay_t<T>>::value,
int> = 0>
289 template<
class T, T from, T to>
295 template<
class T, T to>
303 #endif // DUNE_COMMON_RANGE_UTILITIES_HH constexpr value_type operator[](const size_type &i) const noexcept
access specified element (dynamic version)
Definition: rangeutilities.hh:258
constexpr IntegralRange(std::pair< value_type, value_type > range) noexcept
construct integer range std::pair
Definition: rangeutilities.hh:185
std::make_unsigned_t< T > size_type
unsigned integer type corresponding to value_type
Definition: rangeutilities.hh:231
dynamic integer range for use in range-based for loops
Definition: rangeutilities.hh:170
bigunsignedint< k > operator-(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:536
constexpr iterator end() const noexcept
obtain a random-access iterator past the last element
Definition: rangeutilities.hh:190
constexpr IntegralRange(value_type to) noexcept
construct integer range [0, to)
Definition: rangeutilities.hh:183
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:652
constexpr value_type operator[](const value_type &i) const noexcept
access specified element
Definition: rangeutilities.hh:193
bool any_true(const AlignedNumber< bool, align > &val)
Definition: debugalign.hh:403
static constexpr iterator begin() noexcept
obtain a random-access iterator to the first element
Definition: rangeutilities.hh:245
T min_value(const AlignedNumber< T, align > &val)
Definition: debugalign.hh:397
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:233
static StaticIntegralRange< T, to, from > range(std::integral_constant< T, from >, std::integral_constant< T, to >) noexcept
Definition: rangeutilities.hh:290
Impl::IntegralRangeIterator< T > iterator
type of iterator
Definition: rangeutilities.hh:229
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:629
constexpr size_type size() const noexcept
obtain number of elements in the range
Definition: rangeutilities.hh:198
constexpr auto operator[](const std::integral_constant< U, i > &) const noexcept -> std::integral_constant< value_type, from+static_cast< value_type >(i)>
access specified element (static version)
Definition: rangeutilities.hh:251
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:675
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:255
T max_value(const AlignedNumber< T, align > &val)
Definition: debugalign.hh:391
Impl::IntegralRangeIterator< T > iterator
type of iterator
Definition: rangeutilities.hh:176
Dune namespace.
Definition: alignedallocator.hh:9
static integer range for use in range-based for loops
Definition: rangeutilities.hh:220
bool all_true(const AlignedNumber< bool, align > &val)
Definition: debugalign.hh:409
constexpr IntegralRange(value_type from, value_type to) noexcept
construct integer range [from, to)
Definition: rangeutilities.hh:181
std::make_unsigned_t< T > size_type
unsigned integer type corresponding to value_type
Definition: rangeutilities.hh:178
bigunsignedint< k > operator+(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:529
static constexpr iterator end() noexcept
obtain a random-access iterator past the last element
Definition: rangeutilities.hh:247
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:697
constexpr bool empty() const noexcept
check whether the range is empty
Definition: rangeutilities.hh:196
static constexpr std::integral_constant< size_type, static_cast< size_type >to) - static_cast< size_type >from) > size() noexcept
obtain number of elements in the range
Definition: rangeutilities.hh:263
T value_type
type of integers contained in the range
Definition: rangeutilities.hh:227
bigunsignedint< k > operator*(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:543
Traits for type conversions and type information.
constexpr iterator begin() const noexcept
obtain a random-access iterator to the first element
Definition: rangeutilities.hh:188
T value_type
type of integers contained in the range
Definition: rangeutilities.hh:174
static constexpr std::integral_constant< bool, from==to > empty() noexcept
check whether the range is empty
Definition: rangeutilities.hh:261