template<class T>
Corrade::Containers::StridedArrayView class

Array view with size and stride information.

Immutable wrapper around continuous sparse range of data, useful for easy iteration over interleaved arrays. Usage example:

struct Position {
    float x, y;
};

Position positions[]{{-0.5f, -0.5f}, { 0.5f, -0.5f}, { 0.0f,  0.5f}};

Containers::StridedArrayView<float> horizontalPositions{
    &positions[0].x, Containers::arraySize(positions), sizeof(Position)};

/* Move to the right */
for(float& x: horizontalPositions) x += 3.0f;

For convenience, similarly to ArrayView, this class is implicitly convertible from plain C arrays, ArrayView and StaticArrayView, with stride equal to array type size.

int data[] { 1, 42, 1337, -69 };

Containers::StridedArrayView<int> view1{data, 4, sizeof(int)};
Containers::StridedArrayView<int> view2 = data;

Unlike ArrayView, this wrapper doesn't provide direct pointer access because pointer arithmetic doesn't work as usual here.

Public types

using Type = T
Element type.

Constructors, destructors, conversion operators

StridedArrayView(std::nullptr_t) constexpr noexcept
Conversion from nullptr
StridedArrayView() constexpr noexcept
Default constructor.
StridedArrayView(T* data, std::size_t size, std::size_t stride) noexcept
Construct view on an array with explicit length.
template<class U, std::size_t size>
StridedArrayView(U(&data)[size]) noexcept
Construct view on a fixed-size array.
template<class U>
StridedArrayView(StridedArrayView<U> view) noexcept
Construct view on StridedArrayView.
template<class U>
StridedArrayView(ArrayView<U> view) noexcept
Construct view on ArrayView.
template<std::size_t size, class U>
StridedArrayView(StaticArrayView<size, U> view) noexcept
Construct view on StaticArrayView.
operator bool() const explicit
Whether the array is non-empty.

Public functions

auto data() const -> const void* constexpr
Array data.
auto size() const -> std::size_t constexpr
Array size.
auto stride() const -> std::size_t constexpr
Array stride.
auto empty() const -> bool constexpr
Whether the array is empty.
auto operator[](std::size_t i) const -> T&
Element access.
auto begin() const -> StridedIterator<T> constexpr
Iterator to first element.
auto cbegin() const -> StridedIterator<T> constexpr
auto end() const -> StridedIterator<T>
Iterator to (one item after) last element.
auto cend() const -> StridedIterator<T>
auto front() const -> T&
First element.
auto back() const -> T&
Last element.
auto slice(std::size_t begin, std::size_t end) const -> StridedArrayView<T>
Array slice.
auto prefix(std::size_t end) const -> StridedArrayView<T>
Array prefix.
auto suffix(std::size_t begin) const -> StridedArrayView<T>
Array suffix.

Function documentation

template<class T>
Corrade::Containers::StridedArrayView<T>::StridedArrayView() constexpr noexcept

Default constructor.

Creates empty view. Copy non-empty Array or ArrayView onto the instance to make it useful.

template<class T>
Corrade::Containers::StridedArrayView<T>::StridedArrayView(T* data, std::size_t size, std::size_t stride) noexcept

Construct view on an array with explicit length.

Parameters
data Data pointer
size Data size
stride Data stride

template<class T> template<class U, std::size_t size>
Corrade::Containers::StridedArrayView<T>::StridedArrayView(U(&data)[size]) noexcept

Construct view on a fixed-size array.

Parameters
data Fixed-size array

Enabled only if T* is implicitly convertible to U*. Expects that both types have the same size; stride is implicitly set to sizeof(T).

template<class T> template<class U>
Corrade::Containers::StridedArrayView<T>::StridedArrayView(StridedArrayView<U> view) noexcept

Construct view on StridedArrayView.

Enabled only if T* is implicitly convertible to U*. Expects that both types have the same size; stride is implicitly set to sizeof(T).

template<class T> template<class U>
Corrade::Containers::StridedArrayView<T>::StridedArrayView(ArrayView<U> view) noexcept

Construct view on ArrayView.

Enabled only if T* is implicitly convertible to U*. Expects that both types have the same size; stride is implicitly set to sizeof(T).

template<class T> template<std::size_t size, class U>
Corrade::Containers::StridedArrayView<T>::StridedArrayView(StaticArrayView<size, U> view) noexcept

Construct view on StaticArrayView.

Enabled only if T* is implicitly convertible to U*. Expects that both types have the same size; stride is implicitly set to sizeof(T).

template<class T>
StridedIterator<T> Corrade::Containers::StridedArrayView<T>::begin() const constexpr

Iterator to first element.

template<class T>
StridedIterator<T> Corrade::Containers::StridedArrayView<T>::cbegin() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
StridedIterator<T> Corrade::Containers::StridedArrayView<T>::end() const

Iterator to (one item after) last element.

template<class T>
StridedIterator<T> Corrade::Containers::StridedArrayView<T>::cend() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T& Corrade::Containers::StridedArrayView<T>::front() const

First element.

Expects there is at least one element.

template<class T>
T& Corrade::Containers::StridedArrayView<T>::back() const

Last element.

Expects there is at least one element.

template<class T>
StridedArrayView<T> Corrade::Containers::StridedArrayView<T>::slice(std::size_t begin, std::size_t end) const

Array slice.

Both arguments are expected to be in range.

template<class T>
StridedArrayView<T> Corrade::Containers::StridedArrayView<T>::prefix(std::size_t end) const

Array prefix.

Equivalent to data.slice(0, end). If end is 0, returns zero-sized nullptr array.

template<class T>
StridedArrayView<T> Corrade::Containers::StridedArrayView<T>::suffix(std::size_t begin) const

Array suffix.

Equivalent to data.slice(begin, data.size()).