Skip to content

Commit c82425f

Browse files
committed
Deploy is_canonical_slice_type in layout_left
(submdspan_mapping_impl)
1 parent 4ab3ef6 commit c82425f

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

include/experimental/__p2630_bits/submdspan_extents.hpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -804,32 +804,36 @@ template<size_t k, class S_k, class IndexType, size_t... Exts>
804804
template<class T>
805805
constexpr bool is_constant_wrapper = false;
806806

807-
template<auto Value>
808-
constexpr bool is_constant_wrapper<std::constant_wrapper<Value>> = true;
807+
template<auto Value, class Type>
808+
constexpr bool is_constant_wrapper<std::constant_wrapper<Value, Type>> = true;
809809

810810
// [mdspan.sub.slices] 1
811811
template<class IndexType, class T>
812-
constexpr bool is_canonical_submdspan_index_type =
813-
std::is_same_v<T, IndexType> || (
814-
is_constant_wrapper<T> &&
815-
std::is_same_v<typename T::value_type, IndexType>
816-
);
812+
constexpr bool is_canonical_submdspan_index_type() {
813+
if constexpr (is_constant_wrapper<T>) {
814+
using value_type = typename T::value_type;
815+
return std::is_same_v<value_type, IndexType>;
816+
}
817+
else {
818+
return std::is_same_v<T, IndexType>;
819+
}
820+
}
817821

818822
// [mdspan.sub.slices] 2
819823
template<class IndexType, class Slice>
820824
MDSPAN_INLINE_FUNCTION
821825
constexpr bool is_canonical_slice_type() {
822-
if constexpr (
823-
std::is_same_v<Slice, full_extent_t> || // 2.1
824-
is_canonical_submdspan_index_type<IndexType, Slice>) // 2.2
825-
{
826+
if constexpr (std::is_same_v<Slice, full_extent_t>) { // 2.1
827+
return true;
828+
}
829+
else if constexpr (is_canonical_submdspan_index_type<IndexType, Slice>()) { // 2.2
826830
return true;
827831
}
828832
else if constexpr (is_strided_slice<Slice>::value) { // 2.3
829833
if constexpr ( // 2.3.1
830-
is_canonical_submdspan_index_type<IndexType, typename Slice::offset_type> &&
831-
is_canonical_submdspan_index_type<IndexType, typename Slice::extent_type> &&
832-
is_canonical_submdspan_index_type<IndexType, typename Slice::stride_type>)
834+
is_canonical_submdspan_index_type<IndexType, typename Slice::offset_type>() &&
835+
is_canonical_submdspan_index_type<IndexType, typename Slice::extent_type>() &&
836+
is_canonical_submdspan_index_type<IndexType, typename Slice::stride_type>())
833837
{
834838
if constexpr (
835839
is_constant_wrapper<typename Slice::stride_type> &&
@@ -840,7 +844,7 @@ constexpr bool is_canonical_slice_type() {
840844
return Extent == 0 || Stride > 0; // 2.3.2
841845
}
842846
else {
843-
return false;
847+
return true;
844848
}
845849
}
846850
else {

include/experimental/__p2630_bits/submdspan_mapping.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ MDSPAN_INLINE_FUNCTION constexpr auto
265265
layout_left::mapping<Extents>::submdspan_mapping_impl(
266266
SliceSpecifiers... slices) const {
267267

268+
#if defined(MDSPAN_ENABLE_P3663)
269+
static_assert((detail::is_canonical_slice_type<typename Extents::index_type, std::remove_cvref_t<SliceSpecifiers>>() && ...));
270+
#endif // MDSPAN_ENABLE_P3663
271+
268272
// compute sub extents
269273
using src_ext_t = Extents;
270274
auto dst_ext = submdspan_extents(extents(), slices...);

0 commit comments

Comments
 (0)