Files
cppdraft_translate/cppdraft/views.md
2025-10-25 03:02:53 +03:00

248 KiB
Raw Blame History

[views]

23 Containers library [containers]

23.7 Views [views]

23.7.1 General [views.general]

1

#

The header defines the view span.

The header defines the class template mdspan and other facilities for interacting with these multidimensional views.

23.7.2 Contiguous access [views.contiguous]

23.7.2.1 Header synopsis [span.syn]

🔗

#include <initializer_list> // see [initializer.list.syn]// mostly freestandingnamespace std {// constantsinline constexpr size_t dynamic_extent = numeric_limits<size_t>::max(); templateconcept integral-constant-like = // exposition only is_integral_v<remove_cvref_t<decltype(T::value)>> &&!is_same_v<bool, remove_const_t<decltype(T::value)>> &&convertible_to<T, decltype(T::value)> &&equality_comparable_with<T, decltype(T::value)> && bool_constant<T() == T::value>::value && bool_constant<static_cast<decltype(T::value)>(T()) == T::value>::value; templateconstexpr size_t maybe-static-ext = dynamic_extent; // exposition onlytemplate<integral-constant-like T>constexpr size_t maybe-static-ext = {T::value}; // [views.span], class template spantemplate<class ElementType, size_t Extent = dynamic_extent>class span; // partially freestandingtemplate<class ElementType, size_t Extent>constexpr bool ranges::enable_view<span<ElementType, Extent>> = true; template<class ElementType, size_t Extent>constexpr bool ranges::enable_borrowed_range<span<ElementType, Extent>> = true; // [span.objectrep], views of object representationtemplate<class ElementType, size_t Extent> span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent> as_bytes(span<ElementType, Extent> s) noexcept; template<class ElementType, size_t Extent> span<byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent> as_writable_bytes(span<ElementType, Extent> s) noexcept;}

23.7.2.2 Class template span [views.span]

23.7.2.2.1 Overview [span.overview]

1

#

A span is a view over a contiguous sequence of objects, the storage of which is owned by some other object.

2

#

All member functions of span have constant time complexity.

🔗

namespace std {template<class ElementType, size_t Extent = dynamic_extent>class span {public:// constants and typesusing element_type = ElementType; using value_type = remove_cv_t; using size_type = size_t; using difference_type = ptrdiff_t; using pointer = element_type*; using const_pointer = const element_type*; using reference = element_type&; using const_reference = const element_type&; using iterator = implementation-defined; // see [span.iterators]using const_iterator = std::const_iterator; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::const_iterator<reverse_iterator>; static constexpr size_type extent = Extent; // [span.cons], constructors, copy, and assignmentconstexpr span() noexcept; templateconstexpr explicit(extent != dynamic_extent) span(It first, size_type count); template<class It, class End>constexpr explicit(extent != dynamic_extent) span(It first, End last); template<size_t N>constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept; template<class T, size_t N>constexpr span(array<T, N>& arr) noexcept; template<class T, size_t N>constexpr span(const array<T, N>& arr) noexcept; templateconstexpr explicit(extent != dynamic_extent) span(R&& r); constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il); constexpr span(const span& other) noexcept = default; template<class OtherElementType, size_t OtherExtent>constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept; constexpr span& operator=(const span& other) noexcept = default; // [span.sub], subviewstemplate<size_t Count>constexpr span<element_type, Count> first() const; template<size_t Count>constexpr span<element_type, Count> last() const; template<size_t Offset, size_t Count = dynamic_extent>constexpr span<element_type, see below> subspan() const; constexpr span<element_type, dynamic_extent> first(size_type count) const; constexpr span<element_type, dynamic_extent> last(size_type count) const; constexpr span<element_type, dynamic_extent> subspan( size_type offset, size_type count = dynamic_extent) const; // [span.obs], observersconstexpr size_type size() const noexcept; constexpr size_type size_bytes() const noexcept; constexpr bool empty() const noexcept; // [span.elem], element accessconstexpr reference operator[](size_type idx) const; constexpr reference at(size_type idx) const; // freestanding-deletedconstexpr reference front() const; constexpr reference back() const; constexpr pointer data() const noexcept; // [span.iterators], iterator supportconstexpr iterator begin() const noexcept; constexpr iterator end() const noexcept; constexpr const_iterator cbegin() const noexcept { return begin(); }constexpr const_iterator cend() const noexcept { return end(); }constexpr reverse_iterator rbegin() const noexcept; constexpr reverse_iterator rend() const noexcept; constexpr const_reverse_iterator crbegin() const noexcept { return rbegin(); }constexpr const_reverse_iterator crend() const noexcept { return rend(); }private: pointer data_; // exposition only size_type size_; // exposition only}; template<class It, class EndOrSize> span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t>, maybe-static-ext>; template<class T, size_t N> span(T (&)[N]) -> span<T, N>; template<class T, size_t N> span(array<T, N>&) -> span<T, N>; template<class T, size_t N> span(const array<T, N>&) -> span<const T, N>; template span(R&&) -> span<remove_reference_t<ranges::range_reference_t>>;}

3

#

span<ElementType, Extent> is a trivially copyable type ([basic.types.general]).

4

#

ElementType is required to be a complete object type that is not an abstract class type.

5

#

For a span s, any operation that invalidates a pointer in the range [s.data(), s.data() + s.size()) invalidates pointers, iterators, and references to elements of s.

23.7.2.2.2 Constructors, copy, and assignment [span.cons]

🔗

constexpr span() noexcept;

1

#

Constraints: Extent == dynamic_extent || Extent == 0 is true.

2

#

Postconditions: size() == 0 && data() == nullptr.

🔗

template<class It> constexpr explicit(extent != dynamic_extent) span(It first, size_type count);

3

#

Constraints: Let U be remove_reference_t<iter_reference_t>.

  • (3.1)

    It satisfies contiguous_iterator.

  • (3.2)

    is_convertible_v<U()[], element_type()[]> is true. [Note 1: The intent is to allow only qualification conversions of the iterator reference type to element_type. — end note]

4

#

Preconditions:

5

#

Hardened preconditions: If extent is not equal to dynamic_extent, then count == extent is true.

6

#

Effects: Initializes data_ with to_address(first) andsize_ with count.

7

#

Throws: Nothing.

🔗

template<class It, class End> constexpr explicit(extent != dynamic_extent) span(It first, End last);

8

#

Constraints: Let U be remove_reference_t<iter_reference_t>.

9

#

Preconditions:

10

#

Hardened preconditions: If extent is not equal to dynamic_extent, then (last - first) == extent is true.

11

#

Effects: Initializes data_ with to_address(first) andsize_ with last - first.

12

#

Throws: When and what last - first throws.

🔗

template<size_t N> constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept; template<class T, size_t N> constexpr span(array<T, N>& arr) noexcept; template<class T, size_t N> constexpr span(const array<T, N>& arr) noexcept;

13

#

Constraints: Let U be remove_pointer_t<decltype(std::data(arr))>.

extent == dynamic_extent || N == extent is true, and

is_convertible_v<U()[], element_type()[]> is true. [Note 3: The intent is to allow only qualification conversions of the array element type to element_type. — end note]

14

#

Effects: Constructs a span that is a view over the supplied array.

[Note 4:

type_identity_t affects class template argument deduction.

— end note]

15

#

Postconditions: size() == N && data() == std::data(arr) is true.

🔗

template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);

16

#

Constraints: Let U be remove_reference_t<ranges::range_reference_t>.

  • (16.1)

    R satisfies ranges::contiguous_range and ranges::sized_range.

  • (16.2)

    Either R satisfies ranges::borrowed_range oris_const_v<element_type> is true.

  • (16.3)

    remove_cvref_t is not a specialization of span.

  • (16.4)

    remove_cvref_t is not a specialization of array.

  • (16.5)

    is_array_v<remove_cvref_t> is false.

  • (16.6)

    is_convertible_v<U()[], element_type()[]> is true. [Note 5: The intent is to allow only qualification conversions of the range reference type to element_type. — end note]

17

#

Preconditions:

18

#

Hardened preconditions: If extent is not equal to dynamic_extent, then ranges::size(r) == extent is true.

19

#

Effects: Initializes data_ with ranges::data(r) andsize_ with ranges::size(r).

20

#

Throws: What and when ranges::data(r) and ranges::size(r) throw.

🔗

constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);

21

#

Constraints: is_const_v<element_type> is true.

22

#

Hardened preconditions: If extent is not equal to dynamic_extent, then il.size() == extent is true.

23

#

Effects: Initializes data_ with il.begin() andsize_ with il.size().

🔗

constexpr span(const span& other) noexcept = default;

24

#

Postconditions: other.size() == size() && other.data() == data().

🔗

template<class OtherElementType, size_t OtherExtent> constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept;

25

#

Constraints:

extent == dynamic_extent || OtherExtent == dynamic_extent || extent == OtherExtent is true, and

is_convertible_v<OtherElementType()[], element_type()[]> is true. [Note 6: The intent is to allow only qualification conversions of the OtherElementType to element_type. — end note]

26

#

Hardened preconditions: If extent is not equal to dynamic_extent, then s.size() == extent is true.

27

#

Effects: Constructs a span that is a view over the range [s.data(), s.data() + s.size()).

28

#

Postconditions: size() == s.size() && data() == s.data().

29

#

Remarks: The expression inside explicit is equivalent to:extent != dynamic_extent && OtherExtent == dynamic_extent

🔗

constexpr span& operator=(const span& other) noexcept = default;

30

#

Postconditions: size() == other.size() && data() == other.data().

23.7.2.2.3 Deduction guides [span.deduct]

🔗

template<class It, class EndOrSize> span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>, [maybe-static-ext](#concept:maybe-static-ext "23.7.2.1Header <span> synopsis[span.syn]")<EndOrSize>>;

1

#

Constraints: It satisfies contiguous_iterator.

🔗

template<class R> span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;

2

#

Constraints: R satisfies ranges::contiguous_range.

23.7.2.2.4 Subviews [span.sub]

🔗

template<size_t Count> constexpr span<element_type, Count> first() const;

1

#

Mandates: Count <= Extent is true.

2

#

Hardened preconditions: Count <= size() is true.

3

#

Effects: Equivalent to: return R{data(), Count}; where R is the return type.

🔗

template<size_t Count> constexpr span<element_type, Count> last() const;

4

#

Mandates: Count <= Extent is true.

5

#

Hardened preconditions: Count <= size() is true.

6

#

Effects: Equivalent to: return R{data() + (size() - Count), Count}; where R is the return type.

🔗

template<size_t Offset, size_t Count = dynamic_extent> constexpr span<element_type, see below> subspan() const;

7

#

Mandates: Offset <= Extent && (Count == dynamic_extent || Count <= Extent - Offset) is true.

8

#

Hardened preconditions: Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset) is true.

9

#

Effects: Equivalent to:return span<ElementType, see below>( data() + Offset, Count != dynamic_extent ? Count : size() - Offset);

10

#

Remarks: The second template argument of the returned span type is:Count != dynamic_extent ? Count : (Extent != dynamic_extent ? Extent - Offset : dynamic_extent)

🔗

constexpr span<element_type, dynamic_extent> first(size_type count) const;

11

#

Hardened preconditions: count <= size() is true.

12

#

Effects: Equivalent to: return {data(), count};

🔗

constexpr span<element_type, dynamic_extent> last(size_type count) const;

13

#

Hardened preconditions: count <= size() is true.

14

#

Effects: Equivalent to: return {data() + (size() - count), count};

🔗

constexpr span<element_type, dynamic_extent> subspan( size_type offset, size_type count = dynamic_extent) const;

15

#

Hardened preconditions: offset <= size() && (count == dynamic_extent || count <= size() - offset) is true.

16

#

Effects: Equivalent to:return {data() + offset, count == dynamic_extent ? size() - offset : count};

23.7.2.2.5 Observers [span.obs]

🔗

constexpr size_type size() const noexcept;

1

#

Effects: Equivalent to: return size_;

🔗

constexpr size_type size_bytes() const noexcept;

2

#

Effects: Equivalent to: return size() * sizeof(element_type);

🔗

constexpr bool empty() const noexcept;

3

#

Effects: Equivalent to: return size() == 0;

23.7.2.2.6 Element access [span.elem]

🔗

constexpr reference operator[](size_type idx) const;

1

#

Hardened preconditions: idx < size() is true.

2

#

Returns: *(data() + idx).

3

#

Throws: Nothing.

🔗

constexpr reference at(size_type idx) const;

4

#

Returns: *(data() + idx).

5

#

Throws: out_of_range if idx >= size() is true.

🔗

constexpr reference front() const;

6

#

Hardened preconditions: empty() is false.

7

#

Returns: *data().

8

#

Throws: Nothing.

🔗

constexpr reference back() const;

9

#

Hardened preconditions: empty() is false.

10

#

Returns: *(data() + (size() - 1)).

11

#

Throws: Nothing.

🔗

constexpr pointer data() const noexcept;

12

#

Returns: data_.

23.7.2.2.7 Iterator support [span.iterators]

🔗

using iterator = implementation-defined;

1

#

The type models contiguous_iterator ([iterator.concept.contiguous]), meets the Cpp17RandomAccessIterator requirements ([random.access.iterators]), and meets the requirements for constexpr iterators ([iterator.requirements.general]), whose value type is value_type and whose reference type is reference.

2

#

All requirements on container iterators ([container.reqmts]) apply tospan::iterator as well.

🔗

constexpr iterator begin() const noexcept;

3

#

Returns: An iterator referring to the first element in the span.

If empty() is true, then it returns the same value as end().

🔗

constexpr iterator end() const noexcept;

4

#

Returns: An iterator which is the past-the-end value.

🔗

constexpr reverse_iterator rbegin() const noexcept;

5

#

Effects: Equivalent to: return reverse_iterator(end());

🔗

constexpr reverse_iterator rend() const noexcept;

6

#

Effects: Equivalent to: return reverse_iterator(begin());

23.7.2.3 Views of object representation [span.objectrep]

🔗

template<class ElementType, size_t Extent> span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent> as_bytes(span<ElementType, Extent> s) noexcept;

1

#

Effects: Equivalent to: return R{reinterpret_cast<const byte*>(s.data()), s.size_bytes()}; where R is the return type.

🔗

template<class ElementType, size_t Extent> span<byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent> as_writable_bytes(span<ElementType, Extent> s) noexcept;

2

#

Constraints: is_const_v is false.

3

#

Effects: Equivalent to: return R{reinterpret_cast<byte*>(s.data()), s.size_bytes()}; where R is the return type.

23.7.3 Multidimensional access [views.multidim]

23.7.3.1 Overview [mdspan.overview]

1

#

A multidimensional index space is a Cartesian product of integer intervals.

Each interval can be represented by a half-open range [Li,Ui), where Li and Ui are the lower and upper bounds of the ith dimension.

The rank of a multidimensional index space is the number of intervals it represents.

The size of a multidimensional index space is the product of Ui−Li for each dimension i if its rank is greater than 0, and 1 otherwise.

2

#

An integer r is a rank index of an index space S if r is in the range [0,rank of S).

3

#

A pack of integers idx is a multidimensional index in a multidimensional index space S (or representation thereof) if both of the following are true:

sizeof...(idx) is equal to the rank of S, and

for every rank index i of S, the ith value of idx is an integer in the interval [Li,Ui) of S.

23.7.3.2 Header synopsis [mdspan.syn]

🔗

