19 #include "trait_backports.hpp" 20 #include "extents.hpp" 23 namespace experimental {
27 template <
class Extents>
30 using extents_type = Extents;
31 using index_type =
typename extents_type::index_type;
32 using size_type =
typename extents_type::size_type;
33 using rank_type =
typename extents_type::rank_type;
37 static_assert(detail::__is_extents_v<extents_type>,
"std::experimental::layout_left::mapping must be instantiated with a specialization of std::experimental::extents.");
43 template <
size_t r,
size_t Rank>
44 struct __rank_count {};
46 template <
size_t r,
size_t Rank,
class I,
class... Indices>
48 constexpr index_type __compute_offset(
49 __rank_count<r,Rank>,
const I& i, Indices... idx)
const {
50 return __compute_offset(__rank_count<r+1,Rank>(), idx...) *
51 __extents.extent(r) + i;
56 constexpr index_type __compute_offset(
57 __rank_count<extents_type::rank()-1,extents_type::rank()>,
const I& i)
const {
62 constexpr index_type __compute_offset(__rank_count<0,0>)
const {
return 0; }
68 MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr
mapping() noexcept =
default;
69 MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr
mapping(
mapping const&) noexcept =
default;
72 constexpr
mapping(extents_type
const& __exts) noexcept
76 MDSPAN_TEMPLATE_REQUIRES(
79 _MDSPAN_TRAIT(is_constructible, extents_type, OtherExtents)
83 MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14
85 :__extents(other.extents())
93 MDSPAN_TEMPLATE_REQUIRES(
96 _MDSPAN_TRAIT(is_constructible, extents_type, OtherExtents) &&
97 (extents_type::rank() <= 1)
101 MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14
103 :__extents(other.extents())
111 MDSPAN_TEMPLATE_REQUIRES(
114 _MDSPAN_TRAIT(is_constructible, extents_type, OtherExtents)
117 MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0))
118 MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14
120 :__extents(other.extents())
126 #if !defined(_MDSPAN_HAS_CUDA) && !defined(_MDSPAN_HAS_HIP) && !defined(NDEBUG) 127 index_type stride = 1;
128 for(rank_type r=0; r<__extents.rank(); r++) {
129 if(stride != static_cast<index_type>(other.stride(r))) {
131 throw std::runtime_error(
"Assigning layout_stride to layout_left with invalid strides.");
133 stride *= __extents.extent(r);
138 MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED
mapping& operator=(
mapping const&) noexcept =
default;
140 MDSPAN_INLINE_FUNCTION
141 constexpr
const extents_type&
extents()
const noexcept {
145 MDSPAN_INLINE_FUNCTION
146 constexpr index_type required_span_size()
const noexcept {
147 index_type
value = 1;
148 for(rank_type r=0; r<extents_type::rank(); r++) value*=__extents.extent(r);
154 MDSPAN_TEMPLATE_REQUIRES(
157 (
sizeof...(Indices) == extents_type::rank()) &&
159 (_MDSPAN_TRAIT(is_convertible, Indices, index_type) &&
160 _MDSPAN_TRAIT(is_nothrow_constructible, index_type, Indices))
165 constexpr index_type operator()(Indices... idxs)
const noexcept {
166 return __compute_offset(__rank_count<0, extents_type::rank()>(), static_cast<index_type>(idxs)...);
171 MDSPAN_INLINE_FUNCTION
static constexpr
bool is_always_unique() noexcept {
return true; }
172 MDSPAN_INLINE_FUNCTION
static constexpr
bool is_always_exhaustive() noexcept {
return true; }
173 MDSPAN_INLINE_FUNCTION
static constexpr
bool is_always_strided() noexcept {
return true; }
175 MDSPAN_INLINE_FUNCTION constexpr
bool is_unique()
const noexcept {
return true; }
176 MDSPAN_INLINE_FUNCTION constexpr
bool is_exhaustive()
const noexcept {
return true; }
177 MDSPAN_INLINE_FUNCTION constexpr
bool is_strided()
const noexcept {
return true; }
179 MDSPAN_INLINE_FUNCTION
180 constexpr index_type stride(rank_type i)
const noexcept
181 #if MDSPAN_HAS_CXX_20 182 requires ( Extents::rank() > 0 )
185 index_type
value = 1;
186 for(rank_type r=0; r<i; r++) value*=__extents.extent(r);
190 template<
class OtherExtents>
191 MDSPAN_INLINE_FUNCTION
193 return lhs.extents() == rhs.extents();
197 #if !(MDSPAN_HAS_CXX_20) 198 template<
class OtherExtents>
199 MDSPAN_INLINE_FUNCTION
201 return lhs.extents() != rhs.extents();
206 template<
size_t N,
class SizeType,
size_t ... E,
size_t ... Idx>
208 return _MDSPAN_FOLD_TIMES_RIGHT((Idx<N? __extents.template __extent<Idx>():1),1);
211 constexpr index_type __stride()
const noexcept {
212 return __get_stride<N>(__extents, make_index_sequence<extents_type::rank()>());
216 _MDSPAN_NO_UNIQUE_ADDRESS extents_type __extents{};
Definition: layout_right.hpp:29
Definition: layout_stride.hpp:70
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition: layout_stride.hpp:40
Definition: trait_backports.hpp:64
Definition: layout_left.hpp:28
Definition: extents.hpp:372