Skip to content

Commit a800e1a

Browse files
authored
Merge pull request #36 from uonrobotics/hotfix-submdspan
Update submdspan.hpp
2 parents 9e363b7 + 2b9d0cf commit a800e1a

File tree

1 file changed

+20
-43
lines changed

1 file changed

+20
-43
lines changed

ctmd/core/submdspan.hpp

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,47 @@
44
#include "type.hpp"
55

66
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+
716
namespace core {
817

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>
1019
[[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 {
1621
return [&]<size_t... Is, size_t... Js>(std::index_sequence<Is...>,
1722
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)...,
1925
std::forward<slices_t>(slices)...,
2026
((void)Js, ctmd::full_extent)...);
2127
}(std::make_index_sequence<lspace>{}, std::make_index_sequence<rspace>{});
2228
}
2329

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-
4530
template <size_t lspace = 0, typename InType, typename... slices_t>
4631
[[nodiscard]] inline constexpr auto
4732
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));
4935

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));
6136
return submdspan_with_space<lspace, rspace>(
62-
in, std::forward<slices_t>(slices)...);
37+
std::forward<InType>(In), std::forward<slices_t>(slices)...);
6338
}
6439

6540
template <size_t rspace = 0, typename InType, typename... slices_t>
6641
[[nodiscard]] inline constexpr auto
6742
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));
6945

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)...);
7148
}
7249

7350
} // namespace core

0 commit comments

Comments
 (0)