|
4 | 4 | #include "type.hpp" |
5 | 5 |
|
6 | 6 | namespace ctmd { |
| 7 | + |
| 8 | +template <typename InType, typename... slices_t> |
| 9 | +[[nodiscard]] inline constexpr auto submdspan(InType &&In, |
| 10 | + slices_t &&...slices) noexcept { |
| 11 | + return std::experimental::submdspan( |
| 12 | + core::to_mdspan(std::forward<InType>(In)), |
| 13 | + std::forward<slices_t>(slices)...); |
| 14 | +} |
| 15 | + |
7 | 16 | namespace core { |
8 | 17 |
|
9 | | -template <size_t lspace, size_t rspace, mdspan_c in_t, typename... slices_t> |
| 18 | +template <size_t lspace, size_t rspace, typename InType, typename... slices_t> |
10 | 19 | [[nodiscard]] inline constexpr auto |
11 | | -submdspan_with_space(const in_t &in, slices_t &&...slices) noexcept { |
12 | | - static_assert(in_t::rank() == lspace + sizeof...(slices_t) + rspace, |
13 | | - "The number of slices must match the rank of the input " |
14 | | - "mdspan."); |
15 | | - |
| 20 | +submdspan_with_space(InType &&In, slices_t &&...slices) noexcept { |
16 | 21 | return [&]<size_t... Is, size_t... Js>(std::index_sequence<Is...>, |
17 | 22 | std::index_sequence<Js...>) { |
18 | | - return ctmd::submdspan(in, ((void)Is, ctmd::full_extent)..., |
| 23 | + return ctmd::submdspan(std::forward<InType>(In), |
| 24 | + ((void)Is, ctmd::full_extent)..., |
19 | 25 | std::forward<slices_t>(slices)..., |
20 | 26 | ((void)Js, ctmd::full_extent)...); |
21 | 27 | }(std::make_index_sequence<lspace>{}, std::make_index_sequence<rspace>{}); |
22 | 28 | } |
23 | 29 |
|
24 | | -template <size_t lspace, size_t rspace, typename InType, typename... slices_t> |
25 | | -[[nodiscard]] inline constexpr auto |
26 | | -submdspan_with_space(InType &&In, slices_t &&...slices) noexcept { |
27 | | - const auto in = core::to_mdspan(std::forward<InType>(In)); |
28 | | - |
29 | | - return submdspan_with_space<lspace, rspace>( |
30 | | - in, std::forward<slices_t>(slices)...); |
31 | | -} |
32 | | - |
33 | | -template <size_t lspace = 0, mdspan_c in_t, typename... slices_t> |
34 | | -[[nodiscard]] inline constexpr auto |
35 | | -submdspan_from_left(const in_t &in, slices_t &&...slices) noexcept { |
36 | | - static_assert( |
37 | | - in_t::rank() >= lspace + sizeof...(slices_t), |
38 | | - "The number of slices must not exceed the rank of the input mdspan."); |
39 | | - |
40 | | - constexpr size_t rspace = in_t::rank() - (lspace + sizeof...(slices_t)); |
41 | | - return submdspan_with_space<lspace, rspace>( |
42 | | - in, std::forward<slices_t>(slices)...); |
43 | | -} |
44 | | - |
45 | 30 | template <size_t lspace = 0, typename InType, typename... slices_t> |
46 | 31 | [[nodiscard]] inline constexpr auto |
47 | 32 | submdspan_from_left(InType &&In, slices_t &&...slices) noexcept { |
48 | | - const auto in = core::to_mdspan(std::forward<InType>(In)); |
| 33 | + constexpr size_t rspace = |
| 34 | + to_mdspan_t<InType>::rank() - (lspace + sizeof...(slices_t)); |
49 | 35 |
|
50 | | - return submdspan_from_left<lspace>(in, std::forward<slices_t>(slices)...); |
51 | | -} |
52 | | - |
53 | | -template <size_t rspace = 0, mdspan_c in_t, typename... slices_t> |
54 | | -[[nodiscard]] inline constexpr auto |
55 | | -submdspan_from_right(const in_t &in, slices_t &&...slices) noexcept { |
56 | | - static_assert( |
57 | | - in_t::rank() >= rspace + sizeof...(slices_t), |
58 | | - "The number of slices must not exceed the rank of the input mdspan."); |
59 | | - |
60 | | - constexpr size_t lspace = in_t::rank() - (rspace + sizeof...(slices_t)); |
61 | 36 | return submdspan_with_space<lspace, rspace>( |
62 | | - in, std::forward<slices_t>(slices)...); |
| 37 | + std::forward<InType>(In), std::forward<slices_t>(slices)...); |
63 | 38 | } |
64 | 39 |
|
65 | 40 | template <size_t rspace = 0, typename InType, typename... slices_t> |
66 | 41 | [[nodiscard]] inline constexpr auto |
67 | 42 | submdspan_from_right(InType &&In, slices_t &&...slices) noexcept { |
68 | | - const auto in = core::to_mdspan(std::forward<InType>(In)); |
| 43 | + constexpr size_t lspace = |
| 44 | + to_mdspan_t<InType>::rank() - (rspace + sizeof...(slices_t)); |
69 | 45 |
|
70 | | - return submdspan_from_right<rspace>(in, std::forward<slices_t>(slices)...); |
| 46 | + return submdspan_with_space<lspace, rspace>( |
| 47 | + std::forward<InType>(In), std::forward<slices_t>(slices)...); |
71 | 48 | } |
72 | 49 |
|
73 | 50 | } // namespace core |
|
0 commit comments