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

22 KiB
Raw Permalink Blame History

[mdspan.layout.rightpad]

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