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

13 KiB
Raw Permalink Blame History

[mdspan.layout.right]

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.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();