[mdspan.layout] (original) (raw)

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]

23.7.3.4.2 Requirements [mdspan.layout.reqmts]

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

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

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

23.7.3.4.5.1 Overview [mdspan.layout.left.overview]

23.7.3.4.5.2 Constructors [mdspan.layout.left.cons]

23.7.3.4.5.3 Observers [mdspan.layout.left.obs]

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

23.7.3.4.6.1 Overview [mdspan.layout.right.overview]

23.7.3.4.6.2 Constructors [mdspan.layout.right.cons]

23.7.3.4.6.3 Observers [mdspan.layout.right.obs]

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

23.7.3.4.7.1 Overview [mdspan.layout.stride.overview]

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

23.7.3.4.7.3 Constructors [mdspan.layout.stride.cons]

23.7.3.4.7.4 Observers [mdspan.layout.stride.obs]

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]

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

23.7.3.4.8.3 Constructors [mdspan.layout.leftpad.cons]

23.7.3.4.8.4 Observers [mdspan.layout.leftpad.obs]

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]

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

23.7.3.4.9.3 Constructors [mdspan.layout.rightpad.cons]

23.7.3.4.9.4 Observers [mdspan.layout.rightpad.obs]


23.7.3.4.1 General [mdspan.layout.general]

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

23.7.3.4.2 Requirements [mdspan.layout.reqmts]

A type M meets the layout mapping requirements if

Result: A type that is a specialization of extents.

Result: typename M​::​extents_type​::​index_type.

Result: typename M​::​extents_type​::​rank_type.

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.

Result: const typename M​::​extents_type&

Result: typename M​::​index_type

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

Result: typename M​::​index_type

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.

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_]

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_]

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

[Note 3:

This implies that for a strided layout.

— _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_]

Preconditions: m.is_strided() is true.

Result: typename M​::​index_type

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

[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_]

Returns: true only if m.is_unique() is truefor 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()

Returns: true only if m.is_exhaustive() is truefor 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_]

Returns: true only if m.is_strided() is truefor 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]

A type MP meets the layout mapping policy requirements if for a type E that is a specialization of extents,MP​::​mapping<E> is valid and denotes a type Xthat 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 { template<class Extents> class mapping;};struct layout_right { template<class Extents> class mapping;};struct layout_stride { template<class Extents> class mapping;};template<size_t PaddingValue> struct layout_left_padded { template<class Extents> class mapping;};template<size_t PaddingValue> struct layout_right_padded { template<class Extents> class mapping;};}

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<T> is truefor 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]

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 { template<class Extents> class layout_left::mapping { public: using extents_type = Extents;using index_type = extents_type::index_type;using size_type = extents_type::size_type;using rank_type = extents_type::rank_type;using layout_type = layout_left;constexpr mapping() noexcept = default;constexpr mapping(const mapping&) noexcept = default;constexpr mapping(const extents_type&) noexcept;template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const mapping<OtherExtents>&) noexcept;template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_right::mapping<OtherExtents>&) noexcept;template<class LayoutLeftPaddedMapping> constexpr explicit(!is_convertible_v<typename LayoutLeftPaddedMapping::extents_type, extents_type>) mapping(const LayoutLeftPaddedMapping&) noexcept;template<class OtherExtents> constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping<OtherExtents>&);constexpr mapping& operator=(const mapping&) noexcept = default;constexpr 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;template<class OtherExtents> friend constexpr bool operator==(const mapping&, const mapping<OtherExtents>&) noexcept;private: extents_type extents_{}; template<class... SliceSpecifiers> constexpr auto submdspan-mapping-impl(SliceSpecifiers...) const -> see below;template<class... SliceSpecifiers> friend constexpr auto submdspan_mapping( const mapping& src, SliceSpecifiers... slices) { return src.submdspan-mapping-impl(slices...);} };}

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

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

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;

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

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;

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

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

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;

Constraints:

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

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;

Constraints:

Mandates: If

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

Preconditions:

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

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

Preconditions:

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;

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

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

