[mdspan.layout.leftpad] (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.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 = 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<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:
- the empty parameter pack, if rank_ equals zero;
- otherwise, 0zu, if rank_ equals one;
- otherwise, the parameter pack 0zu, 1zu, …, _rank__- 1.
Mandates:
- If rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents()is representable as a value of type index_type.
- padding_value is representable as a value of type index_type.
- 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.
- If
- rank_ is greater than one,
- padding_value does not equal dynamic_extent, and
- extents_type::static_extent(k) does not equal dynamic_extentfor all k in the range [0, extents_type::rank()),
then the product of_LEAST-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_;
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 is_LEAST-MULTIPLE-AT-LEAST_(padding_value, first-static-extent).
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:
- The size of the multidimensional index space ext is representable as a value of type index_type.
- 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.
- If rank_ is greater than one andpadding_value does not equal dynamic_extent, then the product of_LEAST-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.
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 with_LEAST-MULTIPLE-AT-LEAST_(padding_value, ext.extent(0)).
template<class OtherIndexType> constexpr mapping(const extents_type& ext, OtherIndexType pad);
Constraints:
- is_convertible_v<OtherIndexType, index_type> is true.
- is_nothrow_constructible_v<index_type, OtherIndexType> is true.
Preconditions:
- pad is representable as a value of type index_type.
- extents_type::index-cast(pad) is greater than zero.
- If rank_ is greater than one, then LEAST-MULTIPLE-AT-LEAST(pad, ext.extent(0))is representable as a value of type index_type.
- If rank_ is greater than one, then the product of_LEAST-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.
- If padding_value is not equal to dynamic_extent,padding_value equals extents_type::index-cast(pad).
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:
- If extents_type::rank() > 1 is true andpadding_value == dynamic_extent is false, then other.stride(1) equals_LEAST-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.
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:
- If rank_ is greater than 1 andpadding_value does not equal dynamic_extent, then other.stride(1) equals_LEAST-MULTIPLE-AT-LEAST_(padding_value, extents_type::index-cast(other.extents().extent(0)))
- If rank_ is greater than 0, then other.stride(0) equals 1.
- 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)
- other.required_span_size() is representable as a value of type index_type.
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);
Constraints:
- is-layout-left-padded-mapping-of<LayoutLeftPaddedMapping>is true.
- is_constructible_v<extents_type, typename LayoutLeftPaddedMapping::extents_type>
is true.
Mandates: If rank_ is greater than 1, thenpadding_value == dynamic_extent ||LayoutLeftPaddedMapping::padding_value == dynamic_extent ||padding_value == LayoutLeftPaddedMapping::padding_valueis true.
- If rank_ is greater than 1 andpadding_value does not equal dynamic_extent, then other.stride(1) equals_LEAST-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.
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).
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:
- is-layout-right-padded-mapping-of<LayoutRightPaddedMapping>is true or
is-mapping-of<layout_right, LayoutRightPaddedMapping>is true. - rank_ equals zero or one.
- is_constructible_v<extents_type, typename LayoutRightPaddedMapping::extents_-
type>is true.
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:
- 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;
Constraints:
- sizeof...(Indices) == rank_ is true.
- (is_convertible_v<Indices, index_type> && ...) is true.
- (is_nothrow_constructible_v<index_type, Indices> && ...) is true.
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:
- 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;
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:
- 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;
Constraints:
- is-layout-left-padded-mapping-of<LayoutLeftPaddedMapping>is true.
- LayoutLeftPaddedMapping::extents_type::rank() == rank_ is true.
Returns: true if x.extents() == y.extents() is true and_rank__ < 2 || x.stride(1) == y.
stride(1) is true.
Otherwise, false.