Distributed Ranges
Loading...
Searching...
No Matches
standard_views.hpp
1// SPDX-FileCopyrightText: Intel Corporation
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#pragma once
6
7#include <dr/detail/index.hpp>
8#include <dr/detail/segments_tools.hpp>
9#include <dr/sp/distributed_span.hpp>
10#include <dr/sp/views/enumerate.hpp>
11#include <dr/sp/zip_view.hpp>
12#include <dr/views/transform.hpp>
13
14namespace dr::sp {
15
16namespace views {
17
18template <dr::distributed_range R>
19auto slice(R &&r, dr::index<> slice_indices) {
20 return dr::sp::distributed_span(dr::ranges::segments(std::forward<R>(r)))
21 .subspan(slice_indices[0], slice_indices[1] - slice_indices[0]);
22}
23
25public:
26 slice_adaptor_closure(dr::index<> slice_indices) : idx_(slice_indices) {}
27
28 template <rng::random_access_range R> auto operator()(R &&r) const {
29 return slice(std::forward<R>(r), idx_);
30 }
31
32 template <rng::random_access_range R>
33 friend auto operator|(R &&r, const slice_adaptor_closure &closure) {
34 return closure(std::forward<R>(r));
35 }
36
37private:
38 dr::index<> idx_;
39};
40
41inline auto slice(dr::index<> slice_indices) {
42 return slice_adaptor_closure(slice_indices);
43}
44
45} // namespace views
46
47} // namespace dr::sp
Definition: index.hpp:34
Definition: distributed_span.hpp:127
Definition: standard_views.hpp:24