Constraints:

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

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;

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

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

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

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

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

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]

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 { template<class Extents> class layout_right::mapping { public: using extents_type = Extents;using index_type = extents_type::index_type;using size_type = extents_type::size_type;using rank_type = extents_type::rank_type;using layout_type = layout_right;constexpr mapping() noexcept = default;constexpr mapping(const mapping&) noexcept = default;constexpr mapping(const extents_type&) noexcept;template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const mapping<OtherExtents>&) noexcept;template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_left::mapping<OtherExtents>&) noexcept;template<class LayoutRightPaddedMapping> constexpr explicit(!is_convertible_v<typename LayoutRightPaddedMapping::extents_type, extents_type>) mapping(const LayoutRightPaddedMapping&) noexcept;template<class OtherExtents> constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping<OtherExtents>&) noexcept;constexpr mapping& operator=(const mapping&) noexcept = default;constexpr 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;template<class OtherExtents> friend constexpr bool operator==(const mapping&, const mapping<OtherExtents>&) noexcept;private: extents_type extents_{}; template<class... SliceSpecifiers> constexpr auto submdspan-mapping-impl(SliceSpecifiers...) const -> see below;template<class... SliceSpecifiers> friend constexpr auto submdspan_mapping( const mapping& src, SliceSpecifiers... slices) { return src.submdspan-mapping-impl(slices...);} };}

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

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

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;

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

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;

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

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

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;

Constraints:

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

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;

Constraints:

Mandates: If

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

Preconditions:

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;

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

Preconditions:

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;

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

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

Constraints:

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

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;

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

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

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

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

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

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]

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

namespace std { template<class Extents> class layout_stride::mapping { public: using extents_type = Extents;using index_type = extents_type::index_type;using size_type = extents_type::size_type;using rank_type = extents_type::rank_type;using layout_type = layout_stride;private: static constexpr rank_type rank_ = extents_type::rank(); public: constexpr mapping() noexcept;constexpr mapping(const mapping&) noexcept = default;template<class OtherIndexType> constexpr mapping(const extents_type&, span<OtherIndexType, _rank__>) noexcept;template<class OtherIndexType> constexpr mapping(const extents_type&, const array<OtherIndexType, _rank__>&) noexcept;template<class StridedLayoutMapping> constexpr explicit(see below) mapping(const StridedLayoutMapping&) noexcept;constexpr mapping& operator=(const mapping&) noexcept = default;constexpr 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]; } template<class OtherMapping> friend constexpr bool operator==(const mapping&, const OtherMapping&) noexcept;private: extents_type extents_{}; array<index_type, _rank__> strides_{}; template<class... SliceSpecifiers> constexpr auto submdspan-mapping-impl(SliceSpecifiers...) const -> see below;template<class... SliceSpecifiers> friend constexpr auto submdspan_mapping( const mapping& src, SliceSpecifiers... slices) { return src.submdspan-mapping-impl(slices...);} };}

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

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

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]

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

Let OFFSET(m) be:

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

Let layout-mapping-alike be the exposition-only concept defined as follows:template<class M> concept layout-mapping-alike = requires { requires is-extents<typename M::extents_type>;{ M::is_always_strided() } -> same_as<bool>;{ M::is_always_exhaustive() } -> same_as<bool>;{ M::is_always_unique() } -> same_as<bool>; 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;

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

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;

Constraints:

Preconditions:

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;

Constraints:

Preconditions:

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

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<StridedLayoutMapping> || is-layout-right-padded-mapping-of<StridedLayoutMapping> || 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;

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

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

Constraints:

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

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;

Returns:

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

Constraints:

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

Returns: true if x.extents() == y.extents() is true,OFFSET(y) == 0 is true, and each of x.stride(r) == y.stride(r) is truefor 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]

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> template<class Extents> class layout_left_padded<PaddingValue>::mapping { public: static constexpr size_t padding_value = PaddingValue;using extents_type = Extents;using index_type = extents_type::index_type;using size_type = extents_type::size_type;using rank_type = extents_type::rank_type;using layout_type = layout_left_padded<PaddingValue>;private: static constexpr size_t rank_ = extents_type::rank(); static constexpr size_t first-static-extent = extents_type::static_extent(0);static constexpr size_t static-padding-stride = see below; public: constexpr mapping() noexcept : mapping(extents_type{}) {} constexpr mapping(const mapping&) noexcept = default;constexpr mapping(const extents_type&);template<class OtherIndexType> constexpr mapping(const extents_type&, OtherIndexType);template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_left::mapping<OtherExtents>&);template<class OtherExtents> constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping<OtherExtents>&);template<class LayoutLeftPaddedMapping> constexpr explicit(see below) mapping(const LayoutLeftPaddedMapping&);template<class LayoutRightPaddedMapping> constexpr explicit(see below) mapping(const LayoutRightPaddedMapping&) noexcept;constexpr mapping& operator=(const mapping&) noexcept = default;constexpr 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;template<class LayoutLeftPaddedMapping> friend constexpr bool operator==(const mapping&, const LayoutLeftPaddedMapping&) noexcept;private: index_type stride-1 = static-padding-stride; extents_type extents_{}; template<class... SliceSpecifiers> constexpr auto submdspan-mapping-impl(SliceSpecifiers...) const -> see below;template<class... SliceSpecifiers> friend constexpr auto submdspan_mapping(const mapping& src, SliceSpecifiers... slices) { return src.submdspan-mapping-impl(slices...);} };}

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

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

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

