15 #ifndef BELUGA_VIEWS_TAKE_EVENLY_HPP
16 #define BELUGA_VIEWS_TAKE_EVENLY_HPP
20 #include <range/v3/view/cache1.hpp>
21 #include <range/v3/view/enumerate.hpp>
22 #include <range/v3/view/filter.hpp>
45 template <
class Range>
46 constexpr
auto operator()(Range&& range, std::size_t count)
const {
47 const std::size_t size = ranges::size(range);
49 const auto filter_function = [size, count](
const auto& pair) {
50 if ((size == 0UL) || (count == 0UL)) {
58 const auto [index, _] = pair;
63 if ((index == 0UL) || (index == size - 1UL)) {
67 const std::size_t m0 = (index - 1UL) * (count - 1UL) / (size - 1UL);
68 const std::size_t m1 = index * (count - 1UL) / (size - 1UL);
74 return ranges::views::enumerate(range) | ranges::views::cache1 | ranges::views::filter(filter_function) |
75 beluga::views::elements<1>;
87 return ranges::make_view_closure(ranges::bind_back(
take_evenly_fn{}, count));