indexed_span data access

Data access

constexpr reference indexed_span::at(Index i) const
constexpr reference indexed_span::operator[](Index i) const

Element access. at is range-checked, and throws std::out_of_range on error. In case of multidimensional span, operator[] signature is std::tuple<Index1, Index2, ...> whereas at signature is at(Index1, Index2, ...). If using C++23, operator[] is also available as [Index1, Index2, ...]`

Parameters

i – The index. Anything that is implicitly convertible to the Index can be used.

Returns

A reference to the item at index i

constexpr pointer indexed_span::data() const

Gives access to the underlying storage.

Returns

A pointer to the start of the sequence of elements

constexpr reference indexed_span::front() const
Returns

The first element of the span. This is the same as *begin().

constexpr reference indexed_span::back() const
Returns

The last element of the span. This is the same as *rbegin().

Subrank access

constexpr auto indexed_span::slice(oneDimensionIndex index) const noexcept
constexpr auto indexed_span::slice_at(oneDimensionIndex index) const noexcept
Both functions returns a slice of the span, at the given index. For multidimensional

spans of rank n, it returns an indexed_span of rank n-1. For single dimension span, it returns the element at the given index. slice does not do any bound checking, slice_at throws std::out_of_range on error.

Parameters

index – The index of the slice. It must be an index of the type of the higher-level rank of the indexer.

Returns

An indexed_span of lower rank, a view of the data at index index

Note

There is no first/last/subspan methods. They do not fit well with the concept of custom indexing, because the return type shall be known at compile time, as it would depend on the parameters.