// mostly freestandingnamespace std {// [mdspan.extents], class template extentstemplate<class IndexType, size_t... Extents>class extents; // [mdspan.extents.dextents], alias template dextentstemplate<class IndexType, size_t Rank>using dextents = see below; // [mdspan.extents.dims], alias template dimstemplate<size_t Rank, class IndexType = size_t>using dims = see below; // [mdspan.layout], layout mappingstruct layout_left; struct layout_right; struct layout_stride; template<size_t PaddingValue = dynamic_extent>struct layout_left_padded; template<size_t PaddingValue = dynamic_extent>struct layout_right_padded; // [mdspan.accessor.default], class template default_accessortemplateclass default_accessor; // [mdspan.accessor.aligned], class template aligned_accessortemplate<class ElementType, size_t ByteAlignment>class aligned_accessor; // [mdspan.mdspan], class template mdspantemplate<class ElementType, class Extents, class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor>class mdspan; // partially freestanding// [mdspan.sub], submdspan creationtemplate<class OffsetType, class LengthType, class StrideType>struct strided_slice; templatestruct submdspan_mapping_result; struct full_extent_t { explicit full_extent_t() = default; }; inline constexpr full_extent_t full_extent{}; template<class IndexType, size_t... Extents, class... SliceSpecifiers>constexpr auto submdspan_extents(const extents<IndexType, Extents...>&, SliceSpecifiers...); // [mdspan.sub.sub], submdspan function templatetemplate<class ElementType, class Extents, class LayoutPolicy, class AccessorPolicy, class... SliceSpecifiers>constexpr auto submdspan(const mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>& src, SliceSpecifiers... slices) -> see below; template<class T, class IndexType>concept index-pair-like = // exposition onlypair-like &&convertible_to<tuple_element_t<0, T>, IndexType> &&convertible_to<tuple_element_t<1, T>, IndexType>;}

23.7.3.3 Class template extents [mdspan.extents]

23.7.3.3.1 Overview [mdspan.extents.overview]

The class template extents represents a multidimensional index space of rank equal to sizeof...(Extents).

In [views],extents is used synonymously with multidimensional index space.

namespace std {template<class IndexType, size_t... Extents>class extents {public:using index_type = IndexType; using size_type = make_unsigned_t<index_type>; using rank_type = size_t; // [mdspan.extents.obs], observers of the multidimensional index spacestatic constexpr rank_type rank() noexcept { return sizeof...(Extents); }static constexpr rank_type rank_dynamic() noexcept { return dynamic-index(rank()); }static constexpr size_t static_extent(rank_type) noexcept; constexpr index_type extent(rank_type) const noexcept; // [mdspan.extents.cons], constructorsconstexpr extents() noexcept = default; template<class OtherIndexType, size_t... OtherExtents>constexpr explicit(see below) extents(const extents<OtherIndexType, OtherExtents...>&) noexcept; template<class... OtherIndexTypes>constexpr explicit extents(OtherIndexTypes...) noexcept; template<class OtherIndexType, size_t N>constexpr explicit(N != rank_dynamic()) extents(span<OtherIndexType, N>) noexcept; template<class OtherIndexType, size_t N>constexpr explicit(N != rank_dynamic()) extents(const array<OtherIndexType, N>&) noexcept; // [mdspan.extents.cmp], comparison operatorstemplate<class OtherIndexType, size_t... OtherExtents>friend constexpr bool operator==(const extents&, const extents<OtherIndexType, OtherExtents...>&) noexcept; // [mdspan.extents.expo], exposition-only helpersconstexpr size_t fwd-prod-of-extents(rank_type) const noexcept; // exposition onlyconstexpr size_t rev-prod-of-extents(rank_type) const noexcept; // exposition onlytemplatestatic constexpr auto index-cast(OtherIndexType&&) noexcept; // exposition onlyprivate:static constexpr rank_type dynamic-index(rank_type) noexcept; // exposition onlystatic constexpr rank_type dynamic-index-inv(rank_type) noexcept; // exposition only array<index_type, rank_dynamic()> dynamic-extents{}; // exposition only}; template<class... Integrals>explicit extents(Integrals...)-> see below;}

1

#

Mandates:

IndexType is a signed or unsigned integer type, and

each element of Extents is either equal to dynamic_extent, or is representable as a value of type IndexType.

2

#

Each specialization of extents models regular and is trivially copyable.

3

#

Let Er be the rth element of Extents.

Er is a dynamic extent if it is equal to dynamic_extent, otherwise Er is a static extent.

Let Dr be the value of dynamic-extents[dynamic-index(r)] if Er is a dynamic extent, otherwise Er.

4

#

The rth interval of the multidimensional index space represented by an extents object is [0,Dr).

23.7.3.3.2 Exposition-only helpers [mdspan.extents.expo]

🔗

static constexpr rank_type dynamic-index(rank_type i) noexcept;

1

#

Preconditions: i <= rank() is true.

2

#

Returns: The number of Er with r<i for which Er is a dynamic extent.

🔗

static constexpr rank_type dynamic-index-inv(rank_type i) noexcept;

3

#

Preconditions: i < rank_dynamic() is true.

4

#

Returns: The minimum value of r such that dynamic-index(r + 1) == i + 1 is true.

🔗

constexpr size_t fwd-prod-of-extents(rank_type i) const noexcept;

5

#

Preconditions: i <= rank() is true.

6

#

Returns: If i > 0 is true, the product of extent(k) for all k in the range [0, i), otherwise 1.

🔗

constexpr size_t rev-prod-of-extents(rank_type i) const noexcept;

7

#

Preconditions: i < rank() is true.

8

#

Returns: If i + 1 < rank() is true, the product of extent(k) for all k in the range [i + 1, rank()), otherwise 1.

🔗

template<class OtherIndexType> static constexpr auto index-cast(OtherIndexType&& i) noexcept;

9

#

Effects:

If OtherIndexType is an integral type other than bool, then equivalent to return i;,

otherwise, equivalent to return static_cast<index_type>(i);.

[Note 1:

This function will always return an integral type other than bool.

Since this function's call sites are constrained on convertibility of OtherIndexType to index_type, integer-class types can use the static_cast branch without loss of precision.

— end note]

23.7.3.3.3 Constructors [mdspan.extents.cons]

🔗

template<class OtherIndexType, size_t... OtherExtents> constexpr explicit(see below) extents(const extents<OtherIndexType, OtherExtents...>& other) noexcept;

1

#

Constraints:

  • (1.1)

    sizeof...(OtherExtents) == rank() is true.

  • (1.2)

    ((OtherExtents == dynamic_extent || Extents == dynamic_extent || OtherExtents ==
    Extents) && ...) is true.

2

#

Preconditions:

other.extent(r) equals Er for each r for which Er is a static extent, and

either

sizeof...(OtherExtents) is zero, or

other.extent(r) is representable as a value of type index_type for every rank index r of other.

3

#

Postconditions: *this == other is true.

4

#

Remarks: The expression inside explicit is equivalent to:(((Extents != dynamic_extent) && (OtherExtents == dynamic_extent)) || ... ) ||(numeric_limits<index_type>::max() < numeric_limits::max())

🔗

template<class... OtherIndexTypes> constexpr explicit extents(OtherIndexTypes... exts) noexcept;

5

#

Let N be sizeof...(OtherIndexTypes), and let exts_arr bearray<index_type, N>{static_cast<
index_type>(std::move(exts))...}.

6

#

Constraints:

(is_convertible_v<OtherIndexTypes, index_type> && ...) is true,

(is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...) is true, and

N == rank_dynamic() || N == rank() is true. [Note 1: One can construct extents from just dynamic extents, which are all the values getting stored, or from all the extents with a precondition. — end note]

7

#

Preconditions:

If N != rank_dynamic() is true,exts_arr[r] equals Er for each r for which Er is a static extent, and

either

sizeof...(exts) == 0 is true, or

each element of exts is representable as a nonnegative value of type index_type.

8

#

Postconditions: *this == extents(exts_arr) is true.

🔗

template<class OtherIndexType, size_t N> constexpr explicit(N != rank_dynamic()) extents(span<OtherIndexType, N> exts) noexcept; template<class OtherIndexType, size_t N> constexpr explicit(N != rank_dynamic()) extents(const array<OtherIndexType, N>& exts) noexcept;

9

#

Constraints:

is_convertible_v<const OtherIndexType&, index_type> is true,

is_nothrow_constructible_v<index_type, const OtherIndexType&> is true, and

N == rank_dynamic() || N == rank() is true.

10

#

Preconditions:

If N != rank_dynamic() is true,exts[r] equals Er for each r for which Er is a static extent, and

either

N is zero, or

exts[r] is representable as a nonnegative value of type index_type for every rank index r.

11

#

Effects:

  • (11.1)

    If N equals rank_dynamic(), for all d in the range [0, rank_dynamic()), direct-non-list-initializes dynamic-extents[d] with as_const(exts[d]).

  • (11.2)

    Otherwise, for all d in the range [0, rank_dynamic()), direct-non-list-initializes dynamic-extents[d] with as_const(exts[dynamic-index-inv(d)]).

🔗

template<class... Integrals> explicit extents(Integrals...) -> see below;

12

#

Constraints: (is_convertible_v<Integrals, size_t> && ...) is true.

13

#

Remarks: The deduced type is extents<size_t, maybe-static-ext...>.

23.7.3.3.4 Observers of the multidimensional index space [mdspan.extents.obs]

🔗

static constexpr size_t static_extent(rank_type i) noexcept;

1

#

Preconditions: i < rank() is true.

2

#

Returns: Ei.

🔗

constexpr index_type extent(rank_type i) const noexcept;

3

#

Preconditions: i < rank() is true.

4

#

Returns: Di.

23.7.3.3.5 Comparison operators [mdspan.extents.cmp]

🔗

template<class OtherIndexType, size_t... OtherExtents> friend constexpr bool operator==(const extents& lhs, const extents<OtherIndexType, OtherExtents...>& rhs) noexcept;

1

#

Returns: true if lhs.rank() equals rhs.rank() and if lhs.extent(r) equals rhs.extent(r) for every rank index r of rhs, otherwise false.

23.7.3.3.6 Alias template dextents [mdspan.extents.dextents]

🔗

template<class IndexType, size_t Rank> using dextents = see below;

1

#

Result: A type E that is a specialization of extents such that E::rank() == Rank && E::rank() == E::rank_dynamic() is true, andE::index_type denotes IndexType.

23.7.3.3.7 Alias template dims [mdspan.extents.dims]

🔗

template<size_t Rank, class IndexType = size_t> using dims = see below;

1

#

Result: A type E that is a specialization of extents such that E::rank() == Rank && E::rank() == E::rank_dynamic() is true, andE::index_type denotes IndexType.

23.7.3.4 Layout mapping [mdspan.layout]

23.7.3.4.1 General [mdspan.layout.general]

1

#

In [mdspan.layout.reqmts] and [mdspan.layout.policy.reqmts]:

  • (1.1)

    M denotes a layout mapping class.

  • (1.2)

    m denotes a (possibly const) value of type M.

  • (1.3)

    i and j are packs of (possibly const) integers that are multidimensional indices in m.extents() ([mdspan.overview]). [Note 1: The type of each element of the packs can be a different integer type. — end note]

  • (1.4)

    r is a (possibly const) rank index of typename M::extents_type.

  • (1.5)

