From 7da73855071de8be5646f1efdb491f2904ae102c Mon Sep 17 00:00:00 2001 From: Christian Trott Date: Tue, 3 Sep 2024 14:32:35 -0600 Subject: [PATCH] Use proper index_pair_like constraint for submdspan --- .../__p2630_bits/submdspan_extents.hpp | 32 +++++++++++++++++-- .../__p2630_bits/submdspan_mapping.hpp | 3 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/include/experimental/__p2630_bits/submdspan_extents.hpp b/include/experimental/__p2630_bits/submdspan_extents.hpp index c3b2f78f..1ee8007f 100644 --- a/include/experimental/__p2630_bits/submdspan_extents.hpp +++ b/include/experimental/__p2630_bits/submdspan_extents.hpp @@ -17,6 +17,7 @@ #pragma once #include +#include #include "strided_slice.hpp" namespace MDSPAN_IMPL_STANDARD_NAMESPACE { @@ -52,6 +53,33 @@ template struct is_strided_slice< strided_slice> : std::true_type {}; +// Helper for identifying valid pair like things +template struct index_pair_like : std::false_type {}; + +template +struct index_pair_like, IndexType> { + static constexpr bool value = std::is_convertible_v && + std::is_convertible_v; +}; + +template +struct index_pair_like, IndexType> { + static constexpr bool value = std::is_convertible_v && + std::is_convertible_v; +}; + +template +struct index_pair_like, IndexType> { + static constexpr bool value = std::is_convertible_v; +}; + +template +struct index_pair_like, IndexType> { + static constexpr bool value = std::is_convertible_v; +}; + +// FIXME: we actually need to pass IndexType into all of these + // first_of(slice): getting begin of slice specifier range MDSPAN_TEMPLATE_REQUIRES( class Integral, @@ -70,7 +98,7 @@ first_of(const ::MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent_t &) { MDSPAN_TEMPLATE_REQUIRES( class Slice, - /* requires */(std::is_convertible_v>) + /* requires */(index_pair_like::value) ) MDSPAN_INLINE_FUNCTION constexpr auto first_of(const Slice &i) { @@ -100,7 +128,7 @@ constexpr Integral MDSPAN_TEMPLATE_REQUIRES( size_t k, class Extents, class Slice, - /* requires */(std::is_convertible_v>) + /* requires */(index_pair_like::value) ) MDSPAN_INLINE_FUNCTION constexpr auto last_of(std::integral_constant, const Extents &, diff --git a/include/experimental/__p2630_bits/submdspan_mapping.hpp b/include/experimental/__p2630_bits/submdspan_mapping.hpp index e1390fde..69762e44 100644 --- a/include/experimental/__p2630_bits/submdspan_mapping.hpp +++ b/include/experimental/__p2630_bits/submdspan_mapping.hpp @@ -98,8 +98,7 @@ template struct is_range_slice { constexpr static bool value = std::is_same_v || - std::is_convertible_v>; + index_pair_like::value; }; template