Namespaces
Variants
Views
Actions

std::mdspan<T,Extents,LayoutPolicy,AccessorPolicy>::operator[]

From cppreference.com
< cpp‎ | container‎ | mdspan
Revision as of 15:35, 23 May 2023 by Runge (Talk | contribs)

 
 
 
 
Defined in header <mdspan>
template< class... OtherIndexTypes >
constexpr reference operator[]( OtherIndexTypes... indices ) const;
(1) (since C++23)
template< class OtherIndexType >
constexpr reference operator[]( span<OtherIndexType, rank()> indices ) const;
(2) (since C++23)
template< class OtherIndexType >
constexpr reference operator[]( const array<OtherIndexType, rank()>& indices ) const;
(3) (since C++23)

Returns a reference to the indicesth element of the mdspan.

1) Equivalent to return acc_.access(ptr_, map_(static_cast<index_type>(std::move(indices))...));.
  • This overload participates in overload resolution only if:
  • (is_convertible_v<OtherIndexTypes, index_type> && ...) is true,
  • (is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...) is true, and
  • sizeof...(OtherIndexTypes) == rank() is true.
  • Let I be extents_type::index-cast(std::move(indices)). Then the behavior is undefined if I is not a multidimensional index in extents(), i.e., map_(I) < map_.required_span_size() is false.
2,3) Let P be a parameter pack such that is_same_v<make_index_sequence<rank()>, index_sequence<P...>> is true, then the operator is equivalent to return operator[](as_const(indices[P])...);.
  • This overload participates in overload resolution only if:
  • is_convertible_v<const OtherIndexType&, index_type> is true, and
  • is_nothrow_constructible_v<index_type, const OtherIndexType&> is true.

Parameters

idices - the indices of the element to access

Example

See also