Files
2025-10-25 03:02:53 +03:00

103 KiB
Raw Permalink Blame History

[mdspan.layout]

23 Containers library [containers]

23.7 Views [views]

23.7.3 Multidimensional access [views.multidim]

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.