    dr is a pack of (possibly const) integers for which sizeof...(dr) == M::extents_type::rank() is true, the rth element is equal to 1, and all other elements are equal to 0.

2

#

In [mdspan.layout.reqmts] through [mdspan.layout.stride]:

Let is-mapping-of be the exposition-only variable template defined as follows:template<class Layout, class Mapping>constexpr bool is-mapping-of = // exposition only is_same_v<typename Layout::template mapping, Mapping>;

Let is-layout-left-padded-mapping-of be the exposition-only variable template defined as follows:templateconstexpr bool is-layout-left-padded-mapping-of = see below; // exposition only where is-layout-left-padded-mapping-of is true if and only if Mapping denotes a specialization of layout_left_padded::mapping for some value S of type size_t.

Let is-layout-right-padded-mapping-of be the exposition-only variable template defined as follows:templateconstexpr bool is-layout-right-padded-mapping-of = see below; // exposition only where is-layout-right-padded-mapping-of is true if and only if Mapping denotes a specialization of layout_right_padded::mapping for some value S of type size_t.

For nonnegative integers x and y, let LEAST-MULTIPLE-AT-LEAST(x,y) denote

y if x is zero,

otherwise, the least multiple of x that is greater than or equal to y.

23.7.3.4.2 Requirements [mdspan.layout.reqmts]

1

#

A type M meets the layout mapping requirements if

M models copyable and equality_comparable,

is_nothrow_move_constructible_v is true,

is_nothrow_move_assignable_v is true,

is_nothrow_swappable_v is true, and

the following types and expressions are well-formed and have the specified semantics.

🔗

typename M::extents_type

2

#

Result: A type that is a specialization of extents.

🔗

typename M::index_type

3

#

Result: typename M::extents_type::index_type.

🔗

typename M::rank_type

4

#

Result: typename M::extents_type::rank_type.

🔗

typename M::layout_type

5

#

Result: A type MP that meets the layout mapping policy requirements ([mdspan.layout.policy.reqmts]) and for which is-mapping-of<MP, M> is true.

🔗

m.extents()

6

#

Result: const typename M::extents_type&

🔗

m(i...)

7

#

Result: typename M::index_type

8

#

Returns: A nonnegative integer less than numeric_limits<typename M::index_type>::max() and less than or equal to numeric_limits<size_t>::max().

🔗

m(i...) == m(static_cast<typename M::index_type>(i)...)

9

#

Result: bool

10

#

Returns: true

🔗

m.required_span_size()

11

#

Result: typename M::index_type

12

#

Returns: If the size of the multidimensional index space m.extents() is 0, then 0, else 1 plus the maximum value of m(i...) for all i.

🔗

m.is_unique()

13

#

Result: bool

14

#

Returns: true only if for every i and j where (i != j || ...) is true,m(i...) != m(j...) is true.

[Note 1:

A mapping can return false even if the condition is met.

For certain layouts, it is possibly not feasible to determine efficiently whether the layout is unique.

— end note]

🔗

m.is_exhaustive()

15

#

Result: bool

16

#

Returns: true only if for all k in the range [0, m.required_span_size()) there exists an i such that m(i...) equals k.

[Note 2:

A mapping can return false even if the condition is met.

For certain layouts, it is possibly not feasible to determine efficiently whether the layout is exhaustive.

— end note]

🔗

m.is_strided()

17

#

Result: bool

18

#

Returns: true only if for every rank index r of m.extents() there exists an integer sr such that, for all i where (i+dr) is a multidimensional index in m.extents() ([mdspan.overview]),m((i + dr)...) - m(i...) equals sr.

[Note 3:

This implies that for a strided layoutm(i0,…,ik)=m(0,…,0)+i0×s0+⋯+ik×sk.

— end note]

[Note 4:

A mapping can return false even if the condition is met.

For certain layouts, it is possibly not feasible to determine efficiently whether the layout is strided.

— end note]

🔗

m.stride(r)

19

#

Preconditions: m.is_strided() is true.

20

#

Result: typename M::index_type

21

#

Returns: sr as defined in m.is_strided() above.

22

#

[Note 5:

It is not required for m.stride(r) to be well-formed if m.extents().rank() is zero, even if m.is_always_strided() is true.

— end note]

🔗

M::is_always_unique()

23

#

Result: A constant expression ([expr.const]) of type bool.

24

#

Returns: true only if m.is_unique() is true for all possible objects m of type M.

[Note 6:

A mapping can return false even if the above condition is met.

For certain layout mappings, it is possibly not feasible to determine whether every instance is unique.

— end note]

🔗

M::is_always_exhaustive()

25

#

Result: A constant expression ([expr.const]) of type bool.

26

#

Returns: true only if m.is_exhaustive() is true for all possible objects m of type M.

[Note 7:

A mapping can return false even if the above condition is met.

For certain layout mappings, it is possibly not feasible to determine whether every instance is exhaustive.

— end note]

🔗

M::is_always_strided()

27

#

Result: A constant expression ([expr.const]) of type bool.

28

#

Returns: true only if m.is_strided() is true for all possible objects m of type M.

[Note 8:

A mapping can return false even if the above condition is met.

For certain layout mappings, it is possibly not feasible to determine whether every instance is strided.

— end note]

23.7.3.4.3 Layout mapping policy requirements [mdspan.layout.policy.reqmts]

1

#

A type MP meets the layout mapping policy requirements if for a type E that is a specialization of extents,MP::mapping is valid and denotes a type X that meets the layout mapping requirements ([mdspan.layout.reqmts]), and for which the qualified-id X::layout_type is valid and denotes the type MP and the qualified-id X::extents_type denotes E.

23.7.3.4.4 Layout mapping policies [mdspan.layout.policy.overview]

namespace std {struct layout_left {templateclass mapping; }; struct layout_right {templateclass mapping; }; struct layout_stride {templateclass mapping; }; template<size_t PaddingValue>struct layout_left_padded {template class mapping; }; template<size_t PaddingValue>struct layout_right_padded {template class mapping; };}

1

#

Each of layout_left, layout_right, and layout_stride, as well as each specialization oflayout_left_padded and layout_right_padded, meets the layout mapping policy requirements and is a trivially copyable type.

Furthermore,is_trivially_default_constructible_v is true for any such type T.

23.7.3.4.5 Class template layout_left::mapping [mdspan.layout.left]

23.7.3.4.5.1 Overview [mdspan.layout.left.overview]

1

#

layout_left provides a layout mapping where the leftmost extent has stride 1, and strides increase left-to-right as the product of extents.

namespace std {templateclass layout_left::mapping {public:using extents_type = Extents; using index_type = typename extents_type::index_type; using size_type = typename extents_type::size_type; using rank_type = typename extents_type::rank_type; using layout_type = layout_left; // [mdspan.layout.left.cons], constructorsconstexpr mapping() noexcept = default; constexpr mapping(const mapping&) noexcept = default; constexpr mapping(const extents_type&) noexcept; templateconstexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const mapping&) noexcept; templateconstexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_right::mapping&) noexcept; templateconstexpr explicit(!is_convertible_v<typename LayoutLeftPaddedMapping::extents_type, extents_type>) mapping(const LayoutLeftPaddedMapping&) noexcept; templateconstexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping&); constexpr mapping& operator=(const mapping&) noexcept = default; // [mdspan.layout.left.obs], observersconstexpr const extents_type& extents() const noexcept { return extents_; }constexpr index_type required_span_size() const noexcept; template<class... Indices>constexpr index_type operator()(Indices...) const noexcept; static constexpr bool is_always_unique() noexcept { return true; }static constexpr bool is_always_exhaustive() noexcept { return true; }static constexpr bool is_always_strided() noexcept { return true; }static constexpr bool is_unique() noexcept { return true; }static constexpr bool is_exhaustive() noexcept { return true; }static constexpr bool is_strided() noexcept { return true; }constexpr index_type stride(rank_type) const noexcept; templatefriend constexpr bool operator==(const mapping&, const mapping&) noexcept; private: extents_type extents_{}; // exposition only// [mdspan.sub.map], submdspan mapping specializationtemplate<class... SliceSpecifiers>constexpr auto submdspan-mapping-impl(SliceSpecifiers...) const // exposition only-> see below; template<class... SliceSpecifiers>friend constexpr auto submdspan_mapping(const mapping& src, SliceSpecifiers... slices) {return src.submdspan-mapping-impl(slices...); }};}

2

#

If Extents is not a specialization of extents, then the program is ill-formed.

3

#

layout_left::mapping is a trivially copyable type that models regular for each E.

4

#

Mandates: If Extents::rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() is representable as a value of type typename Extents::index_type.

23.7.3.4.5.2 Constructors [mdspan.layout.left.cons]

🔗

constexpr mapping(const extents_type& e) noexcept;

1

#

Preconditions: The size of the multidimensional index space e is representable as a value of type index_type ([basic.fundamental]).

2

#

Effects: Direct-non-list-initializes extents_ with e.

🔗

template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const mapping<OtherExtents>& other) noexcept;

3

#

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

4

#

Preconditions: other.required_span_size() is representable as a value of type index_type ([basic.fundamental]).

5

#

Effects: Direct-non-list-initializes extents_ with other.extents().

🔗

template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_right::mapping<OtherExtents>& other) noexcept;

6

#

Constraints:

extents_type::rank() <= 1 is true, and

is_constructible_v<extents_type, OtherExtents> is true.

7

#

Preconditions: other.required_span_size() is representable as a value of type index_type ([basic.fundamental]).

8

#

Effects: Direct-non-list-initializes extents_ with other.extents().

🔗

template<class LayoutLeftPaddedMapping> constexpr explicit(!is_convertible_v<typename LayoutLeftPaddedMapping::extents_type, extents_type>) mapping(const LayoutLeftPaddedMapping&) noexcept;

9

#

Constraints:

  • (9.1)

    is-layout-left-padded-mapping-of is true.

  • (9.2)

    is_constructible_v<extents_type, typename LayoutLeftPaddedMapping::extents_type>
    is true.

10

#

Mandates: If

Extents::rank() is greater than one,

Extents::static_extent(0) does not equal dynamic_extent, and

LayoutLeftPaddedMapping::static-padding-stride does not equal dynamic_extent,

then Extents::static_extent(0) equalsLayoutLeftPaddedMapping::static-padding-stride.

11

#

Preconditions:

  • (11.1)

    If extents_type::rank() > 1 is true, then other.stride(1) equals other.extents(0).

  • (11.2)

    other.required_span_size() is representable as a value of type index_type.

12

#

Effects: Direct-non-list-initializes extents_ with other.extents().

🔗

template<class OtherExtents> constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping<OtherExtents>& other);

13

#

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

14

#

Preconditions:

If extents_type::rank() > 0 is true, then for all r in the range [0, extents_type::rank()),other.stride(r) equalsother.extents().fwd-prod-of-extents(r), and

other.required_span_size() is representable as a value of type index_type ([basic.fundamental]).

15

#

Effects: Direct-non-list-initializes extents_ with other.extents().

23.7.3.4.5.3 Observers [mdspan.layout.left.obs]

🔗

constexpr index_type required_span_size() const noexcept;

1

#

Returns: extents().fwd-prod-of-extents(extents_type::rank()).

🔗

template<class... Indices> constexpr index_type operator()(Indices... i) const noexcept;

2

#

Constraints:

sizeof...(Indices) == extents_type::rank() is true,

(is_convertible_v<Indices, index_type> && ...) is true, and

(is_nothrow_constructible_v<index_type, Indices> && ...) is true.

3

#

Preconditions: extents_type::index-cast(i) is a multidimensional index in extents_ ([mdspan.overview]).

4

#

Effects: Let P be a parameter pack such thatis_same_v<index_sequence_for<Indices...>, index_sequence<P...>> is true.

Equivalent to:return ((static_cast<index_type>(i) * stride(P)) + ... + 0);

🔗

constexpr index_type stride(rank_type i) const noexcept;

5

#

Constraints: extents_type::rank() > 0 is true.

6

#

Preconditions: i < extents_type::rank() is true.

7

#

Returns: extents().fwd-prod-of-extents(i).

🔗

template<class OtherExtents> friend constexpr bool operator==(const mapping& x, const mapping<OtherExtents>& y) noexcept;

8

#

Constraints: extents_type::rank() == OtherExtents::rank() is true.

9

#

Effects: Equivalent to: return x.extents() == y.extents();

23.7.3.4.6 Class template layout_right::mapping [mdspan.layout.right]

23.7.3.4.6.1 Overview [mdspan.layout.right.overview]

1

#

layout_right provides a layout mapping where the rightmost extent is stride 1, and strides increase right-to-left as the product of extents.

namespace std {templateclass layout_right::mapping {public:using extents_type = Extents; using index_type = typename extents_type::index_type; using size_type = typename extents_type::size_type; using rank_type = typename extents_type::rank_type; using layout_type = layout_right; // [mdspan.layout.right.cons], constructorsconstexpr mapping() noexcept = default; constexpr mapping(const mapping&) noexcept = default; constexpr mapping(const extents_type&) noexcept; templateconstexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const mapping&) noexcept; templateconstexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_left::mapping&) noexcept; templateconstexpr explicit(!is_convertible_v<typename LayoutRightPaddedMapping::extents_type, extents_type>) mapping(const LayoutRightPaddedMapping&) noexcept; templateconstexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping&) noexcept; constexpr mapping& operator=(const mapping&) noexcept = default; // [mdspan.layout.right.obs], observersconstexpr const extents_type& extents() const noexcept { return extents_; }constexpr index_type required_span_size() const noexcept; template<class... Indices>constexpr index_type operator()(Indices...) const noexcept; static constexpr bool is_always_unique() noexcept { return true; }static constexpr bool is_always_exhaustive() noexcept { return true; }static constexpr bool is_always_strided() noexcept { return true; }static constexpr bool is_unique() noexcept { return true; }static constexpr bool is_exhaustive() noexcept { return true; }static constexpr bool is_strided() noexcept { return true; }constexpr index_type stride(rank_type) const noexcept; templatefriend constexpr bool operator==(const mapping&, const mapping&) noexcept; private: extents_type extents_{}; // exposition only// [mdspan.sub.map], submdspan mapping specializationtemplate<class... SliceSpecifiers>constexpr auto submdspan-mapping-impl(SliceSpecifiers...) const // exposition only-> see below; template<class... SliceSpecifiers>friend constexpr auto submdspan_mapping(const mapping& src, SliceSpecifiers... slices) {return src.submdspan-mapping-impl(slices...); }};}

2

#

If Extents is not a specialization of extents, then the program is ill-formed.

3

#

layout_right::mapping is a trivially copyable type that models regular for each E.

4

#

Mandates: If Extents::rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() is representable as a value of type typename Extents::index_type.

23.7.3.4.6.2 Constructors [mdspan.layout.right.cons]

🔗

constexpr mapping(const extents_type& e) noexcept;

1

#

Preconditions: The size of the multidimensional index space e is representable as a value of type index_type ([basic.fundamental]).

2

#

Effects: Direct-non-list-initializes extents_ with e.

🔗

template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const mapping<OtherExtents>& other) noexcept;

3

#

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

4

#

Preconditions: other.required_span_size() is representable as a value of type index_type ([basic.fundamental]).

5

#

Effects: Direct-non-list-initializes extents_ with other.extents().

🔗

template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_left::mapping<OtherExtents>& other) noexcept;

6

#

Constraints:

extents_type::rank() <= 1 is true, and

is_constructible_v<extents_type, OtherExtents> is true.

7

#

Preconditions: other.required_span_size() is representable as a value of type index_type ([basic.fundamental]).

8

#

Effects: Direct-non-list-initializes extents_ with other.extents().

🔗

template<class LayoutRightPaddedMapping> constexpr explicit(!is_convertible_v<typename LayoutRightPaddedMapping::extents_type, extents_type>) mapping(const LayoutRightPaddedMapping&) noexcept;

9

#

Constraints:

  • (9.1)

    is-layout-right-padded-mapping-of is true.

  • (9.2)

    is_constructible_v<extents_type, typename LayoutRightPaddedMapping::extents_-
    type> is true.

10

#

Mandates: If

Extents::rank() is greater than one,

Extents::static_extent(Extents::rank() - 1) does not equal dynamic_extent, and

LayoutRightPaddedMapping::static-padding-stride does not equal dynamic_extent,

then Extents::static_extent(Extents::rank() - 1) equalsLayoutRightPaddedMapping::static-padding-stride.

11

#

Preconditions:

  • (11.1)

    If extents_type::rank() > 1 is true, then other.stride(extents_type::rank() - 2)
    equalsother.extents().extent(extents_type::rank() - 1).

  • (11.2)

    other.required_span_size() is representable as a value of type index_type.

12

#

Effects: Direct-non-list-initializes extents_ with other.extents().

🔗

template<class OtherExtents> constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping<OtherExtents>& other) noexcept;

13

#

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

14

#

Preconditions:

  • (14.1)

    If extents_type::rank() > 0 is true, then for all r in the range [0, extents_type::rank()),other.stride(r) equalsother.extents().rev-prod-of-extents(r).

  • (14.2)

    other.required_span_size() is representable as a value of type index_type ([basic.fundamental]).

15

#

Effects: Direct-non-list-initializes extents_ with other.extents().

23.7.3.4.6.3 Observers [mdspan.layout.right.obs]

🔗

constexpr index_type required_span_size() const noexcept;

1

#

Returns: extents().fwd-prod-of-extents(extents_type::rank()).

🔗

template<class... Indices> constexpr index_type operator()(Indices... i) const noexcept;

2

#

Constraints:

sizeof...(Indices) == extents_type::rank() is true,

(is_convertible_v<Indices, index_type> && ...) is true, and

(is_nothrow_constructible_v<index_type, Indices> && ...) istrue.

3

#

Preconditions: extents_type::index-cast(i) is a multidimensional index in extents_ ([mdspan.overview]).

4

#

Effects: Let P be a parameter pack such thatis_same_v<index_sequence_for<Indices...>, index_sequence<P...>> is true.

Equivalent to:return ((static_cast<index_type>(i) * stride(P)) + ... + 0);

🔗

constexpr index_type stride(rank_type i) const noexcept;

5

#

Constraints: extents_type::rank() > 0 is true.

6

#

Preconditions: i < extents_type::rank() is true.

7

#

Returns: extents().rev-prod-of-extents(i).

🔗

template<class OtherExtents> friend constexpr bool operator==(const mapping& x, const mapping<OtherExtents>& y) noexcept;

8

#

Constraints: extents_type::rank() == OtherExtents::rank() is true.

9

#

Effects: Equivalent to: return x.extents() == y.extents();

23.7.3.4.7 Class template layout_stride::mapping [mdspan.layout.stride]

23.7.3.4.7.1 Overview [mdspan.layout.stride.overview]

1

#

layout_stride provides a layout mapping where the strides are user-defined.

