Dune Core Modules (2.5.0)

rangeutilities.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_COMMON_RANGE_UTILITIES_HH
4#define DUNE_COMMON_RANGE_UTILITIES_HH
5
7#include <algorithm>
8#include <utility>
9#include <type_traits>
10#include <bitset>
11
23namespace Dune
24{
30 template <typename T,
31 typename std::enable_if<is_range<T>::value, int>::type = 0>
32 typename T::value_type
33 max_value(const T & v) {
34 using std::max_element;
35 return *max_element(v.begin(), v.end());
36 }
37
38 template <typename T,
39 typename std::enable_if<!is_range<T>::value, int>::type = 0>
40 const T & max_value(const T & v) { return v; }
41
47 template <typename T,
48 typename std::enable_if<is_range<T>::value, int>::type = 0>
49 typename T::value_type
50 min_value(const T & v) {
51 using std::min_element;
52 return *min_element(v.begin(), v.end());
53 }
54
55 template <typename T,
56 typename std::enable_if<!is_range<T>::value, int>::type = 0>
57 const T & min_value(const T & v) { return v; }
58
64 template <typename T,
65 typename std::enable_if<is_range<T>::value, int>::type = 0>
66 bool any_true(const T & v) {
67 bool b = false;
68 for (const auto & e : v)
69 b = b or bool(e);
70 return b;
71 }
72
73 template <typename T,
74 typename std::enable_if<!is_range<T>::value, int>::type = 0>
75 bool any_true(const T & v) { return v; }
76
77 template<std::size_t N>
78 bool any_true(const std::bitset<N> & b)
79 {
80 return b.any();
81 }
82
88 template <typename T,
89 typename std::enable_if<is_range<T>::value, int>::type = 0>
90 bool all_true(const T & v) {
91 bool b = true;
92 for (const auto & e : v)
93 b = b and bool(e);
94 return b;
95 }
96
97 template <typename T,
98 typename std::enable_if<!is_range<T>::value, int>::type = 0>
99 bool all_true(const T & v) { return v; }
100
101 template<std::size_t N>
102 bool all_true(const std::bitset<N> & b)
103 {
104 return b.all();
105 }
106
107}
108
109#endif // DUNE_COMMON_RANGE_UTILITIES_HH
bool any_true(const T &v)
similar to std::bitset<N>::any() return true, if any entries is true
Definition: rangeutilities.hh:66
bool all_true(const T &v)
similar to std::bitset<N>::all() return true, if any entries is true
Definition: rangeutilities.hh:90
T::value_type min_value(const T &v)
compute the minimum value over a range
Definition: rangeutilities.hh:50
T::value_type max_value(const T &v)
compute the maximum value over a range
Definition: rangeutilities.hh:33
Dune namespace.
Definition: alignment.hh:11
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)