Mandates:

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

static constexpr size_t _static-padding-stride_ = _see below_;

The value is

index_type _stride-1_ = _static-padding-stride_;

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

Preconditions:

Effects:

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

Constraints:

Preconditions:

Effects: Direct-non-list-initializes extents_ with ext, and if rank_ is greater than one, direct-non-list-initializes stride-1 with_LEAST-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);

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

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.

Preconditions:

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

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

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

Preconditions:

Effects:

template<class LayoutLeftPaddedMapping> constexpr explicit(_see below_) mapping(const LayoutLeftPaddedMapping& other);

Constraints:

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

Preconditions:

Effects:

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;

Constraints:

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

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

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;

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

constexpr index_type required_span_size() const noexcept;

Returns:

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

Constraints:

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

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

static constexpr bool is_always_exhaustive() noexcept;

Returns:

constexpr bool is_exhaustive() const noexcept;

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

constexpr index_type stride(rank_type r) const noexcept;

Preconditions: r is smaller than rank_.

Returns:

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

Constraints:

Returns: true if x.extents() == y.extents() is true and_rank__ < 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]

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> template<class Extents> class layout_right_padded<PaddingValue>::mapping { public: static constexpr size_t padding_value = PaddingValue;using extents_type = Extents;using index_type = extents_type::index_type;using size_type = extents_type::size_type;using rank_type = extents_type::rank_type;using layout_type = layout_right_padded<PaddingValue>;private: static constexpr size_t rank_ = extents_type::rank(); static constexpr size_t last-static-extent = extents_type::static_extent(rank_ - 1);static constexpr size_t static-padding-stride = see below; public: constexpr mapping() noexcept : mapping(extents_type{}) {} constexpr mapping(const mapping&) noexcept = default;constexpr mapping(const extents_type&);template<class OtherIndexType> constexpr mapping(const extents_type&, OtherIndexType);template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const layout_right::mapping<OtherExtents>&);template<class OtherExtents> constexpr explicit(rank_ > 0) mapping(const layout_stride::mapping<OtherExtents>&);template<class LayoutRightPaddedMapping> constexpr explicit(see below) mapping(const LayoutRightPaddedMapping&);template<class LayoutLeftPaddedMapping> constexpr explicit(see below) mapping(const LayoutLeftPaddedMapping&) noexcept;constexpr mapping& operator=(const mapping&) noexcept = default;constexpr 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;template<class LayoutRightPaddedMapping> friend constexpr bool operator==(const mapping&, const LayoutRightPaddedMapping&) noexcept;private: index_type stride-rm2 = static-padding-stride; extents_type extents_{}; template<class... SliceSpecifiers> constexpr auto submdspan-mapping-impl(SliceSpecifiers...) const -> see below;template<class... SliceSpecifiers> friend constexpr auto submdspan_mapping(const mapping& src, SliceSpecifiers... slices) { return src.submdspan-mapping-impl(slices...);} };}

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

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

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

Mandates:

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

static constexpr size_t _static-padding-stride_ = _see below_;

The value is

index_type _stride-rm2_ = _static-padding-stride_;

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

Preconditions:

Effects:

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

Constraints:

Preconditions:

Effects: Direct-non-list-initializes extents_ with ext, and if rank_ is greater than one, direct-non-list-initializes stride-rm2 with_LEAST-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);

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

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.

Preconditions:

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

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

Constraints: is_constructible_v<extents_type, OtherExtents> is true.

Preconditions:

Effects:

template<class LayoutRightPaddedMapping> constexpr explicit(_see below_) mapping(const LayoutRightPaddedMapping& other);

Constraints:

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

Preconditions:

Effects:

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;

Constraints:

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

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

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;

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

constexpr index_type required_span_size() const noexcept;

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

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

Constraints:

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

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

static constexpr bool is_always_exhaustive() noexcept;

Returns:

constexpr bool is_exhaustive() const noexcept;

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;

Preconditions: r is smaller than rank_.

Returns:

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

Constraints:

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

Otherwise, false.