namespace std {templateclass layout_stride::mapping {public:using extents_type = Extents; using index_type = typename extents_type::index_type; using size_type = typename extents_type::size_type; using rank_type = typename extents_type::rank_type; using layout_type = layout_stride; private:static constexpr rank_type rank_ = extents_type::rank(); // exposition onlypublic:// [mdspan.layout.stride.cons], constructorsconstexpr mapping() noexcept; constexpr mapping(const mapping&) noexcept = default; templateconstexpr mapping(const extents_type&, span<OtherIndexType, rank_>) noexcept; templateconstexpr mapping(const extents_type&, const array<OtherIndexType, rank_>&) noexcept; templateconstexpr explicit(see below) mapping(const StridedLayoutMapping&) noexcept; constexpr mapping& operator=(const mapping&) noexcept = default; // [mdspan.layout.stride.obs], observersconstexpr const extents_type& extents() const noexcept { return extents_; }constexpr array<index_type, rank_> strides() const noexcept { return strides_; }constexpr index_type required_span_size() const noexcept; template<class... Indices>constexpr index_type operator()(Indices...) const noexcept; static constexpr bool is_always_unique() noexcept { return true; }static constexpr bool is_always_exhaustive() noexcept { return false; }static constexpr bool is_always_strided() noexcept { return true; }static constexpr bool is_unique() noexcept { return true; }constexpr bool is_exhaustive() const noexcept; static constexpr bool is_strided() noexcept { return true; }constexpr index_type stride(rank_type i) const noexcept { return strides_[i]; }templatefriend constexpr bool operator==(const mapping&, const OtherMapping&) noexcept; private: extents_type extents_{}; // exposition only array<index_type, rank_> strides_{}; // exposition only// [mdspan.sub.map], submdspan mapping specializationtemplate<class... SliceSpecifiers>constexpr auto submdspan-mapping-impl(SliceSpecifiers...) const // exposition only-> see below; template<class... SliceSpecifiers>friend constexpr auto submdspan_mapping(const mapping& src, SliceSpecifiers... slices) {return src.submdspan-mapping-impl(slices...); }};}

2

#

If Extents is not a specialization of extents, then the program is ill-formed.

3

#

layout_stride::mapping is a trivially copyable type that models regular for each E.

4

#

Mandates: If Extents::rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() is representable as a value of type typename Extents::index_type.

23.7.3.4.7.2 Exposition-only helpers [mdspan.layout.stride.expo]

1

#

Let REQUIRED-SPAN-SIZE(e, strides) be:

1, if e.rank() == 0 is true,

otherwise 0, if the size of the multidimensional index space e is 0,

otherwise 1 plus the sum of products of(e.extent(r) - 1) andextents_type::index-cast(strides[r]) for all r in the range [0, e.rank()).

2

#

Let OFFSET(m) be:

m(), if e.rank() == 0 is true,

otherwise 0, if the size of the multidimensional index space e is 0,

otherwise m(z...) for a pack of integers z that is a multidimensional index in m.extents() and each element of z equals 0.

3

#

Let is-extents be the exposition-only variable template defined as follows:templateconstexpr bool is-extents = false; // exposition onlytemplate<class IndexType, size_t... Args>constexpr bool is-extents<extents<IndexType, Args...>> = true; // exposition only

4

#

Let layout-mapping-alike be the exposition-only concept defined as follows:templateconcept layout-mapping-alike = requires { // exposition onlyrequires is-extents; { M::is_always_strided() } -> same_as; { M::is_always_exhaustive() } -> same_as; { M::is_always_unique() } -> same_as; bool_constant<M::is_always_strided()>::value; bool_constant<M::is_always_exhaustive()>::value; bool_constant<M::is_always_unique()>::value;};

[Note 1:

This concept checks that the functionsM::is_always_strided(),M::is_always_exhaustive(), andM::is_always_unique() exist, are constant expressions, and have a return type of bool.

— end note]

23.7.3.4.7.3 Constructors [mdspan.layout.stride.cons]

🔗

constexpr mapping() noexcept;

1

#

Preconditions: layout_right::mapping<extents_type>().required_span_size() is representable as a value of type index_type ([basic.fundamental]).

2

#

Effects: Direct-non-list-initializes extents_ with extents_type(), and for all d in the range [0, rank_), direct-non-list-initializes strides_[d] withlayout_right::mapping<extents_type>().stride(d).

🔗

template<class OtherIndexType> constexpr mapping(const extents_type& e, span<OtherIndexType, rank_> s) noexcept; template<class OtherIndexType> constexpr mapping(const extents_type& e, const array<OtherIndexType, rank_>& s) noexcept;

3

#

Constraints:

is_convertible_v<const OtherIndexType&, index_type> is true, and

is_nothrow_constructible_v<index_type, const OtherIndexType&> is true.

4

#

Preconditions:

  • (4.1)

    The result of converting s[i] to index_type is greater than 0 for all i in the range [0, rank_).

  • (4.2)

    REQUIRED-SPAN-SIZE(e, s) is representable as a value of type index_type ([basic.fundamental]).

  • (4.3)

    If rank_ is greater than 0, then there exists a permutation P of the integers in the range [0, rank_), such that s[pi] >= s[pi−1] * e.extent(pi−1) is true for all i in the range [1, rank_), where pi is the ith element of P. [Note 1: For layout_stride, this condition is necessary and sufficient for is_unique() to be true. — end note]

5

#

Effects: Direct-non-list-initializes extents_ with e, and for all d in the range [0, rank_), direct-non-list-initializes strides_[d] with as_const(s[d]).

🔗

template<class StridedLayoutMapping> constexpr explicit(see below) mapping(const StridedLayoutMapping& other) noexcept;

6

#

Constraints:

  • (6.1)

    layout-mapping-alike is satisfied.

  • (6.2)

    is_constructible_v<extents_type, typename StridedLayoutMapping::extents_type> is
    true.

  • (6.3)

    StridedLayoutMapping::is_always_unique() is true.

  • (6.4)

    StridedLayoutMapping::is_always_strided() is true.

7

#

Preconditions:

StridedLayoutMapping meets the layout mapping requirements ([mdspan.layout.reqmts]),

other.stride(r) > 0 is true for every rank index r of extents(),

other.required_span_size() is representable as a value of type index_type ([basic.fundamental]), and

OFFSET(other) == 0 is true.

8

#

Effects: Direct-non-list-initializes extents_ with other.extents(), and for all d in the range [0, rank_), direct-non-list-initializes strides_[d] with other.stride(d).

9

#

Remarks: The expression inside explicit is equivalent to:!(is_convertible_v<typename StridedLayoutMapping::extents_type, extents_type> &&(is-mapping-of<layout_left, StridedLayoutMapping> ||is-mapping-of<layout_right, StridedLayoutMapping> ||is-layout-left-padded-mapping-of ||is-layout-right-padded-mapping-of ||is-mapping-of<layout_stride, StridedLayoutMapping>))

23.7.3.4.7.4 Observers [mdspan.layout.stride.obs]

🔗

constexpr index_type required_span_size() const noexcept;

1

#

Returns: REQUIRED-SPAN-SIZE(extents(), strides_).

🔗

template<class... Indices> constexpr index_type operator()(Indices... i) const noexcept;

2

#

Constraints:

sizeof...(Indices) == rank_ is true,

(is_convertible_v<Indices, index_type> && ...) is true, and

(is_nothrow_constructible_v<index_type, Indices> && ...) is true.

3

#

Preconditions: extents_type::index-cast(i) is a multidimensional index in extents_ ([mdspan.overview]).

4

#

Effects: Let P be a parameter pack such thatis_same_v<index_sequence_for<Indices...>, index_sequence<P...>> is true.

Equivalent to:return ((static_cast<index_type>(i) * stride(P)) + ... + 0);

🔗

constexpr bool is_exhaustive() const noexcept;

5

#

Returns:

  • (5.1)

    true if rank_ is 0.

  • (5.2)

    Otherwise, true if there is a permutation P of the integers in the range [0, rank_) such that stride(p0) equals 1, andstride(pi) equals stride(pi−1) * extents().extent(pi−1) for i in the range [1, rank_), where pi is the ith element of P.

  • (5.3)

    Otherwise, false.

🔗

template<class OtherMapping> friend constexpr bool operator==(const mapping& x, const OtherMapping& y) noexcept;

6

#

Constraints:

7

#

Preconditions: OtherMapping meets the layout mapping requirements ([mdspan.layout.policy.reqmts]).

8

#

Returns: true if x.extents() == y.extents() is true,OFFSET(y) == 0 is true, and each of x.stride(r) == y.stride(r) is true for r in the range [0, x.extents().rank()).

Otherwise, false.

23.7.3.4.8 Class template layout_left_padded::mapping [mdspan.layout.leftpad]

23.7.3.4.8.1 Overview [mdspan.layout.leftpad.overview]

1

#

layout_left_padded provides a layout mapping that behaves like layout_left::mapping, except that the padding stride stride(1) can be greater than or equal to extent(0).

namespace std {template<size_t PaddingValue>templateclass layout_left_padded::mapping {public:static constexpr size_t padding_value = PaddingValue; using extents_type = Extents; using index_type = typename extents_type::index_type; using size_type = typename extents_type::size_type; using rank_type = typename extents_type::rank_type; using layout_type = layout_left_padded; private:static constexpr size_t rank_ = extents_type::rank(); // exposition onlystatic constexpr size_t first-static-extent = // exposition only extents_type::static_extent(0); // [mdspan.layout.leftpad.expo], exposition-only membersstatic constexpr size_t static-padding-stride = see below; // exposition onlypublic:// [mdspan.layout.leftpad.cons], constructorsconstexpr mapping() noexcept : mapping(extents_type{}) {}constexpr mapping(const mapping&) noexcept = default; constexpr mapping(const extents_type&); templateconstexpr mapping(const extents_type&, OtherIndexType); templateconstexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_left::mapping&); templateconstexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping&); templateconstexpr explicit(see below) mapping(const LayoutLeftPaddedMapping&); templateconstexpr explicit(see below) mapping(const LayoutRightPaddedMapping&) noexcept; constexpr mapping& operator=(const mapping&) noexcept = default; // [mdspan.layout.leftpad.obs], observersconstexpr const extents_type& extents() const noexcept { return extents_; }constexpr array<index_type, rank_> strides() const noexcept; constexpr index_type required_span_size() const noexcept; template<class... Indices>constexpr index_type operator()(Indices...) const noexcept; static constexpr bool is_always_unique() noexcept { return true; }static constexpr bool is_always_exhaustive() noexcept; static constexpr bool is_always_strided() noexcept { return true; }static constexpr bool is_unique() noexcept { return true; }constexpr bool is_exhaustive() const noexcept; static constexpr bool is_strided() noexcept { return true; }constexpr index_type stride(rank_type) const noexcept; templatefriend constexpr bool operator==(const mapping&, const LayoutLeftPaddedMapping&) noexcept; private:// [mdspan.layout.leftpad.expo], exposition-only members index_type stride-1 = static-padding-stride; // exposition only extents_type extents_{}; // exposition only// [mdspan.sub.map], submdspan mapping specializationtemplate<class... SliceSpecifiers>constexpr auto submdspan-mapping-impl(SliceSpecifiers...) const // exposition only-> see below; template<class... SliceSpecifiers>friend constexpr auto submdspan_mapping(const mapping& src, SliceSpecifiers... slices) {return src.submdspan-mapping-impl(slices...); }};}

2

#

If Extents is not a specialization of extents, then the program is ill-formed.

3

#

layout_left_padded::mapping is a trivially copyable type that models regular for each E.

4

#

Throughout [mdspan.layout.leftpad], let P_rank be the following size rank_ parameter pack of size_t values:

the empty parameter pack, if rank_ equals zero;

otherwise, 0zu, if rank_ equals one;

otherwise, the parameter pack 0zu, 1zu, …, rank_- 1.

5

#

Mandates:

  • (5.1)

    If rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() is representable as a value of type index_type.

  • (5.2)

    padding_value is representable as a value of type index_type.

  • (5.3)

    If

rank_ is greater than one,

padding_value does not equal dynamic_extent, and

first-static-extent does not equal dynamic_extent,

then LEAST-MULTIPLE-AT-LEAST(padding_value, first-static-extent) is representable as a value of type size_t, and is representable as a value of type index_type.

rank_ is greater than one,

padding_value does not equal dynamic_extent, and

extents_type::static_extent(k) does not equal dynamic_extent for all k in the range [0, extents_type::rank()),

then the product ofLEAST-MULTIPLE-AT-LEAST(padding_value, ext.static_extent(0)) and all values ext.static_extent(k) with k in the range of [1, rank_) is representable as a value of type size_t, and is representable as a value of type index_type.

23.7.3.4.8.2 Exposition-only members [mdspan.layout.leftpad.expo]

🔗

static constexpr size_t static-padding-stride = see below;

1

#

The value is

0, if rank_ equals zero or one;

otherwise, dynamic_extent, if padding_value or first-static-extent equalsdynamic_extent;

otherwise, the size_t value which isLEAST-MULTIPLE-AT-LEAST(padding_value, first-static-extent).

🔗

index_type stride-1 = static-padding-stride;

2

#

Recommended practice: Implementations should not store this value if static-padding-stride is not dynamic_extent.

[Note 1:

Using extents<index_type, static-padding-stride> instead ofindex_type as the type of stride-1 would achieve this.

— end note]

23.7.3.4.8.3 Constructors [mdspan.layout.leftpad.cons]

🔗

constexpr mapping(const extents_type& ext);

1

#

Preconditions:

  • (1.1)

    The size of the multidimensional index space ext is representable as a value of type index_type.

  • (1.2)

    If rank_ is greater than one andpadding_value does not equal dynamic_extent, then LEAST-MULTIPLE-AT-LEAST(padding_value, ext.extent(0)) is representable as a value of type index_type.

  • (1.3)

    If rank_ is greater than one andpadding_value does not equal dynamic_extent, then the product ofLEAST-MULTIPLE-AT-LEAST(padding_value, ext.extent(0)) and all values ext.extent(k) with k in the range of [1, rank_) is representable as a value of type index_type.

2

#

Effects:

Direct-non-list-initializes extents_ with ext; and

if rank_ is greater than one, direct-non-list-initializes stride-1

with ext.extent(0) if padding_value is dynamic_extent,

otherwise withLEAST-MULTIPLE-AT-LEAST(padding_value, ext.extent(0)).

🔗

template<class OtherIndexType> constexpr mapping(const extents_type& ext, OtherIndexType pad);

3

#

Constraints:

  • (3.1)

    is_convertible_v<OtherIndexType, index_type> is true.

  • (3.2)

    is_nothrow_constructible_v<index_type, OtherIndexType> is true.

4

#

Preconditions:

  • (4.1)

    pad is representable as a value of type index_type.

  • (4.2)

    extents_type::index-cast(pad) is greater than zero.

  • (4.3)

    If rank_ is greater than one, then LEAST-MULTIPLE-AT-LEAST(pad, ext.extent(0)) is representable as a value of type index_type.

  • (4.4)

    If rank_ is greater than one, then the product ofLEAST-MULTIPLE-AT-LEAST(pad, ext.extent(0)) and all values ext.extent(k) with k in the range of [1, rank_) is representable as a value of type index_type.

  • (4.5)

    If padding_value is not equal to dynamic_extent,padding_value equals extents_type::index-cast(pad).

5

#

Effects: Direct-non-list-initializes extents_ with ext, and if rank_ is greater than one, direct-non-list-initializes stride-1 withLEAST-MULTIPLE-AT-LEAST(pad, ext.extent(0)).

🔗

template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_left::mapping<OtherExtents>& other);

6

#

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

7

#

Mandates: If OtherExtents::rank() is greater than 1, then(static-padding-stride == dynamic_extent) ||(OtherExtents::static_extent(0) == dynamic_extent) ||(static-padding-stride == OtherExtents::static_extent(0)) is true.

8

#

Preconditions:

If extents_type::rank() > 1 is true andpadding_value == dynamic_extent is false, then other.stride(1) equalsLEAST-MULTIPLE-AT-LEAST(padding_value, extents_type::index-cast(other.extents().extent(0))) and

other.required_span_size() is representable as a value of type index_type.

9

#

Effects: Equivalent to mapping(other.extents()).

🔗

template<class OtherExtents> constexpr explicit(rank_ > 0) mapping(const layout_stride::mapping<OtherExtents>& other);

10

#

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

11

#

Preconditions:

  • (11.1)

    If rank_ is greater than 1 andpadding_value does not equal dynamic_extent, then other.stride(1) equalsLEAST-MULTIPLE-AT-LEAST(padding_value, extents_type::index-cast(other.extents().extent(0)))

  • (11.2)

    If rank_ is greater than 0, then other.stride(0) equals 1.

  • (11.3)

    If rank_ is greater than 2, then for all r in the range [2, rank_),other.stride(r) equals(other.extents().fwd-prod-of-extents(r) / other.extents().extent(0)) * other.stride(1)

  • (11.4)

    other.required_span_size() is representable as a value of type index_type.

12

#

Effects:

Direct-non-list-initializes extents_ with other.extents() and

if rank_ is greater than one, direct-non-list-initializes stride-1 withother.stride(1).

🔗

template<class LayoutLeftPaddedMapping> constexpr explicit(see below) mapping(const LayoutLeftPaddedMapping& other);

13

#

Constraints:

  • (13.1)

    is-layout-left-padded-mapping-of is true.

  • (13.2)

    is_constructible_v<extents_type, typename LayoutLeftPaddedMapping::extents_type>
    is true.

14

#

Mandates: If rank_ is greater than 1, thenpadding_value == dynamic_extent || LayoutLeftPaddedMapping::padding_value == dynamic_extent || padding_value == LayoutLeftPaddedMapping::padding_value is true.

15

#

Preconditions:

If rank_ is greater than 1 andpadding_value does not equal dynamic_extent, then other.stride(1) equalsLEAST-MULTIPLE-AT-LEAST(padding_value, extents_type::index-cast(other.extent(0)))

other.required_span_size() is representable as a value of type index_type.

16

#

Effects:

Direct-non-list-initializes extents_ with other.extents() and

if rank_ is greater than one, direct-non-list-initializes stride-1 with other.stride(1).

17

#

Remarks: The expression inside explicit is equivalent to:rank_> 1 &&(padding_value != dynamic_extent || LayoutLeftPaddedMapping::padding_value == dynamic_extent)

🔗

template<class LayoutRightPaddedMapping> constexpr explicit(see below) mapping(const LayoutRightPaddedMapping& other) noexcept;

18

#

Constraints:

  • (18.1)

    is-layout-right-padded-mapping-of is true or
    is-mapping-of<layout_right, LayoutRightPaddedMapping> is true.

  • (18.2)

    rank_ equals zero or one.

  • (18.3)

    is_constructible_v<extents_type, typename LayoutRightPaddedMapping::extents_-
    type> is true.

19

#

Preconditions: other.required_span_size() is representable as a value of type index_type.

20

#

Effects: Direct-non-list-initializes extents_ with other.extents().

21

#

Remarks: The expression inside explicit is equivalent to:!is_convertible_v<typename LayoutRightPaddedMapping::extents_type, extents_type>

[Note 1:

Neither the input mapping nor the mapping to be constructed uses the padding stride in the rank-0 or rank-1 case, so the padding stride does not affect either the constraints or the preconditions.

— end note]

23.7.3.4.8.4 Observers [mdspan.layout.leftpad.obs]

🔗

constexpr array<index_type, rank_> strides() const noexcept;

1

#

Returns: array<index_type, rank_>({stride(P_rank)...}).

🔗

constexpr index_type required_span_size() const noexcept;

2

#

Returns:

0 if the multidimensional index space extents_ is empty,

otherwise, *this(((extents_(P_rank) - index_type(1))...)) + 1.

🔗

template<class... Indices> constexpr size_t operator()(Indices... idxs) const noexcept;

3

#

Constraints:

  • (3.1)

    sizeof...(Indices) == rank_ is true.

  • (3.2)

    (is_convertible_v<Indices, index_type> && ...) is true.

  • (3.3)

    (is_nothrow_constructible_v<index_type, Indices> && ...) is true.

4

#

Preconditions: extents_type::index-cast(idxs) is a multidimensional index in extents() ([mdspan.overview]).

5

#

Returns: ((static_cast<index_type>(idxs) * stride(P_rank)) + ... + 0).

🔗

static constexpr bool is_always_exhaustive() noexcept;

6

#

Returns:

If rank_ equals zero or one, then true;

otherwise, if neither static-padding-stride nor first-static-extent equal dynamic_extent, then static-padding-stride == first-static-extent;

otherwise, false.

🔗

constexpr bool is_exhaustive() const noexcept;

7

#

Returns: true if rank_ equals zero or one; otherwise, extents_.extent(0) == stride(1).

🔗

constexpr index_type stride(rank_type r) const noexcept;

8

#

Preconditions: r is smaller than rank_.

9

#

Returns:

If r equals zero: 1;

otherwise, if r equals one: stride-1;

otherwise, the product of stride-1 and all values extents_.extent(k) with k in the range [1, r).

🔗

template<class LayoutLeftPaddedMapping> friend constexpr bool operator==(const mapping& x, const LayoutLeftPaddedMapping& y) noexcept;

10

#

Constraints:

  • (10.1)

    is-layout-left-padded-mapping-of is true.

  • (10.2)

    LayoutLeftPaddedMapping::extents_type::rank() == rank_ is true.

11

#

Returns: true if x.extents() == y.extents() is true andrank_ < 2 || x.stride(1) == y.
stride(1) is true.

Otherwise, false.

23.7.3.4.9 Class template layout_right_padded::mapping [mdspan.layout.rightpad]

23.7.3.4.9.1 Overview [mdspan.layout.rightpad.overview]

1

#

layout_right_padded provides a layout mapping that behaves like layout_right::mapping, except that the padding stride stride(extents_type::rank() - 2) can be greater than or equal toextents_type::extent(extents_type::rank() - 1).

namespace std {template<size_t PaddingValue>templateclass layout_right_padded::mapping {public:static constexpr size_t padding_value = PaddingValue; using extents_type = Extents; using index_type = typename extents_type::index_type; using size_type = typename extents_type::size_type; using rank_type = typename extents_type::rank_type; using layout_type = layout_right_padded; private:static constexpr size_t rank_ = extents_type::rank(); // exposition onlystatic constexpr size_t last-static-extent = // exposition only extents_type::static_extent(rank_ - 1); // [mdspan.layout.rightpad.expo], exposition-only membersstatic constexpr size_t static-padding-stride = see below; // exposition onlypublic:// [mdspan.layout.rightpad.cons], constructorsconstexpr mapping() noexcept : mapping(extents_type{}) {}constexpr mapping(const mapping&) noexcept = default; constexpr mapping(const extents_type&); templateconstexpr mapping(const extents_type&, OtherIndexType); templateconstexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_right::mapping&); templateconstexpr explicit(rank_ > 0) mapping(const layout_stride::mapping&); templateconstexpr explicit(see below) mapping(const LayoutRightPaddedMapping&); templateconstexpr explicit(see below) mapping(const LayoutLeftPaddedMapping&) noexcept; constexpr mapping& operator=(const mapping&) noexcept = default; // [mdspan.layout.rightpad.obs], observersconstexpr const extents_type& extents() const noexcept { return extents_; }constexpr array<index_type, rank_> strides() const noexcept; constexpr index_type required_span_size() const noexcept; template<class... Indices>constexpr index_type operator()(Indices...) const noexcept; static constexpr bool is_always_unique() noexcept { return true; }static constexpr bool is_always_exhaustive() noexcept; static constexpr bool is_always_strided() noexcept { return true; }static constexpr bool is_unique() noexcept { return true; }constexpr bool is_exhaustive() const noexcept; static constexpr bool is_strided() noexcept { return true; }constexpr index_type stride(rank_type) const noexcept; templatefriend constexpr bool operator==(const mapping&, const LayoutRightPaddedMapping&) noexcept; private:// [mdspan.layout.rightpad.expo], exposition-only members index_type stride-rm2 = static-padding-stride; // exposition only extents_type extents_{}; // exposition only// [mdspan.sub.map], submdspan mapping specializationtemplate<class... SliceSpecifiers>constexpr auto submdspan-mapping-impl(SliceSpecifiers...) const // exposition only-> see below; template<class... SliceSpecifiers>friend constexpr auto submdspan_mapping(const mapping& src, SliceSpecifiers... slices) {return src.submdspan-mapping-impl(slices...); }};}

2

#

If Extents is not a specialization of extents, then the program is ill-formed.

3

#

layout_right_padded::mapping is a trivially copyable type that models regular for each E.

4

#

Throughout [mdspan.layout.rightpad], let P_rank be the following size rank_ parameter pack of size_t values:

the empty parameter pack, if rank_ equals zero;

otherwise, 0zu, if rank_ equals one;

otherwise, the parameter pack 0zu, 1zu, …, rank_- 1.

5

#

Mandates:

  • (5.1)

    If rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() is representable as a value of type index_type.

  • (5.2)

    padding_value is representable as a value of type index_type.

  • (5.3)

    If

rank_ is greater than one,

padding_value does not equal dynamic_extent, and

last-static-extent does not equal dynamic_extent,

then LEAST-MULTIPLE-AT-LEAST(padding_value, last-static-extent) is representable as a value of type size_t, and is representable as a value of type index_type.

rank_ is greater than one,

padding_value does not equal dynamic_extent, and

extents_type::static_extent(k) does not equal dynamic_extent for all k in the range [0, rank_),

then the product ofLEAST-MULTIPLE-AT-LEAST(padding_value, ext.static_extent(rank_ - 1)) and all values ext.static_extent(k) with k in the range of [0, rank_ - 1) is representable as a value of type size_t, and is representable as a value of type index_type.

23.7.3.4.9.2 Exposition-only members [mdspan.layout.rightpad.expo]

🔗

static constexpr size_t static-padding-stride = see below;

1

#

The value is

0, if rank_ equals zero or one;

otherwise, dynamic_extent, if padding_value or last-static-extent equalsdynamic_extent;

otherwise, the size_t value which isLEAST-MULTIPLE-AT-LEAST(padding_value, last-static-extent).

🔗

index_type stride-rm2 = static-padding-stride;

2

#

Recommended practice: Implementations should not store this value if static-padding-stride is not dynamic_extent.

[Note 1:

Using extents<index_type, static-padding-stride> instead of index_type as the type of stride-rm2 would achieve this.

— end note]

23.7.3.4.9.3 Constructors [mdspan.layout.rightpad.cons]

🔗

constexpr mapping(const extents_type& ext);

1

#

Preconditions:

  • (1.1)

    The size of the multidimensional index space ext is representable as a value of type index_type.

  • (1.2)

    If rank_ is greater than one andpadding_value does not equal dynamic_extent, then LEAST-MULTIPLE-AT-LEAST(padding_value, ext.extent(rank_ - 1)) is representable as a value of type index_type.

  • (1.3)

    If rank_ is greater than one andpadding_value does not equal dynamic_extent, then the product ofLEAST-MULTIPLE-AT-LEAST(padding_value, ext.extent(rank_ - 1)) and all values ext.extent(k) with k in the range of [0, rank_ - 1) is representable as a value of type index_type.

2

#

Effects:

Direct-non-list-initializes extents_ with ext; and

if rank_ is greater than one, direct-non-list-initializes stride-rm2

with ext.extent(rank_ - 1) if padding_value is dynamic_extent,

otherwise withLEAST-MULTIPLE-AT-LEAST(padding_value, ext.extent(rank_ - 1)).

🔗

template<class OtherIndexType> constexpr mapping(const extents_type& ext, OtherIndexType pad);

3

#

Constraints:

  • (3.1)

    is_convertible_v<OtherIndexType, index_type> is true.

  • (3.2)

    is_nothrow_constructible_v<index_type, OtherIndexType> is true.

4

#

Preconditions:

  • (4.1)

    pad is representable as a value of type index_type.

  • (4.2)

    extents_type::index-cast(pad) is greater than zero.

  • (4.3)

    If rank_ is greater than one, then LEAST-MULTIPLE-AT-LEAST(pad, ext.extent(rank_ - 1)) is representable as a value of type index_type.

  • (4.4)

    If rank_ is greater than one, then the product ofLEAST-MULTIPLE-AT-LEAST(pad, ext.extent(rank_ - 1)) and all values ext.extent(k) with k in the range of [0, rank_ - 1) is representable as a value of type index_type.

  • (4.5)

    If padding_value is not equal to dynamic_extent,padding_value equals extents_type::index-cast(pad).

5

#

Effects: Direct-non-list-initializes extents_ with ext, and if rank_ is greater than one, direct-non-list-initializes stride-rm2 withLEAST-MULTIPLE-AT-LEAST(pad, ext.extent(rank_ - 1)).

🔗

template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_right::mapping<OtherExtents>& other);

6

#

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

7

#

Mandates: If OtherExtents::rank() is greater than 1, then(static-padding-stride == dynamic_extent) ||(OtherExtents::static_extent(rank_ - 1) == dynamic_extent) ||(static-padding-stride == OtherExtents::static_extent(rank_ - 1)) is true.

8

#

Preconditions:

If rank_ > 1 is true andpadding_value == dynamic_extent is false, thenother.stride(
rank_ - 2) equalsLEAST-MULTIPLE-AT-LEAST(padding_value, extents_type::index-cast(other.extents().extent(rank_ - 1))) and

other.required_span_size() is representable as a value of type index_type.

9

#

Effects: Equivalent to mapping(other.extents()).

🔗

template<class OtherExtents> constexpr explicit(rank_ > 0) mapping(const layout_stride::mapping<OtherExtents>& other);

10

#

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

11

#

Preconditions:

  • (11.1)

    If rank_ is greater than 1 andpadding_value does not equal dynamic_extent, then other.stride(rank_ - 2) equalsLEAST-MULTIPLE-AT-LEAST(padding_value, extents_type::index-cast(other.extents().extent(rank_ - 1)))

  • (11.2)

    If rank_ is greater than 0, then other.stride(rank_ - 1) equals 1.

  • (11.3)

    If rank_ is greater than 2, then for all r in the range [0, rank_ - 2),other.stride(r) equals(other.extents().rev-prod-of-extents(r) / other.extents().extent(rank_ - 1)) * other.stride(rank_ - 2)

  • (11.4)

    other.required_span_size() is representable as a value of type index_type.

12

#

Effects:

Direct-non-list-initializes extents_ with other.extents(); and

if rank_ is greater than one, direct-non-list-initializes stride-rm2 with other.stride(rank_ - 2).

🔗

template<class LayoutRightPaddedMapping> constexpr explicit(see below) mapping(const LayoutRightPaddedMapping& other);

13

#

Constraints:

  • (13.1)

    is-layout-right-padded-mapping-of is true.

  • (13.2)

    is_constructible_v<extents_type, typename LayoutRightPaddedMapping::extents_-
    type> is true.

14

#

Mandates: If rank_ is greater than 1, thenpadding_value == dynamic_extent || LayoutRightPaddedMapping::padding_value == dynamic_extent || padding_value == LayoutRightPaddedMapping::padding_value is true.

15

#

Preconditions:

If rank_ is greater than 1 andpadding_value does not equal dynamic_extent, then other.stride(rank_ - 2) equalsLEAST-MULTIPLE-AT-LEAST(padding_value, extents_type::index-cast(other.extent(rank_ - 1)))

other.required_span_size() is representable as a value of type index_type.

16

#

Effects:

Direct-non-list-initializes extents_ with other.extents(); and

if rank_ is greater than one, direct-non-list-initializes stride-rm2 with other.stride(rank_ - 2).

17

#

Remarks: The expression inside explicit is equivalent to:rank_ > 1 &&(padding_value != dynamic_extent || LayoutRightPaddedMapping::padding_value == dynamic_extent)

🔗

template<class LayoutLeftPaddedMapping> constexpr explicit(see below) mapping(const LayoutLeftPaddedMapping& other) noexcept;

18

#

Constraints:

  • (18.1)

    is-layout-left-padded-mapping-of is true or
    is-mapping-of<layout_left, LayoutLeftPaddedMapping> is true.

  • (18.2)

    rank_ equals zero or one.

  • (18.3)

    is_constructible_v<extents_type, typename LayoutLeftPaddedMapping::extents_type>
    is true.

19

#

Preconditions: other.required_span_size() is representable as a value of type index_type.

20

#

Effects: Direct-non-list-initializes extents_ with other.extents().

21

#

Remarks: The expression inside explicit is equivalent to:!is_convertible_v<typename LayoutLeftPaddedMapping::extents_type, extents_type>

[Note 1:

Neither the input mapping nor the mapping to be constructed uses the padding stride in the rank-0 or rank-1 case, so the padding stride affects neither the constraints nor the preconditions.

— end note]

23.7.3.4.9.4 Observers [mdspan.layout.rightpad.obs]

🔗

constexpr array<index_type, rank_> strides() const noexcept;

1

#

Returns: array<index_type, rank_>(stride(P_rank)...).

🔗

constexpr index_type required_span_size() const noexcept;

2

#

Returns: 0 if the multidimensional index space extents_ is empty, otherwise *this(((extents_(P_rank) - index_type(1))...)) + 1.

🔗

template<class... Indices> constexpr size_t operator()(Indices... idxs) const noexcept;

3

#

Constraints:

  • (3.1)

    sizeof...(Indices) == rank_ is true.

  • (3.2)

    (is_convertible_v<Indices, index_type> && ...) is true.

  • (3.3)

    (is_nothrow_constructible_v<index_type, Indices> && ...) is true.

4

#

Preconditions: extents_type::index-cast(idxs) is a multidimensional index in extents() ([mdspan.overview]).

5

#

Returns: ((static_cast<index_type>(idxs) * stride(P_rank)) + ... + 0).

🔗

static constexpr bool is_always_exhaustive() noexcept;

6

#

Returns:

If rank_ equals zero or one, then true;

otherwise, if neither static-padding-stride nor last-static-extent equal dynamic_extent, then static-padding-stride == last-static-extent;

otherwise, false.

🔗

constexpr bool is_exhaustive() const noexcept;

7

#

Returns: true if rank_ equals zero or one; otherwise,extents_.extent(rank_ - 1) == stride(rank_ - 2)

🔗

constexpr index_type stride(rank_type r) const noexcept;

8

#

Preconditions: r is smaller than rank_.

9

#

Returns:

If r equals rank_ - 1: 1;

otherwise, if r equals rank_ - 2: stride-rm2;

otherwise, the product of stride-rm2 and all values extents_.extent(k) with k in the range of [r + 1, rank_ - 1).

🔗

template<class LayoutRightPaddedMapping> friend constexpr bool operator==(const mapping& x, const LayoutRightPaddedMapping& y) noexcept;

10

#

Constraints:

  • (10.1)

    is-layout-right-padded-mapping-of is true.

  • (10.2)

    LayoutRightPaddedMapping::extents_type::rank() == rank_ is true.

11

#

Returns: true if x.extents() == y.extents() is true andrank_ < 2 || x.stride(rank_ - 2) == y.stride(rank_ - 2) is true.

Otherwise, false.

23.7.3.5 Accessor policy [mdspan.accessor]

23.7.3.5.1 General [mdspan.accessor.general]

1

#

An accessor policy defines types and operations by which a reference to a single object is created from an abstract data handle to a number of such objects and an index.

2

#

A range of indices [0,N) is an accessible range of a given data handle and an accessor if, for each i in the range, the accessor policy's access function produces a valid reference to an object.

3

#

In [mdspan.accessor.reqmts],

  • (3.1)

    A denotes an accessor policy.

  • (3.2)

    a denotes a value of type A or const A.

  • (3.3)

    p denotes a value of type A::data_handle_type or const A::data_handle_type. [Note 1: The type A::data_handle_type need not be dereferenceable. — end note]

  • (3.4)

    n, i, and j each denote values of type size_t.

23.7.3.5.2 Requirements [mdspan.accessor.reqmts]

1

#

A type A meets the accessor policy requirements if

A models copyable,

is_nothrow_move_constructible_v is true,

is_nothrow_move_assignable_v is true,

is_nothrow_swappable_v is true, and

the following types and expressions are well-formed and have the specified semantics.

🔗

typename A::element_type

2

#

Result: A complete object type that is not an abstract class type.

🔗

typename A::data_handle_type

3

#

Result: A type that models copyable, and for which is_nothrow_move_constructible_v<A::data_handle_type> is true,is_nothrow_move_assignable_v<A::data_handle_type> is true, andis_nothrow_swappable_v<A::data_handle_type> is true.

[Note 1:

The type of data_handle_type need not be element_type*.

— end note]

🔗

typename A::reference

4

#

Result: A type that modelscommon_reference_with<A::reference&&, A::element_type&>.

[Note 2:

The type of reference need not be element_type&.

— end note]

🔗

typename A::offset_policy

5

#

Result: A type OP such that:

OP meets the accessor policy requirements,

constructible_from<OP, const A&> is modeled, and

is_same_v<typename OP::element_type, typename A::element_type> is true.

🔗

a.access(p, i)

6

#

Result: A::reference

7

#

Remarks: The expression is equality preserving.

8

#

[Note 3:

Concrete accessor policies can impose preconditions for their access function.

However, they might not.

For example, an accessor wherep is span<A::element_type, dynamic_extent> andaccess(p, i) returns p[i % p.size()] does not need to impose a precondition on i.

— end note]

🔗

a.offset(p, i)

9

#

Result: A::offset_policy::data_handle_type

10

#

Returns: q such that for b being A::offset_policy(a), and any integer n for which [0, n) is an accessible range of p and a:

[0,n−i) is an accessible range of q and b; and

b.access(q, j) provides access to the same element as a.access(p, i + j), for every j in the range [0,n−i).

11

#

Remarks: The expression is equality-preserving.

23.7.3.5.3 Class template default_accessor [mdspan.accessor.default]

23.7.3.5.3.1 Overview [mdspan.accessor.default.overview]

namespace std {templatestruct default_accessor {using offset_policy = default_accessor; using element_type = ElementType; using reference = ElementType&; using data_handle_type = ElementType*; constexpr default_accessor() noexcept = default; templateconstexpr default_accessor(default_accessor) noexcept; constexpr reference access(data_handle_type p, size_t i) const noexcept; constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept; };}

1

#

default_accessor meets the accessor policy requirements.

2

#

ElementType is required to be a complete object type that is neither an abstract class type nor an array type.

3

#

Each specialization of default_accessor is a trivially copyable type that models semiregular.

4

#

[0,n) is an accessible range for an object p of type data_handle_type and an object of type default_accessor if and only if [p, p + n) is a valid range.

23.7.3.5.3.2 Members [mdspan.accessor.default.members]

🔗

template<class OtherElementType> constexpr default_accessor(default_accessor<OtherElementType>) noexcept {}

1

#

Constraints: is_convertible_v<OtherElementType()[], element_type()[]> is true.

🔗

constexpr reference access(data_handle_type p, size_t i) const noexcept;

2

#

Effects: Equivalent to: return p[i];

🔗

constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept;

3

#

Effects: Equivalent to: return p + i;

23.7.3.5.4 Class template aligned_accessor [mdspan.accessor.aligned]

23.7.3.5.4.1 Overview [mdspan.accessor.aligned.overview]

namespace std {template<class ElementType, size_t ByteAlignment>struct aligned_accessor {using offset_policy = default_accessor; using element_type = ElementType; using reference = ElementType&; using data_handle_type = ElementType*; static constexpr size_t byte_alignment = ByteAlignment; constexpr aligned_accessor() noexcept = default; template<class OtherElementType, size_t OtherByteAlignment>constexpr aligned_accessor( aligned_accessor<OtherElementType, OtherByteAlignment>) noexcept; templateconstexpr explicit aligned_accessor(default_accessor) noexcept; templateconstexpr operator default_accessor() const noexcept; constexpr reference access(data_handle_type p, size_t i) const noexcept; constexpr typename offset_policy::data_handle_type offset( data_handle_type p, size_t i) const noexcept; };}

1

#

Mandates:

byte_alignment is a power of two, and

byte_alignment >= alignof(ElementType) is true.

2

#

aligned_accessor meets the accessor policy requirements.

3

#

ElementType is required to be a complete object type that is neither an abstract class type nor an array type.

4

#

Each specialization of aligned_accessor is a trivially copyable type that models semiregular.

5

#

[0, n) is an accessible range for an object p of type data_handle_type and an object of type aligned_accessor if and only if

[p, p + n) is a valid range, and,

if n is greater than zero, then is_sufficiently_aligned<byte_alignment>(p) is true.

6

#

[Example 1:

The following function compute uses is_sufficiently_aligned to check whether a given mdspan with default_accessor has a data handle with sufficient alignment to be used with aligned_accessor<float, 4 * sizeof(float)>.

If so, the function dispatches to a function compute_using_fourfold_overalignment that requires fourfold over-alignment of arrays, but can therefore use hardware-specific instructions, such as four-wide SIMD (Single Instruction Multiple Data) instructions.

Otherwise, compute dispatches to a possibly less optimized function compute_without_requiring_overalignment that has no over-alignment requirement.

void compute_using_fourfold_overalignment( std::mdspan<float, std::dims<1>, std::layout_right, std::aligned_accessor<float, 4 * alignof(float)>> x);

void compute_without_requiring_overalignment( std::mdspan<float, std::dims<1>, std::layout_right> x);

void compute(std::mdspan<float, std::dims<1>> x) {constexpr auto byte_alignment = 4 * sizeof(float); auto accessor = std::aligned_accessor<float, byte_alignment>{}; auto x_handle = x.data_handle(); if (std::is_sufficiently_aligned<byte_alignment>(x_handle)) { compute_using_fourfold_overalignment(std::mdspan{x_handle, x.mapping(), accessor}); } else { compute_without_requiring_overalignment(x); }} — end example]

23.7.3.5.4.2 Members [mdspan.accessor.aligned.members]

🔗

template<class OtherElementType, size_t OtherByteAlignment> constexpr aligned_accessor(aligned_accessor<OtherElementType, OtherByteAlignment>) noexcept;

1

#

Constraints:

  • (1.1)

    is_convertible_v<OtherElementType()[], element_type()[]> is true.

  • (1.2)

    OtherByteAlignment >= byte_alignment is true.

2

#

Effects: None.

🔗

template<class OtherElementType> constexpr explicit aligned_accessor(default_accessor<OtherElementType>) noexcept;

3

#

Constraints: is_convertible_v<OtherElementType()[], element_type()[]> is true.

4

#

Effects: None.

🔗

constexpr reference access(data_handle_type p, size_t i) const noexcept;

5

#

Preconditions: [0, i + 1) is an accessible range for p and *this.

6

#

Effects: Equivalent to: return assume_aligned<byte_alignment>(p)[i];

🔗

template<class OtherElementType> constexpr operator default_accessor<OtherElementType>() const noexcept;

7

#

Constraints: is_convertible_v<element_type()[], OtherElementType()[]> is true.

8

#

Effects: Equivalent to: return {};

🔗

constexpr typename offset_policy::data_handle_type offset(data_handle_type p, size_t i) const noexcept;

9

#

Preconditions: [0, i + 1) is an accessible range for p and *this.

10

#

Effects: Equivalent to: return assume_aligned<byte_alignment>(p) + i;

23.7.3.6 Class template mdspan [mdspan.mdspan]

23.7.3.6.1 Overview [mdspan.mdspan.overview]

1

#

mdspan is a view of a multidimensional array of elements.

namespace std {template<class ElementType, class Extents, class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor>class mdspan {public:using extents_type = Extents; using layout_type = LayoutPolicy; using accessor_type = AccessorPolicy; using mapping_type = typename layout_type::template mapping<extents_type>; using element_type = ElementType; using value_type = remove_cv_t<element_type>; using index_type = typename extents_type::index_type; using size_type = typename extents_type::size_type; using rank_type = typename extents_type::rank_type; using data_handle_type = typename accessor_type::data_handle_type; using reference = typename accessor_type::reference; static constexpr rank_type rank() noexcept { return extents_type::rank(); }static constexpr rank_type rank_dynamic() noexcept { return extents_type::rank_dynamic(); }static constexpr size_t static_extent(rank_type r) noexcept{ return extents_type::static_extent(r); }constexpr index_type extent(rank_type r) const noexcept { return extents().extent(r); }// [mdspan.mdspan.cons], constructorsconstexpr mdspan(); constexpr mdspan(const mdspan& rhs) = default; constexpr mdspan(mdspan&& rhs) = default; template<class... OtherIndexTypes>constexpr explicit mdspan(data_handle_type ptr, OtherIndexTypes... exts); template<class OtherIndexType, size_t N>constexpr explicit(N != rank_dynamic()) mdspan(data_handle_type p, span<OtherIndexType, N> exts); template<class OtherIndexType, size_t N>constexpr explicit(N != rank_dynamic()) mdspan(data_handle_type p, const array<OtherIndexType, N>& exts); constexpr mdspan(data_handle_type p, const extents_type& ext); constexpr mdspan(data_handle_type p, const mapping_type& m); constexpr mdspan(data_handle_type p, const mapping_type& m, const accessor_type& a); template<class OtherElementType, class OtherExtents, class OtherLayoutPolicy, class OtherAccessorPolicy>constexpr explicit(see below) mdspan(const mdspan<OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessorPolicy>& other); constexpr mdspan& operator=(const mdspan& rhs) = default; constexpr mdspan& operator=(mdspan&& rhs) = default; // [mdspan.mdspan.members], memberstemplate<class... OtherIndexTypes>constexpr reference operator[](OtherIndexTypes... indices) const; templateconstexpr reference operator[](span<OtherIndexType, rank()> indices) const; templateconstexpr reference operator[](const array<OtherIndexType, rank()>& indices) const; template<class... OtherIndexTypes>constexpr reference at(OtherIndexTypes... indices) const; // freestanding-deletedtemplateconstexpr reference at(span<OtherIndexType, rank()> indices) const; // freestanding-deletedtemplateconstexpr reference at(const array<OtherIndexType, rank()>& indices) const; // freestanding-deletedconstexpr size_type size() const noexcept; constexpr bool empty() const noexcept; friend constexpr void swap(mdspan& x, mdspan& y) noexcept; constexpr const extents_type& extents() const noexcept { return map_.extents(); }constexpr const data_handle_type& data_handle() const noexcept { return ptr_; }constexpr const mapping_type& mapping() const noexcept { return map_; }constexpr const accessor_type& accessor() const noexcept { return acc_; }static constexpr bool is_always_unique(){ return mapping_type::is_always_unique(); }static constexpr bool is_always_exhaustive(){ return mapping_type::is_always_exhaustive(); }static constexpr bool is_always_strided(){ return mapping_type::is_always_strided(); }constexpr bool is_unique() const{ return map_.is_unique(); }constexpr bool is_exhaustive() const{ return map_.is_exhaustive(); }constexpr bool is_strided() const{ return map_.is_strided(); }constexpr index_type stride(rank_type r) const{ return map_.stride(r); }private: accessor_type acc_; // exposition only mapping_type map_; // exposition only data_handle_type ptr_; // exposition only}; templaterequires (is_array_v && rank_v == 1) mdspan(CArray&)-> mdspan<remove_all_extents_t, extents<size_t, extent_v<CArray, 0>>>; templaterequires (is_pointer_v<remove_reference_t>) mdspan(Pointer&&)-> mdspan<remove_pointer_t<remove_reference_t>, extents<size_t>>; template<class ElementType, class... Integrals>requires ((is_convertible_v<Integrals, size_t> && ...) && sizeof...(Integrals) > 0)explicit mdspan(ElementType*, Integrals...)-> mdspan<ElementType, extents<size_t, maybe-static-ext...>>; template<class ElementType, class OtherIndexType, size_t N> mdspan(ElementType*, span<OtherIndexType, N>)-> mdspan<ElementType, dextents<size_t, N>>; template<class ElementType, class OtherIndexType, size_t N> mdspan(ElementType*, const array<OtherIndexType, N>&)-> mdspan<ElementType, dextents<size_t, N>>; template<class ElementType, class IndexType, size_t... ExtentsPack> mdspan(ElementType*, const extents<IndexType, ExtentsPack...>&)-> mdspan<ElementType, extents<IndexType, ExtentsPack...>>; template<class ElementType, class MappingType> mdspan(ElementType*, const MappingType&)-> mdspan<ElementType, typename MappingType::extents_type, typename MappingType::layout_type>; template<class MappingType, class AccessorType> mdspan(const typename AccessorType::data_handle_type&, const MappingType&, const AccessorType&)-> mdspan<typename AccessorType::element_type, typename MappingType::extents_type, typename MappingType::layout_type, AccessorType>;}

2

#

Mandates:

ElementType is a complete object type that is neither an abstract class type nor an array type,

Extents is a specialization of extents, and

is_same_v<ElementType, typename AccessorPolicy::element_type> is true.

3

#

LayoutPolicy shall meet the layout mapping policy requirements ([mdspan.layout.policy.reqmts]), andAccessorPolicy shall meet the accessor policy requirements ([mdspan.accessor.reqmts]).

4

#

Each specialization MDS of mdspan models copyable and

is_nothrow_move_constructible_v is true,

is_nothrow_move_assignable_v is true, and

is_nothrow_swappable_v is true.

5

#

A specialization of mdspan is a trivially copyable type if its accessor_type, mapping_type, and data_handle_type are trivially copyable types.

23.7.3.6.2 Constructors [mdspan.mdspan.cons]

🔗

constexpr mdspan();

1

#

Constraints:

  • (1.1)

    rank_dynamic() > 0 is true.

  • (1.2)

    is_default_constructible_v<data_handle_type> is true.

  • (1.3)

    is_default_constructible_v<mapping_type> is true.

  • (1.4)

    is_default_constructible_v<accessor_type> is true.

2

#

Preconditions: [0, map_.required_span_size()) is an accessible range of ptr_ and acc_ for the values of map_ and acc_ after the invocation of this constructor.

3

#

Effects: Value-initializes ptr_, map_, and acc_.

🔗

template<class... OtherIndexTypes> constexpr explicit mdspan(data_handle_type p, OtherIndexTypes... exts);

4

#

Let N be sizeof...(OtherIndexTypes).

5

#

Constraints:

(is_convertible_v<OtherIndexTypes, index_type> && ...) is true,

(is_nothrow_constructible<index_type, OtherIndexTypes> && ...) is true,

N == rank() || N == rank_dynamic() is true,

is_constructible_v<mapping_type, extents_type> is true, and

is_default_constructible_v<accessor_type> is true.

6

#

Preconditions: [0, map_.required_span_size()) is an accessible range of p and acc_ for the values of map_ and acc_ after the invocation of this constructor.

7

#

Effects:

Direct-non-list-initializes ptr_ with std::move(p),

direct-non-list-initializes map_ withextents_type(static_cast<index_type>(std::move(exts))...), and

value-initializes acc_.

🔗

template<class OtherIndexType, size_t N> constexpr explicit(N != rank_dynamic()) mdspan(data_handle_type p, span<OtherIndexType, N> exts); template<class OtherIndexType, size_t N> constexpr explicit(N != rank_dynamic()) mdspan(data_handle_type p, const array<OtherIndexType, N>& exts);

8

#

Constraints:

is_convertible_v<const OtherIndexType&, index_type> is true,

is_nothrow_constructible_v<index_type, const OtherIndexType&> is true,

N == rank() || N == rank_dynamic() is true,

is_constructible_v<mapping_type, extents_type> is true, and

is_default_constructible_v<accessor_type> is true.

9

#

Preconditions: [0, map_.required_span_size()) is an accessible range of p and acc_ for the values of map_ and acc_ after the invocation of this constructor.

10

#

Effects:

Direct-non-list-initializes ptr_ with std::move(p),

direct-non-list-initializes map_ with extents_type(exts), and

value-initializes acc_.

🔗

constexpr mdspan(data_handle_type p, const extents_type& ext);

11

#

Constraints:

is_constructible_v<mapping_type, const extents_type&> is true, and

is_default_constructible_v<accessor_type> is true.

12

#

Preconditions: [0, map_.required_span_size()) is an accessible range of p and acc_ for the values of map_ and acc_ after the invocation of this constructor.

13

#

Effects:

Direct-non-list-initializes ptr_ with std::move(p),

direct-non-list-initializes map_ with ext, and

value-initializes acc_.

🔗

constexpr mdspan(data_handle_type p, const mapping_type& m);

14

#

Constraints: is_default_constructible_v<accessor_type> is true.

15

#

Preconditions: [0, m.required_span_size()) is an accessible range of p and acc_ for the value of acc_ after the invocation of this constructor.

16

#

Effects:

Direct-non-list-initializes ptr_ with std::move(p),

direct-non-list-initializes map_ with m, and

value-initializes acc_.

🔗

constexpr mdspan(data_handle_type p, const mapping_type& m, const accessor_type& a);

17

#

Preconditions: [0, m.required_span_size()) is an accessible range of p and a.

18

#

Effects:

Direct-non-list-initializes ptr_ with std::move(p),

direct-non-list-initializes map_ with m, and

direct-non-list-initializes acc_ with a.

🔗

template<class OtherElementType, class OtherExtents, class OtherLayoutPolicy, class OtherAccessor> constexpr explicit(see below) mdspan(const mdspan<OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessor>& other);

19

#

Constraints:

is_constructible_v<mapping_type, const OtherLayoutPolicy::template mapping&> is true, and

is_constructible_v<accessor_type, const OtherAccessor&> is true.

20

#

Mandates:

is_constructible_v<data_handle_type, const OtherAccessor::data_handle_type&> is
true, and

is_constructible_v<extents_type, OtherExtents> is true.

21

#

Preconditions: [0, map_.required_span_size()) is an accessible range of ptr_ and acc_ for values of ptr_, map_, and acc_ after the invocation of this constructor.

22

#

Hardened preconditions: For each rank index r of extents_type,static_extent(r) == dynamic_extent || static_extent(r) == other.extent(r) is true.

23

#

Effects:

Direct-non-list-initializes ptr_ with other.ptr_,

direct-non-list-initializes map_ with other.map_, and

direct-non-list-initializes acc_ with other.acc_.

24

#

Remarks: The expression inside explicit is equivalent to:!is_convertible_v<const OtherLayoutPolicy::template mapping&, mapping_type>|| !is_convertible_v<const OtherAccessor&, accessor_type>

23.7.3.6.3 Members [mdspan.mdspan.members]

🔗

template<class... OtherIndexTypes> constexpr reference operator[](OtherIndexTypes... indices) const;

1

#

Constraints:

(is_convertible_v<OtherIndexTypes, index_type> && ...) is true,

(is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...) is true, and

sizeof...(OtherIndexTypes) == rank() is true.

2

#

Let I be extents_type::index-cast(std::move(indices)).

3

#

Hardened preconditions: I is a multidimensional index in extents().

[Note 1:

This implies thatmap_(I) < map_.required_span_size() is true.

— end note]

4

#

Effects: Equivalent to:return acc_.access(ptr_, map_(static_cast<index_type>(std::move(indices))...));

🔗

template<class OtherIndexType> constexpr reference operator[](span<OtherIndexType, rank()> indices) const; template<class OtherIndexType> constexpr reference operator[](const array<OtherIndexType, rank()>& indices) const;

5

#

Constraints:

is_convertible_v<const OtherIndexType&, index_type> is true, and

is_nothrow_constructible_v<index_type, const OtherIndexType&> is true.

6

#

Effects: Let P be a parameter pack such thatis_same_v<make_index_sequence<rank()>, index_sequence<P...>> is true.

Equivalent to:return operator;

🔗

template<class... OtherIndexTypes> constexpr reference at(OtherIndexTypes... indices) const;

7

#

Constraints:

(is_convertible_v<OtherIndexTypes, index_type> && ...) is true,

(is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...) is true, and

sizeof...(OtherIndexTypes) == rank() is true.

8

#

Let I be extents_type::index-cast(std::move(indices)).

9

#

Returns: (*this)[I...].

10

#

Throws: out_of_range if I is not a multidimensional index in extents().

🔗

template<class OtherIndexType> constexpr reference at(span<OtherIndexType, rank()> indices) const; template<class OtherIndexType> constexpr reference at(const array<OtherIndexType, rank()>& indices) const;

11

#

Constraints:

is_convertible_v<const OtherIndexType&, index_type> is true, and

is_nothrow_constructible_v<index_type, const OtherIndexType&> is true.

12

#

Effects: Let P be a parameter pack such thatis_same_v<make_index_sequence<rank()>, index_sequence<P...>> is true.

Equivalent to:return at(extents_type::index-cast(as_const(indices[P]))...);

🔗

constexpr size_type size() const noexcept;

13

#

Preconditions: The size of the multidimensional index space extents() is representable as a value of type size_type ([basic.fundamental]).

14

#

Returns: extents().fwd-prod-of-extents(rank()).

🔗

constexpr bool empty() const noexcept;

15

#

Returns: true if the size of the multidimensional index space extents() is 0, otherwise false.

🔗

friend constexpr void swap(mdspan& x, mdspan& y) noexcept;

16

#

Effects: Equivalent to:swap(x.ptr_, y.ptr_); swap(x.map_, y.map_); swap(x.acc_, y.acc_);

23.7.3.7 submdspan [mdspan.sub]

23.7.3.7.1 Overview [mdspan.sub.overview]

1

#

The submdspan facilities create a new mdspan viewing a subset of elements of an existing input mdspan.

The subset viewed by the created mdspan is determined by the SliceSpecifier arguments.

2

#

For each function defined in [mdspan.sub] that takes a parameter pack named slices as an argument:

let index_type be

M::index_type if the function is a member of a class M,

otherwise, remove_reference_t<decltype(src)>::index_type if the function has a parameter named src,

otherwise, the same type as the function's template argument IndexType;

let rank be the number of elements in slices;

let sk be the kth element of slices;

let Sk be the type of sk; and

let map-rank be an array<size_t, rank> such that for each k in the range [0, rank),map-rank[k] equals:

dynamic_extent if Sk models convertible_to<index_type>,

otherwise, the number of types Sj with j<k that do not model convertible_to<index_type>.

23.7.3.7.2 strided_slice [mdspan.sub.strided.slice]

1

#

strided_slice represents a set ofextent regularly spaced integer indices.

The indices start at offset, and increase by increments of stride.

🔗

namespace std {template<class OffsetType, class ExtentType, class StrideType>struct strided_slice {using offset_type = OffsetType; using extent_type = ExtentType; using stride_type = StrideType; no_unique_address offset_type offset{}; no_unique_address extent_type extent{}; no_unique_address stride_type stride{}; };}

2

#

strided_slice has the data members and special members specified above.

It has no base classes or members other than those specified.

3

#

Mandates: OffsetType, ExtentType, and StrideType are signed or unsigned integer types, or model integral-constant-like.

[Note 1:

strided_slice{.offset = 1, .extent = 10, .stride = 3} indicates the indices 1, 4, 7, and 10.

Indices are selected from the half-open interval [1, 1 + 10).

— end note]

23.7.3.7.3 submdspan_mapping_result [mdspan.sub.map.result]

1

#

Specializations of submdspan_mapping_result are returned by overloads of submdspan_mapping.

🔗

namespace std {templatestruct submdspan_mapping_result {no_unique_address LayoutMapping mapping = LayoutMapping(); size_t offset{}; };}

2

#

submdspan_mapping_result has the data members and special members specified above.

It has no base classes or members other than those specified.

3

#

LayoutMapping shall meet the layout mapping requirements ([mdspan.layout.policy.reqmts]).

23.7.3.7.4 Exposition-only helpers [mdspan.sub.helpers]

🔗

`template constexpr T de-ice(T val) { return val; } template<integral-constant-like T> constexpr auto de-ice(T) { return T::value; }

template<class IndexType, size_t k, class... SliceSpecifiers> constexpr IndexType first_(SliceSpecifiers... slices); `

1

#

Mandates: IndexType is a signed or unsigned integer type.

2

#

Let ϕk denote the following value:

sk if Sk models convertible_to;

otherwise,get<0>(sk) if Sk models index-pair-like;

otherwise,de-ice(sk.offset) if Sk is a specialization of strided_slice;

otherwise,0.

3

#

Preconditions: ϕk is representable as a value of type IndexType.

4

#

Returns: extents::index-cast•k).

🔗

template<size_t k, class Extents, class... SliceSpecifiers> constexpr auto last_(const Extents& src, SliceSpecifiers... slices);

5

#

Mandates: Extents is a specialization of extents.

6

#

Let index_type be typename Extents::index_type.

7

#

Let λk denote the following value:

de-ice(sk) + 1 if Sk models convertible_to<index_type>; otherwise

get<1>(sk) if Sk models index-pair-like<index_type>; otherwise

de-ice(sk.offset) +de-ice(sk.extent) if Sk is a specialization of strided_slice; otherwise

src.extent(k).

8

#

Preconditions: λk is representable as a value of type index_type.

9

#

Returns: Extents::index-cast(λk).

🔗

template<class IndexType, size_t N, class... SliceSpecifiers> constexpr array<IndexType, sizeof...(SliceSpecifiers)> src-indices(const array<IndexType, N>& indices, SliceSpecifiers... slices);

10

#

Mandates: IndexType is a signed or unsigned integer type.

11

#

Returns: An array<IndexType, sizeof...(SliceSpecifiers)> src_idx such that for each k in the range [0, sizeof...(SliceSpecifiers)),src_idx[k] equals

first_<IndexType, k>(slices...) for each k where map-rank[k] equalsdynamic_extent,

otherwise,first_<IndexType, k>(slices...) +indices[map-rank[k]].

23.7.3.7.5 submdspan_extents function [mdspan.sub.extents]

🔗

template<class IndexType, size_t... Extents, class... SliceSpecifiers> constexpr auto submdspan_extents(const extents<IndexType, Extents...>& src, SliceSpecifiers... slices);

1

#

Constraints: sizeof...(slices) equals sizeof...(Extents).

2

#

Mandates: For each rank index k of src.extents(), exactly one of the following is true:

Sk models convertible_to,

Sk models index-pair-like,

is_convertible_v<Sk, full_extent_t> is true, or

Sk is a specialization of strided_slice.

3

#

Preconditions: For each rank index k of src.extents(), all of the following are true:

if Sk is a specialization of strided_slice

sk.extent=0, or

sk.stride>0

0 ≤ first_<IndexType, k>(slices...) ≤ last_(src, slices...) ≤ src.extent(k)

4

#

Let SubExtents be a specialization of extents such that:

SubExtents::rank() equals the number of k such thatSk does not model convertible_to; and

for each rank index k of Extents such thatmap-rank[k] != dynamic_extent is true,SubExtents::static_extent(map-rank[k]) equals:

Extents::static_extent(k) if is_convertible_v<Sk, full_extent_t> is true; otherwise

de-ice(tuple_element_t<1, Sk>()) -de-ice(tuple_element_t<0, Sk>()) if Sk models index-pair-like, and both tuple_element_t<0, Sk> and tuple_element_t<1, Sk> model integral-constant-like; otherwise

0, if Sk is a specialization of strided_slice, whose extent_type models integral-constant-like, for which extent_type() equals zero; otherwise

1 + (de-ice(Sk::extent_type()) - 1) /de-ice(Sk::stride_type()), if Sk is a specialization of strided_slice whose extent_type and stride_type model integral-constant-like;

otherwise, dynamic_extent.

5

#

Returns: A value ext of type SubExtents such that for each k for which map-rank[k] != dynamic_extent is true,ext.extent(map-rank[k]) equals:

sk.extent == 0 ? 0 : 1 + (de-ice(sk.extent) - 1) / de-ice(sk.stride) if Sk is a specialization of strided_slice,

otherwise,last_(src, slices...) - first_<IndexType, k>(slices...).

23.7.3.7.6 Specializations of submdspan_mapping [mdspan.sub.map]

23.7.3.7.6.1 Common [mdspan.sub.map.common]

1

#

The following elements apply to all functions in [mdspan.sub.map].

2

#

Constraints: sizeof...(slices) equals extents_type::rank().

3

#

Mandates: For each rank index k of extents(), exactly one of the following is true:

Sk models convertible_to<index_type>,

Sk models index-pair-like<index_type>,

is_convertible_v<Sk, full_extent_t> is true, or

Sk is a specialization of strided_slice.

4

#

Preconditions: For each rank index k of extents(), all of the following are true:

if Sk is a specialization of strided_slice,sk.extent is equal to zero orsk.stride is greater than zero; and

0 ≤ first_<index_type, k>(slices...)
0 ≤ last_(extents(), slices...)
0 ≤ extents().extent(k)

5

#

Let sub_ext be the result of submdspan_extents(extents(), slices...) and let SubExtents be decltype(sub_ext).

6

#

Let sub_strides be an array<SubExtents::index_type, SubExtents::rank()> such that for each rank index k of extents() for which map-rank[k] is not dynamic_extent,sub_strides[map-rank[k]] equals:

stride(k) * de-ice(sk.stride) if Sk is a specialization of strided_slice andsk.stride < sk.extent is true;

otherwise, stride(k).

7

#

Let P be a parameter pack such that is_same_v<make_index_sequence<rank()>, index_sequence<P...>> is true.

8

#

If first_<index_type, k>(slices...) equals extents().extent(k) for any rank index k of extents(), then let offset be a value of type size_t equal to(*this).required_span_size().

Otherwise, let offset be a value of type size_t equal to(*this)(first_<index_type, P>(slices...)...).

9

#

Given a layout mapping type M, a type S is aunit-stride slice for M if

S is a specialization of strided_slice where S::stride_type models integral-constant-like and S::stride_type::value equals 1,

S models index-pair-like<M::index_type>, or

is_convertible_v<S, full_extent_t> is true.

23.7.3.7.6.2 layout_left specialization of submdspan_mapping [mdspan.sub.map.left]

🔗

template<class Extents> template<class... SliceSpecifiers> constexpr auto layout_left::mapping<Extents>::submdspan-mapping-impl( SliceSpecifiers... slices) const -> see below;

1

#

Returns:

submdspan_mapping_result{*this, 0}, if Extents::rank() == 0 is true;

otherwise,submdspan_mapping_result{layout_left::mapping(sub_ext), offset}, if SubExtents::rank() == 0 is true;

otherwise,submdspan_mapping_result{layout_left::mapping(sub_ext), offset}, if

for each k in the range [0, SubExtents::rank() - 1)), is_convertible_v<Sk, full_extent_t> is true; and

for k equal to SubExtents::rank() - 1, Sk is a unit-stride slice for mapping;

[Note 1: If the above conditions are true, all Sk with k larger than SubExtents::rank() - 1 are convertible to index_type. — end note]

otherwise,submdspan_mapping_result{layout_left_padded<S_static>::mapping(sub_ext, stride(u + 1)), offset} if for a value u for which u+1 is the smallest value p larger than zero for which Sp is a unit-stride slice for mapping, the following conditions are met:

S0 is a unit-stride slice for mapping; and

for each k in the range [u + 1, u + SubExtents::rank() - 1),is_convertible_v<Sk, full_extent_t> is true; and

for k equal to u + SubExtents::rank() - 1,Sk is a unit-stride slice for mapping;

and where S_static is:

dynamic_extent, if static_extent(k) is dynamic_extent for any k in the range [0, u + 1),

otherwise, the product of all valuesstatic_extent(k) for k in the range [0, u + 1);

otherwise,submdspan_mapping_result{layout_stride::mapping(sub_ext, sub_strides), offset}

23.7.3.7.6.3 layout_right specialization of submdspan_mapping [mdspan.sub.map.right]

🔗

template<class Extents> template<class... SliceSpecifiers> constexpr auto layout_right::mapping<Extents>::submdspan-mapping-impl( SliceSpecifiers... slices) const -> see below;

1

#

Returns:

submdspan_mapping_result{*this, 0}, if Extents::rank() == 0 is true;

otherwise,submdspan_mapping_result{layout_right::mapping(sub_ext), offset}, if SubExtents::rank() == 0 is true;

otherwise,submdspan_mapping_result{layout_left::mapping(sub_ext), offset}, if

for each k in the range [rank_ - SubExtents::rank() + 1, rank_), is_convertible_v<Sk, full_extent_t> is true; and

for k equal to _rank - SubExtents::rank(), Sk is a unit-stride slice for mapping;

[Note 1: If the above conditions are true, all Sk with k<_rank - SubExtents::rank() are convertible to index_type. — end note]

otherwise,submdspan_mapping_result{layout_right_padded<S_static>::mapping(sub_ext, stride(rank_ - u - 2)), offset} if for a value u for which rank_−ˆ’2 is the largest value p smaller than rank_ - 1 for which Sp is a unit-stride slice for mapping, the following conditions are met:

for k equal to rank_ - 1,Sk is a unit-stride slice for mapping; and

for each k in the range [rank_ - SubExtents::rank() - u + 1, rank_ - u - 1),is_convertible_v<Sk, full_extent_t> is true; and

for k equal to rank_ - SubExtents::rank() - u,
Sk is a unit-stride slice for mapping;

and where S_static is:

dynamic_extent, if static_extent(k) is dynamic_extent for any k in the range [rank_ - u - 1, rank_),

otherwise, the product of all valuesstatic_extent(k) for k in the range [rank_ - u - 1, rank_);

otherwise,submdspan_mapping_result{layout_stride::mapping(sub_ext, sub_strides), offset}

23.7.3.7.6.4 layout_stride specialization of submdspan_mapping [mdspan.sub.map.stride]

🔗

template<class Extents> template<class... SliceSpecifiers> constexpr auto layout_stride::mapping<Extents>::submdspan-mapping-impl( SliceSpecifiers... slices) const -> see below;

1

#

Returns:

submdspan_mapping_result{*this, 0}, if Extents::rank() == 0 is true;

otherwise,submdspan_mapping_result{layout_stride::mapping(sub_ext, sub_strides), offset}

23.7.3.7.6.5 layout_left_padded specialization of submdspan_mapping [mdspan.sub.map.leftpad]

🔗

template<class Extents> template<class... SliceSpecifiers> constexpr auto layout_left_padded::mapping<Extents>::submdspan-mapping-impl( SliceSpecifiers... slices) const -> see below;

1

#

Returns:

submdspan_mapping_result{*this, 0}, if Extents::rank() == 0 is true;

otherwise,submdspan_mapping_result{layout_left::mapping(sub_ext), offset}, if rank_ == 1 is true orSubExtents::rank() == 0 is true;

otherwise,submdspan_mapping_result{layout_left::mapping(sub_ext), offset}, if

SubExtents::rank() == 1 is true and

S0 is a unit-stride slice for mapping;

otherwise,submdspan_mapping_result{layout_left_padded<S_static>::mapping(sub_ext, stride(u + 1)), offset} if for a value u for which u + 1 is the smallest value p larger than zero for which Sp is a unit-stride slice for mapping, the following conditions are met:

S0 is a unit-stride slice for mapping; and

for each k in the range [u + 1, u + SubExtents::rank() - 1),is_convertible_v<Sk, full_extent_t> is true; and

for k equal to u + SubExtents::rank() - 1,Sk is a unit-stride slice for mapping;

where S_static is:

dynamic_extent, if static-padding-stride is dynamic_extent orstatic_extent(k) is dynamic_extent for any k in the range [1, u + 1),

otherwise, the product of static-padding-stride and all values static_extent(k) for k in the range [1, u + 1);

otherwise,submdspan_mapping_result{layout_stride::mapping(sub_ext, sub_strides), offset}

23.7.3.7.6.6 layout_right_padded specialization of submdspan_mapping [mdspan.sub.map.rightpad]

🔗

template<class Extents> template<class... SliceSpecifiers> constexpr auto layout_right_padded::mapping<Extents>::submdspan-mapping-impl( SliceSpecifiers... slices) const -> see below;

1

#

Returns:

submdspan_mapping_result{*this, 0}, if rank_ == 0 is true;

otherwise,submdspan_mapping_result{layout_right::mapping(sub_ext), offset},
if rank_ == 1 is true orSubExtents::rank() == 0 is true;

otherwise,submdspan_mapping_result{layout_right::mapping(sub_ext), offset}, if

SubExtents::rank() == 1 is true and

for k equal to rank_ - 1,Sk is a unit-stride slice for mapping;

otherwise,submdspan_mapping_result{layout_right_padded<S_static>::mapping(sub_ext, stride(rank_ - u - 2)), offset} if for a value u for which rank_ - u - 2 is the largest value p smaller than rank_ - 1 for which Sp is a unit-stride slice for mapping, the following conditions are met:

for k equal to rank_ - 1,Sk is a unit-stride slice for mapping; and

for each k in the range [rank_ - SubExtents::rank() - u + 1, rank_ - u - 1)),is_convertible_v<Sk, full_extent_t> is true; and

for k equal to rank_ - SubExtents::rank() - u,
Sk is a unit-stride slice for mapping;

and where S_static is:

dynamic_extent if static-padding-stride is dynamic_extent or for any k in the range [rank_ - u - 1, rank_ - 1)static_extent(k) is dynamic_extent,

otherwise, the product of static-padding-stride and all values static_extent(k) with k in the range [rank_ - u - 1, rank_ - 1);

otherwise,submdspan_mapping_result{layout_stride::mapping(sub_ext, sub_strides), offset}

23.7.3.7.7 submdspan function template [mdspan.sub.sub]

🔗

template<class ElementType, class Extents, class LayoutPolicy, class AccessorPolicy, class... SliceSpecifiers> constexpr auto submdspan( const mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>& src, SliceSpecifiers... slices) -> see below;

1

#

Let index_type be typename Extents::index_type.

2

#

Let sub_map_offset be the result ofsubmdspan_mapping(src.mapping(), slices...).

[Note 1:

This invocation of submdspan_mapping selects a function call via overload resolution on a candidate set that includes the lookup set found by argument-dependent lookup ([basic.lookup.argdep]).

— end note]

3

#

Constraints:

sizeof...(slices) equals Extents::rank(), and

the expression submdspan_mapping(src.mapping(), slices...) is well-formed when treated as an unevaluated operand.

4

#

Mandates:

  • (4.1)

    decltype(submdspan_mapping(src.mapping(), slices...)) is a specialization of submdspan_mapping_result.

  • (4.2)

    is_same_v<remove_cvref_t<decltype(sub_map_offset.mapping.extents())>,decltype(submdspan_extents(src.mapping(), slices...))> is true.

  • (4.3)

    For each rank index k of src.extents(), exactly one of the following is true:

Sk models convertible_to<index_type>,

Sk models index-pair-like<index_type>,

is_convertible_v<Sk, full_extent_t> is true, or

Sk is a specialization of strided_slice.

5

#

Preconditions:

For each rank index k of src.extents(), all of the following are true:

if Sk is a specialization of strided_slice + (5.1.1.1) sk.extent=0, or

+
      [(5.1.1.2)](#mdspan.sub.sub-5.1.1.2)

sk.stride>0

0 ≤ first_<index_type, k>(slices...) ≤ last_(src.extents(), slices...) ≤ src.extent(k)

sub_map_offset.mapping.extents() == submdspan_extents(src.mapping(), slices...) is true; and

for each integer pack I which is a multidimensional index in sub_map_offset.mapping.extents(),sub_map_offset.mapping(I...) + sub_map_offset.offset == src.mapping()(src-indices(array{I...}, slices...)) is true.

[Note 2:

These conditions ensure that the mapping returned by submdspan_mapping matches the algorithmically expected index-mapping given the slice specifiers.

— end note]

6

#

Effects: Equivalent to:auto sub_map_result = submdspan_mapping(src.mapping(), slices...);return mdspan(src.accessor().offset(src.data_handle(), sub_map_result.offset), sub_map_result.mapping, typename AccessorPolicy::offset_policy(src.accessor()));

7

#

[Example 1:

Given a rank-3 mdspan grid3d representing a three-dimensional grid of regularly spaced points in a rectangular prism, the function zero_surface sets all elements on the surface of the 3-dimensional shape to zero.

It does so by reusing a function zero_2d that takes a rank-2 mdspan.

// zero out all elements in an mdspantemplate<class T, class E, class L, class A>void zero_2d(mdspan<T, E, L, A> a) {static_assert(a.rank() == 2); for (int i = 0; i < a.extent(0); i++)for (int j = 0; j < a.extent(1); j++) a[i, j] = 0;}// zero out just the surfacetemplate<class T, class E, class L, class A>void zero_surface(mdspan<T, E, L, A> grid3d) {static_assert(grid3d.rank() == 3); zero_2d(submdspan(grid3d, 0, full_extent, full_extent)); zero_2d(submdspan(grid3d, full_extent, 0, full_extent)); zero_2d(submdspan(grid3d, full_extent, full_extent, 0)); zero_2d(submdspan(grid3d, grid3d.extent(0) - 1, full_extent, full_extent)); zero_2d(submdspan(grid3d, full_extent, grid3d.extent(1) - 1, full_extent)); zero_2d(submdspan(grid3d, full_extent, full_extent, grid3d.extent(2) - 1));} — end example]