24 Containers library [containers]

24.7 Views [views]

24.7.3 Multidimensional access [views.multidim]

24.7.3.5 Accessor policy [mdspan.accessor]

24.7.3.5.1 General [mdspan.accessor.general]

An accessor policy defines types and operations by which a reference to a single object is created from an abstract data handle to a number of such objects and an index.
A range of indices is an accessible range of a given data handle and an accessor if, for each i in the range, the accessor policy's access function produces a valid reference to an object.
  • A denotes an accessor policy.
  • a denotes a value of type A or const A.
  • p denotes a value of type A​::​data_handle_type or const A​::​data_handle_type.
    [Note 1: 
    The type A​::​data_handle_type need not be dereferenceable.
    — end note]
  • n, i, and j each denote values of type size_t.

24.7.3.5.2 Requirements [mdspan.accessor.reqmts]

A type A meets the accessor policy requirements if
  • A models copyable,
  • is_nothrow_move_constructible_v<A> is true,
  • is_nothrow_move_assignable_v<A> is true,
  • is_nothrow_swappable_v<A> is true, and
  • the following types and expressions are well-formed and have the specified semantics.
typename A::element_type
Result: A complete object type that is not an abstract class type.
typename A::data_handle_type
Result: A type that models copyable, and for which is_nothrow_move_constructible_v<A​::​data_handle_type> is true, is_nothrow_move_assignable_v<A​::​data_handle_type> is true, and is_nothrow_swappable_v<A​::​data_handle_type> is true.
[Note 1: 
The type of data_handle_type need not be element_type*.
— end note]
typename A::reference
Result: A type that models common_reference_with<A​::​reference&&, A​::​element_type&>.
[Note 2: 
The type of reference need not be element_type&.
— end note]
typename A::offset_policy
Result: A type OP such that:
  • OP meets the accessor policy requirements,
  • constructible_from<OP, const A&> is modeled, and
  • is_same_v<typename OP​::​element_type, typename A​::​element_type> is true.
a.access(p, i)
Result: A​::​reference
Remarks: The expression is equality preserving.
[Note 3: 
Concrete accessor policies can impose preconditions for their access function.
However, they might not.
For example, an accessor where p is span<A​::​element_type, dynamic_extent> and access(p, i) returns p[i % p.size()] does not need to impose a precondition on i.
— end note]
a.offset(p, i)
Result: A​::​offset_policy​::​data_handle_type
Returns: q such that for b being A​::​offset_policy(a), and any integer n for which [0, n) is an accessible range of p and a:
  • is an accessible range of q and b; and
  • b.access(q, j) provides access to the same element as a.access(p, i + j), for every j in the range .
Remarks: The expression is equality-preserving.

24.7.3.5.3 Class template default_accessor [mdspan.accessor.default]

24.7.3.5.3.1 Overview [mdspan.accessor.default.overview]

namespace std { template<class ElementType> struct default_accessor { using offset_policy = default_accessor; using element_type = ElementType; using reference = ElementType&; using data_handle_type = ElementType*; constexpr default_accessor() noexcept = default; template<class OtherElementType> constexpr default_accessor(default_accessor<OtherElementType>) noexcept; constexpr reference access(data_handle_type p, size_t i) const noexcept; constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept; }; }
default_accessor meets the accessor policy requirements.
ElementType is required to be a complete object type that is neither an abstract class type nor an array type.
Each specialization of default_accessor is a trivially copyable type that models semiregular.
is an accessible range for an object p of type data_handle_type and an object of type default_accessor if and only if [p, p + n) is a valid range.

24.7.3.5.3.2 Members [mdspan.accessor.default.members]

template<class OtherElementType> constexpr default_accessor(default_accessor<OtherElementType>) noexcept {}
Constraints: is_convertible_v<OtherElementType(*)[], element_type(*)[]> is true.
constexpr reference access(data_handle_type p, size_t i) const noexcept;
Effects: Equivalent to: return p[i];
constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept;
Effects: Equivalent to: return p + i;