63 T operator()(
const T& _t)
const {
return _t; }
69 template <
typename RangeT,
typename HandleT>
80 template <
typename Functor>
81 auto sum(Functor&& f) ->
typename std::decay<decltype (f(std::declval<HandleT>()))>::type
83 auto range =
static_cast<const RangeT*
>(
this);
84 auto begin = range->begin();
85 auto end = range->end();
87 typename std::decay<decltype (f(*begin))>::type result = f(*begin);
90 for (; it != end; ++it)
101 template <
typename Functor>
102 auto avg(Functor&& f) ->
typename std::decay<decltype (f(std::declval<HandleT>()))>::type
104 auto range =
static_cast<const RangeT*
>(
this);
105 auto begin = range->begin();
106 auto end = range->end();
107 assert(begin != end);
108 typename std::decay<decltype (f(*begin))>::type result = f(*begin);
112 for (; it != end; ++it)
117 return (1.0 / n_elements) * result;
127 template <
typename Functor>
130 auto range =
static_cast<const RangeT*
>(
this);
131 for (
auto e : *range)
144 template <
typename Functor>
147 auto range =
static_cast<const RangeT*
>(
this);
148 for (
auto e : *range)
163 template <
int n,
typename Functor = Identity>
164 auto to_array(Functor&& f = {}) -> std::array<
typename std::decay<decltype (f(std::declval<HandleT>()))>::type, n>
166 auto range =
static_cast<const RangeT*
>(
this);
167 std::array<typename std::decay<decltype (f(std::declval<HandleT>()))>::type, n> res;
168 auto it = range->begin();
169 auto end = range->end();
171 while (i < n && it != end)
172 res[i++] = f(*(it++));
183 template <
typename Functor = Identity>
184 auto to_vector(Functor&& f = {}) -> std::vector<
typename std::decay<decltype (f(std::declval<HandleT>()))>::type>
186 auto range =
static_cast<const RangeT*
>(
this);
187 std::vector<typename std::decay<decltype (f(std::declval<HandleT>()))>::type> res;
188 for (
const auto& e : *range)
200 template <
typename Functor = Identity>
201 auto to_set(Functor&& f = {}) -> std::set<
typename std::decay<decltype (f(std::declval<HandleT>()))>::type>
203 auto range =
static_cast<const RangeT*
>(
this);
204 std::set<typename std::decay<decltype (f(std::declval<HandleT>()))>::type> res;
205 for (
const auto& e : *range)
218 template <
typename Functor>
219 auto first(Functor&& f = {}) -> HandleT
221 auto range =
static_cast<const RangeT*
>(
this);
222 for (
const auto& e : *range)
234 template <
typename Functor>
235 auto min(Functor&& f) ->
typename std::decay<decltype (f(std::declval<HandleT>()))>::type
239 auto range =
static_cast<const RangeT*
>(
this);
240 auto it = range->begin();
241 auto end = range->end();
244 typename std::decay<decltype (f(std::declval<HandleT>()))>::type res = f(*it);
247 for (; it != end; ++it)
248 res = min(res, f(*it));
259 template <
typename Functor>
260 auto max(Functor&& f) ->
typename std::decay<decltype (f(std::declval<HandleT>()))>::type
264 auto range =
static_cast<const RangeT*
>(
this);
265 auto it = range->begin();
266 auto end = range->end();
269 typename std::decay<decltype (f(std::declval<HandleT>()))>::type res = f(*it);
272 for (; it != end; ++it)
273 res = max(res, f(*it));
285 template <
typename Functor>
286 auto minmax(Functor&& f) -> std::pair<typename std::decay<decltype (f(std::declval<HandleT>()))>::type,
287 typename std::decay<decltype (f(std::declval<HandleT>()))>::type>
289 return std::make_pair(this->min(f), this->max(f));
auto to_vector(Functor &&f={}) -> std::vector< typename std::decay< decltype(f(std::declval< HandleT >()))>::type >
Convert range to vector.
auto any_of(Functor &&f) -> bool
Check if any element fulfils condition.
Base class for all smart range types.
auto min(Functor &&f) -> typename std::decay< decltype(f(std::declval< HandleT >()))>::type
Compute minimum.
auto first(Functor &&f={}) -> HandleT
Get the first element that fulfills a condition.
auto max(Functor &&f) -> typename std::decay< decltype(f(std::declval< HandleT >()))>::type
Compute maximum.
auto minmax(Functor &&f) -> std::pair< typename std::decay< decltype(f(std::declval< HandleT >()))>::type, typename std::decay< decltype(f(std::declval< HandleT >()))>::type >
Computes minimum and maximum.
auto sum(Functor &&f) -> typename std::decay< decltype(f(std::declval< HandleT >()))>::type
Computes the sum of elements.
auto to_array(Functor &&f={}) -> std::array< typename std::decay< decltype(f(std::declval< HandleT >()))>::type, n >
Convert range to array.
auto to_set(Functor &&f={}) -> std::set< typename std::decay< decltype(f(std::declval< HandleT >()))>::type >
Convert range to set.
auto all_of(Functor &&f) -> bool
Check if all elements fulfil condition.
auto avg(Functor &&f) -> typename std::decay< decltype(f(std::declval< HandleT >()))>::type
Computes the average of elements.