template<unsigned dimensions, class T>
Corrade::Containers::StridedArrayView class

Multi-dimensional array view with size and stride information.

Immutable wrapper around continuous sparse range of data, useful for easy iteration over interleaved arrays and for describing multi-dimensional data. A multi-dimensional counterpart to an ArrayView. For efficient bit manipulation see StridedBitArrayView. Usage example:

struct Position {
    float x, y;
};

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

Containers::StridedArrayView1D<float> horizontalPositions{positions,
    &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. The following two statements are equivalent:

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

Containers::StridedArrayView1D<int> a{data, 4, sizeof(int)};
Containers::StridedArrayView1D<int> b = data;

When constructing, if you don't specify the stride, the constructor assumes contiguous data and calculates the stride automatically — stride of a dimension is stride of the next dimension times next dimension size, while last dimension stride is implicitly sizeof(T). This is especially useful for "reshaping" linear data as a multi-dimensional view. Again, the following two statements are equivalent:

int data3D[2*3*5];

Containers::StridedArrayView3D<int> a{data3D, {2, 3, 5}, {3*5*4, 5*4, 4}};
Containers::StridedArrayView3D<int> b{data3D, {2, 3, 5}};

Unlike ArrayView, this wrapper doesn't provide direct pointer access because pointer arithmetic doesn't work as usual here. The arrayCast(const StridedArrayView<dimensions, T>&) overload also works slightly differently with strided arrays — it checks that a type fits into the stride instead of expecting the total byte size to stay the same.

Multi-dimensional views

Strided array views are very useful for describing and iteration over multi-dimensional data such as 2D (sub)images. In that case, operator[](std::size_t) const and iterator access return a view of one dimension less instead of a direct element reference, and there are operator[](const Containers::Size<dimensions>&) const, slice(const Containers::Size<dimensions>&, const Containers::Size<dimensions>&) const, prefix(const Containers::Size<dimensions>&) const, exceptPrefix(const Containers::Size<dimensions>&) const and exceptSuffix(const Containers::Size<dimensions>&) const overloads working on all dimensions at the same time.

/* Sixteen 256x256 RGBA8 images */
Containers::StridedArrayView3D<std::uint32_t> images{rgbaData, {16, 256, 256}};

/* Make the center 64x64 pixels of each image opaque red */
for(auto&& image: images.slice({0, 96, 96}, {16, 160, 160}))
    for(auto&& row: image)
        for(std::uint32_t& pixel: row)
            pixel = 0xff0000ff;

Both the subscription operator and the slicing operations allow you to change the view dimension count — for example, obtaining the fifth image or just a view on the (now red) center of it. Conversely, it's possible to turn a lower-dimensional view into a slice in a higher-dimensional view.

Containers::StridedArrayView2D<std::uint32_t> image = images[4];
Containers::StridedArrayView2D<std::uint32_t> imageCenter =
    images.slice<2>({4, 96, 96}, {5, 160, 160});

Since the actual view elements can be also non-scalar data, there's an overload of arrayCast(const StridedArrayView<dimensions, T>&) that can "extract" an additional dimension out of these or, on the other hand, flatten it back if the last dimension is contiguous.

/* First dimension is Y, second X, third R/G/B/A */
Containers::StridedArrayView3D<std::uint8_t> channels =
    Containers::arrayCast<3, std::uint8_t>(image);

Utility::Debug{} << channels[128][128][1]; // green channel, 0xff

With expanded() it's possible to expand a particular dimension to multiple, collapsed() then does the inverse assuming the strides allow that. The following example splits the 256-pixel-wide image into two 128-pixel halves, and the second expression turns the 2D image into a linear list of pixels:

Containers::StridedArrayView3D<std::uint32_t> halves =
    image.expanded<1>(Containers::Size2D{2, 128});

Utility::Debug{} << halves[128][1][0]; // first pixel of second half of row 128

Containers::StridedArrayView1D<std::uint32_t> linear =
    image.collapsed<0, 2>();

Utility::Debug{} << linear[8359];      // pixel at offset 8359

Zero and negative stride

The stride value doesn't have to be just positive. Order of elements in any dimension of the view can be reversed by calling flipped(), and together with transposed() it's possible to generate any 90° rotation of the data:

/* Bottom left before is now bottom right */
Containers::StridedArrayView2D<std::uint32_t> rotated90DegLeft =
    image.transposed<0, 1>().flipped<0>();

Setting stride to 0 in a particular dimension will reuse the same memory address for every element. The convenience broadcasted() function will repeat given dimension given number of times:

int data[8] { 0, 1, 2, 3, 4, 5, 6, 7 };

/* 8x8 array with 0–7 repeated in every row */
Containers::StridedArrayView2D<int> gradient =
    Containers::StridedArrayView1D<int>{data}.slice<2>().broadcasted<1>(8);

STL compatibility

On compilers that support C++2a and std::span, implicit conversion of it to a StridedArrayView1D is provided in Corrade/Containers/ArrayViewStlSpan.h. The conversion is provided in a separate header to avoid unconditional #include <span>, which significantly affects compile times. The following table lists allowed conversions:

Corrade typeSTL type
StridedArrayView1D<T>std::span<T>
StridedArrayView1D<T>std::span<const T, size>
StridedArrayView1D<const T>std::span<const T>

See ArrayView STL compatibility for more information.

The Corrade/Containers/StridedArrayViewStl.h header provides a std::iterator_traits specialization for StridedIterator, which is required in order to be able to use strided array views in STL algorithms such as std::lower_bound(). Right now the specialization is limited to just 1D views, as higher-dimensional iterators return temporary views instead of value references and thus it's not clear what their use in (1D) STL algorithms would be.

Public types

enum (anonymous): unsigned { Dimensions = dimensions new in 2019.10 }
using Type = T
Underlying type.
using ElementType = std::conditional<dimensions==1, T&, StridedArrayView<dimensions - 1, T>>::type
Element type.
using ErasedType = std::conditional<std::is_const<T>::value, const void, void>::type
Erased type.
using ArithmeticType = std::conditional<std::is_const<T>::value, const char, char>::type
Arithmetic type.
using Size = Containers::Size<dimensions> deprecated in Git master
Size values.
using Stride = Containers::Stride<dimensions> deprecated in Git master
Stride values.

Constructors, destructors, conversion operators

StridedArrayView(std::nullptr_t = nullptr) constexpr noexcept
Default constructor.
StridedArrayView(ArrayView<ErasedType> data, T* member, const Containers::Size<dimensions>& size, const Containers::Stride<dimensions>& stride) constexpr noexcept
Construct a view with explicit size and stride.
StridedArrayView(ArrayView<T> data, const Containers::Size<dimensions>& size, const Containers::Stride<dimensions>& stride) constexpr noexcept new in 2019.10
Construct a view with explicit size and stride.
StridedArrayView(ArrayView<T> data, const Containers::Size<dimensions>& size) constexpr noexcept new in 2019.10
Construct a view with explicit size.
StridedArrayView(T* data, std::size_t size) constexpr noexcept new in Git master
Construct a 1D view on an array with explicit size.
template<class U, std::size_t size>
StridedArrayView(U(&data)[size]) constexpr noexcept
Construct a view on a fixed-size array.
template<class U>
StridedArrayView(const StridedArrayView<dimensions, U>& view) constexpr noexcept
Construct from a StridedArrayView of different type.
template<unsigned lessDimensions>
StridedArrayView(const StridedArrayView<lessDimensions, T>& other) noexcept new in Git master
Construct from a StridedArrayView of smaller dimension count.
template<class U>
StridedArrayView(ArrayView<U> view) constexpr noexcept
Construct from a ArrayView.
template<std::size_t size, class U>
StridedArrayView(StaticArrayView<size, U> view) constexpr noexcept
Construct a view on StaticArrayView.
template<class U, unsigned d = dimensions, class = typename std::enable_if<d == 1, decltype(Implementation::ArrayViewConverter<T, typename std::decay<U && >::type>::from(std::declval<U && >()))>::type>
StridedArrayView(U&& other) constexpr noexcept
Construct a view on an external type.
operator bool() const explicit constexpr
Whether the array is non-empty.

Public functions

auto data() const -> ErasedType* constexpr
Array data.
auto size() const -> std::conditional<dimensions==1, std::size_t, const Containers::Size<dimensions>&>::type constexpr
Array size.
auto stride() const -> std::conditional<dimensions==1, std::ptrdiff_t, const Containers::Stride<dimensions>&>::type constexpr
Array stride.
auto isEmpty() const -> StridedDimensions<dimensions, bool> constexpr new in Git master
Whether the view is empty.
auto empty() const -> StridedDimensions<dimensions, bool> deprecated in Git master constexpr
Whether the view is empty.
template<unsigned dimension = 0>
auto isContiguous() const -> bool new in 2020.06
Whether the view is contiguous from given dimension further.
auto asContiguous() const -> ArrayView<T> new in 2020.06
Convert the view to a contiguous one.
template<unsigned dimension>
auto asContiguous() const -> StridedArrayView<dimension+1, T> new in Git master
Convert the view to a contiguous one from given dimension further.
auto begin() const -> StridedIterator<dimensions, T>
Iterator to first element.
auto cbegin() const -> StridedIterator<dimensions, T>
auto end() const -> StridedIterator<dimensions, T>
Iterator to (one item after) last element.
auto cend() const -> StridedIterator<dimensions, T>
auto front() const -> ElementType
First element.
auto back() const -> ElementType
Last element.
auto operator[](std::size_t i) const -> ElementType
Element or sub-view access.
auto operator[](const Containers::Size<dimensions>& i) const -> T& new in Git master
Element access.
auto slice(std::size_t begin, std::size_t end) const -> StridedArrayView<dimensions, T>
View slice in the first dimension.
template<unsigned newDimensions = dimensions>
auto slice(const Containers::Size<dimensions>& begin, const Containers::Size<dimensions>& end) const -> StridedArrayView<newDimensions, T>
View slice in all dimensions.
auto sliceSize(std::size_t begin, std::size_t size) const -> StridedArrayView<dimensions, T> new in Git master
View slice of given size in the first dimension.
template<unsigned newDimensions = dimensions>
auto sliceSize(const Containers::Size<dimensions>& begin, const Containers::Size<dimensions>& size) const -> StridedArrayView<newDimensions, T> new in Git master
View slice of given size in all dimensions.
template<unsigned newDimensions = dimensions>
auto slice() const -> StridedArrayView<newDimensions, T>
Expand or shrink dimension count.
template<class U>
auto slice(U T::* member) const -> StridedArrayView<dimensions, typename std::conditional<std::is_const<T>::value, const U, U>::type> new in Git master
Slice to a member.
template<class U>
auto slice(U&(T::*)() memberFunction) const -> StridedArrayView<dimensions, U> new in Git master
Slice to a member function.
template<class U>
auto slice(U&(T::*)() memberFunction&) const -> StridedArrayView<dimensions, U> new in Git master
template<class U>
auto slice(const U&(T::*)() const memberFunction) const -> StridedArrayView<dimensions, U> new in Git master
template<class U>
auto slice(const U&(T::*)() const memberFunction&) const -> StridedArrayView<dimensions, U> new in Git master
auto sliceBit(std::size_t index) const -> BasicStridedBitArrayView<dimensions, ArithmeticType> new in Git master
Slice to a bit.
auto prefix(std::size_t size) const -> StridedArrayView<dimensions, T>
View on the first size items in the first dimension.
template<unsigned newDimensions = dimensions>
auto prefix(const Containers::Size<dimensions>& size) const -> StridedArrayView<newDimensions, T>
View on the first size items in all dimensions.
auto exceptPrefix(std::size_t size) const -> StridedArrayView<dimensions, T> new in Git master
View except the first size items in the first dimension.
auto suffix(std::size_t begin) const -> StridedArrayView<dimensions, T> deprecated in Git master
View except the first size items in the first dimension.
template<unsigned newDimensions = dimensions>
auto exceptPrefix(const Containers::Size<dimensions>& size) const -> StridedArrayView<newDimensions, T> new in Git master
View except the first size items in all dimensions.
template<unsigned newDimensions = dimensions>
auto suffix(const Containers::Size<dimensions>& begin) const -> StridedArrayView<newDimensions, T> deprecated in Git master
View except the first size items in the first dimension.
auto exceptSuffix(std::size_t size) const -> StridedArrayView<dimensions, T> new in Git master
View except the last size items in the first dimension.
auto except(std::size_t count) const -> StridedArrayView<dimensions, T> deprecated in Git master
View except the last size items in the first dimension.
template<unsigned newDimensions = dimensions>
auto exceptSuffix(const Containers::Size<dimensions>& size) const -> StridedArrayView<newDimensions, T> new in Git master
View except the last size items in all dimensions.
template<unsigned newDimensions = dimensions>
auto except(const Containers::Size<dimensions>& count) const -> StridedArrayView<newDimensions, T> deprecated in Git master
View except the last size items in the first dimension.
auto every(std::ptrdiff_t skip) const -> StridedArrayView<dimensions, T> new in 2019.10
Pick every Nth element.
auto every(const Containers::Stride<dimensions>& skip) const -> StridedArrayView<dimensions, T> new in 2019.10
Pick every Nth element.
template<unsigned dimensionA, unsigned dimensionB>
auto transposed() const -> StridedArrayView<dimensions, T> new in 2019.10
Transpose two dimensions.
template<unsigned dimension>
auto flipped() const -> StridedArrayView<dimensions, T> new in 2019.10
Flip a dimension.
template<unsigned dimension>
auto broadcasted(std::size_t size) const -> StridedArrayView<dimensions, T> new in 2019.10
Broadcast a dimension.
template<unsigned dimension, unsigned count>
auto expanded(const Containers::Size<count>& size) const -> StridedArrayView<dimensions+count - 1, T> new in Git master
Expand a dimension.
template<unsigned dimension, unsigned count>
auto collapsed() const -> StridedArrayView<dimensions - count+1, T> new in Git master
Collapse dimensions.

Enum documentation

template<unsigned dimensions, class T>
enum Corrade::Containers::StridedArrayView<dimensions, T>::(anonymous): unsigned

Enumerators
Dimensions new in 2019.10

View dimensions

Typedef documentation

template<unsigned dimensions, class T>
typedef T Corrade::Containers::StridedArrayView<dimensions, T>::Type

Underlying type.

Underlying data type. See also ElementType, ErasedType and ArithmeticType.

template<unsigned dimensions, class T>
typedef std::conditional<dimensions==1, T&, StridedArrayView<dimensions - 1, T>>::type Corrade::Containers::StridedArrayView<dimensions, T>::ElementType

Element type.

For StridedArrayView1D is equivalent to a reference to Type, for higher dimensions to a strided view of one dimension less.

template<unsigned dimensions, class T>
typedef std::conditional<std::is_const<T>::value, const void, void>::type Corrade::Containers::StridedArrayView<dimensions, T>::ErasedType

Erased type.

Either void or const void based on constness of Type. See also ArithmeticType.

template<unsigned dimensions, class T>
typedef std::conditional<std::is_const<T>::value, const char, char>::type Corrade::Containers::StridedArrayView<dimensions, T>::ArithmeticType

Arithmetic type.

Unlike ErasedType can be used for pointer value calculations. Either char or const char based on constness of Type.

template<unsigned dimensions, class T>
typedef Containers::Size<dimensions> Corrade::Containers::StridedArrayView<dimensions, T>::Size

Size values.

template<unsigned dimensions, class T>
typedef Containers::Stride<dimensions> Corrade::Containers::StridedArrayView<dimensions, T>::Stride

Stride values.

Function documentation

template<unsigned dimensions, class T>
Corrade::Containers::StridedArrayView<dimensions, T>::StridedArrayView(std::nullptr_t = nullptr) constexpr noexcept

Default constructor.

Creates an empty nullptr view. Copy a non-empty Array, ArrayView or StridedArrayView onto the instance to make it useful.

template<unsigned dimensions, class T>
Corrade::Containers::StridedArrayView<dimensions, T>::StridedArrayView(ArrayView<ErasedType> data, T* member, const Containers::Size<dimensions>& size, const Containers::Stride<dimensions>& stride) constexpr noexcept

Construct a view with explicit size and stride.

Parameters
data Continuous view on the data
member Pointer to the first member of the strided view
size Data size
stride Data stride

The data view is used only for a bounds check — expects that it's is large enough for size and stride in the largest dimension if the stride is either positive or negative. Zero strides unfortunately can't be reliably checked for out-of-bounds conditions, so be extra careful when specifying these.

template<unsigned dimensions, class T>
Corrade::Containers::StridedArrayView<dimensions, T>::StridedArrayView(ArrayView<T> data, const Containers::Size<dimensions>& size, const Containers::Stride<dimensions>& stride) constexpr noexcept new in 2019.10

Construct a view with explicit size and stride.

Equivalent to calling StridedArrayView(ArrayView<ErasedType>, T*, const Containers::Size<dimensions>&, const Containers::Stride<dimensions>&) with data.data() as the member parameter.

template<unsigned dimensions, class T>
Corrade::Containers::StridedArrayView<dimensions, T>::StridedArrayView(ArrayView<T> data, const Containers::Size<dimensions>& size) constexpr noexcept new in 2019.10

Construct a view with explicit size.

Assuming data is contiguous, stride is calculated implicitly from size — stride of a dimension is stride of the next dimension times next dimension size, while last dimension stride is implicitly sizeof(T). In a one-dimensional case you probably want to use StridedArrayView(ArrayView<U>) instead.

template<unsigned dimensions, class T>
Corrade::Containers::StridedArrayView<dimensions, T>::StridedArrayView(T* data, std::size_t size) constexpr noexcept new in Git master

Construct a 1D view on an array with explicit size.

Parameters
data Data pointer
size Data size

Enabled only on one-dimensional views. Stride is implicitly set to sizeof(T).

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

Construct a view on a fixed-size array.

Parameters
data Fixed-size array

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

template<unsigned dimensions, class T> template<class U>
Corrade::Containers::StridedArrayView<dimensions, T>::StridedArrayView(const StridedArrayView<dimensions, U>& view) constexpr noexcept

Construct from a StridedArrayView of different type.

Enabled only if T* is implicitly convertible to U*. Expects that both types have the same size.

template<unsigned dimensions, class T> template<unsigned lessDimensions>
Corrade::Containers::StridedArrayView<dimensions, T>::StridedArrayView(const StridedArrayView<lessDimensions, T>& other) noexcept new in Git master

Construct from a StridedArrayView of smaller dimension count.

The extra dimensions are added at the front, with sizes being 1 and strides equal to size times stride of other in the first dimension. For example, a 1D view that represents an image row (the X axis) expanded to a 3D view would have 1 row (the Y axis) and 1 slice (the Z axis), in the common Z-Y-X order, with the last dimension being the most dense or even contiguous.

To reduce dimension count you can use operator[](), potentially in combination with transposed().

template<unsigned dimensions, class T> template<class U>
Corrade::Containers::StridedArrayView<dimensions, T>::StridedArrayView(ArrayView<U> view) constexpr noexcept

Construct from a ArrayView.

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

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

Construct a view on StaticArrayView.

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

template<unsigned dimensions, class T> template<class U, unsigned d = dimensions, class = typename std::enable_if<d == 1, decltype(Implementation::ArrayViewConverter<T, typename std::decay<U && >::type>::from(std::declval<U && >()))>::type>
Corrade::Containers::StridedArrayView<dimensions, T>::StridedArrayView(U&& other) constexpr noexcept

Construct a view on an external type.

Enabled only on one-dimensional views.

template<unsigned dimensions, class T>
std::conditional<dimensions==1, std::size_t, const Containers::Size<dimensions>&>::type Corrade::Containers::StridedArrayView<dimensions, T>::size() const constexpr

Array size.

Returns just std::size_t instead of Size for the one-dimensional case so the usual numeric operations work as expected. Explicitly cast to Size to ensure consistent behavior for all dimensions in generic implementations.

template<unsigned dimensions, class T>
std::conditional<dimensions==1, std::ptrdiff_t, const Containers::Stride<dimensions>&>::type Corrade::Containers::StridedArrayView<dimensions, T>::stride() const constexpr

Array stride.

Returns just std::ptrdiff_t instead of Stride for the one-dimensional case so the usual numeric operations work as expected. Explicitly cast to Stride to ensure consistent behavior for all dimensions in generic implementations.

template<unsigned dimensions, class T>
StridedDimensions<dimensions, bool> Corrade::Containers::StridedArrayView<dimensions, T>::isEmpty() const constexpr new in Git master

Whether the view is empty.

template<unsigned dimensions, class T>
StridedDimensions<dimensions, bool> Corrade::Containers::StridedArrayView<dimensions, T>::empty() const constexpr

Whether the view is empty.

template<unsigned dimensions, class T> template<unsigned dimension = 0>
bool Corrade::Containers::StridedArrayView<dimensions, T>::isContiguous() const new in 2020.06

Whether the view is contiguous from given dimension further.

The view is considered contiguous if its last dimension has stride() equal to the type size and every dimension before that until and including dimension has its stride equal to element count times stride of the dimension that follows it.

Note that even if the data are tightly packed in memory, this function may return false — for example, a contiguous view with two dimensions transposed() is no longer contiguous, same as with zero or negative strides.

template<unsigned dimensions, class T>
ArrayView<T> Corrade::Containers::StridedArrayView<dimensions, T>::asContiguous() const new in 2020.06

Convert the view to a contiguous one.

Returns a view large as the product of sizes in all dimensions. Expects that the view is contiguous.

template<unsigned dimensions, class T> template<unsigned dimension>
StridedArrayView<dimension+1, T> Corrade::Containers::StridedArrayView<dimensions, T>::asContiguous() const new in Git master

Convert the view to a contiguous one from given dimension further.

Returns a view with the last dimension having size as the product of sizes in this and all following dimensions, and stride equal to sizeof(T). Expects that isContiguous<dimension>() returns true.

Assuming the view is contiguous, calling this function with dimension equal to Dimensions minus one will return the same view; calling it with 0 will return a StridedArrayView1D with stride equal to sizeof(T); while the non-templated asContiguous() will return an ArrayView (where the stride is implicitly defined as sizeof(T)).

template<unsigned dimensions, class T>
StridedIterator<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::begin() const

Iterator to first element.

template<unsigned dimensions, class T>
StridedIterator<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::cbegin() const

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

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

Iterator to (one item after) last element.

template<unsigned dimensions, class T>
StridedIterator<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, 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<unsigned dimensions, class T>
ElementType Corrade::Containers::StridedArrayView<dimensions, T>::front() const

First element.

Expects there is at least one element.

template<unsigned dimensions, class T>
ElementType Corrade::Containers::StridedArrayView<dimensions, T>::back() const

Last element.

Expects there is at least one element.

template<unsigned dimensions, class T>
ElementType Corrade::Containers::StridedArrayView<dimensions, T>::operator[](std::size_t i) const

Element or sub-view access.

Expects that i is less than size(). On multi-dimensional views returns a view of one dimension less, use operator[](const Containers::Size<dimensions>&) const to index all dimensions.

template<unsigned dimensions, class T>
T& Corrade::Containers::StridedArrayView<dimensions, T>::operator[](const Containers::Size<dimensions>& i) const new in Git master

Element access.

Expects that i is less than size().

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

View slice in the first dimension.

Both arguments are expected to be in range. On multi-dimensional views slices just the top-level dimension, use slice(const Containers::Size<dimensions>&, const Containers::Size<dimensions>&) const to slice in all dimensions.

template<unsigned dimensions, class T> template<unsigned newDimensions = dimensions>
StridedArrayView<newDimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::slice(const Containers::Size<dimensions>& begin, const Containers::Size<dimensions>& end) const

View slice in all dimensions.

Values in both arguments are expected to be in range for given dimension. If newDimensions is smaller than Dimensions, only the first slice is taken from the remaining dimensions; if newDimensions is larger than Dimensions, size of the new dimensions is set to 1 and and stride to size of Type.

template<unsigned dimensions, class T>
StridedArrayView<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::sliceSize(std::size_t begin, std::size_t size) const new in Git master

View slice of given size in the first dimension.

Equivalent to data.slice(begin, begin + size). On multi-dimensional views slices just the top-level dimension, use sliceSize(const Containers::Size<dimensions>&, const Containers::Size<dimensions>&) const to slice in all dimensions.

template<unsigned dimensions, class T> template<unsigned newDimensions = dimensions>
StridedArrayView<newDimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::sliceSize(const Containers::Size<dimensions>& begin, const Containers::Size<dimensions>& size) const new in Git master

View slice of given size in all dimensions.

Equivalent to data.slice(begin, end), where end is begin[i] + size[i] for all dimensions.

template<unsigned dimensions, class T> template<unsigned newDimensions = dimensions>
StridedArrayView<newDimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::slice() const

Expand or shrink dimension count.

Equivalent to data.slice<newDimensions>({}, data.size()).

template<unsigned dimensions, class T> template<class U>
StridedArrayView<dimensions, typename std::conditional<std::is_const<T>::value, const U, U>::type> Corrade::Containers::StridedArrayView<dimensions, T>::slice(U T::* member) const new in Git master

Slice to a member.

Returns a view on a particular structure member. Example usage:

struct Position {
    float x, y;
};

Containers::StridedArrayView1D<Position> data;
Containers::StridedArrayView1D<float> y = data.slice(&Position::y);

template<unsigned dimensions, class T> template<class U>
StridedArrayView<dimensions, U> Corrade::Containers::StridedArrayView<dimensions, T>::slice(U&(T::*)() memberFunction) const new in Git master

Slice to a member function.

Assuming the function takes no arguments and returns a reference to a class member, returns a view on such member.

class Color3 {
    public:
        

        float& r();
        float& g();
        float& b();

    private:
        
};

Containers::StridedArrayView1D<Color3> colors;
Containers::StridedArrayView1D<float> greens = colors.slice(&Color3::g);

Expects the function to return a reference to the class data members (i.e., the returned offset being less than sizeof(T)).

template<unsigned dimensions, class T> template<class U>
StridedArrayView<dimensions, U> Corrade::Containers::StridedArrayView<dimensions, T>::slice(U&(T::*)() memberFunction&) const new in Git master

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

template<unsigned dimensions, class T> template<class U>
StridedArrayView<dimensions, U> Corrade::Containers::StridedArrayView<dimensions, T>::slice(const U&(T::*)() const memberFunction) const new in Git master

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

template<unsigned dimensions, class T> template<class U>
StridedArrayView<dimensions, U> Corrade::Containers::StridedArrayView<dimensions, T>::slice(const U&(T::*)() const memberFunction&) const new in Git master

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

template<unsigned dimensions, class T>
BasicStridedBitArrayView<dimensions, ArithmeticType> Corrade::Containers::StridedArrayView<dimensions, T>::sliceBit(std::size_t index) const new in Git master

Slice to a bit.

Returns a bit view on a particular bit of the underlying type. The index is expected to be less than size of the type in bits, i.e. sizeof(T)*8. Additionally, due to restrictions of the BitArrayView family of APIs, on 32-bit systems the input size has to be less than 512M elements in all dimensions.

The returned view has the same size as the original, stride is converted from bytes to bits, and its BasicStridedBitArrayView::data() and offset() is derived from data() based on index. Example usage — converting a bool view to a StridedBitArrayView2D:

const bool data[]{
    true, false, true,
    false, true, false
};
Containers::StridedArrayView2D<const bool> bools{data, {3, 2}};

/* 1, 0, 1
   0, 1, 0 */
Containers::StridedBitArrayView2D bits = bools.sliceBit(0);

template<unsigned dimensions, class T>
StridedArrayView<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::prefix(std::size_t size) const

View on the first size items in the first dimension.

Equivalent to data.slice(0, size). On multi-dimensional views slices just the top-level dimension, use prefix(const Containers::Size<dimensions>&) const to slice in all dimensions.

template<unsigned dimensions, class T> template<unsigned newDimensions = dimensions>
StridedArrayView<newDimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::prefix(const Containers::Size<dimensions>& size) const

View on the first size items in all dimensions.

Equivalent to data.slice<newDimensions>({}, size).

template<unsigned dimensions, class T>
StridedArrayView<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::exceptPrefix(std::size_t size) const new in Git master

View except the first size items in the first dimension.

Equivalent to data.slice(size, data.size()[0]). On multi-dimensional views slices just the top-level dimension, use exceptPrefix(const Containers::Size<dimensions>&) const to slice in all dimensions.

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

View except the first size items in the first dimension.

template<unsigned dimensions, class T> template<unsigned newDimensions = dimensions>
StridedArrayView<newDimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::exceptPrefix(const Containers::Size<dimensions>& size) const new in Git master

View except the first size items in all dimensions.

Equivalent to data.slice<newDimensions>(size, data.size()).

template<unsigned dimensions, class T> template<unsigned newDimensions = dimensions>
StridedArrayView<newDimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::suffix(const Containers::Size<dimensions>& begin) const

View except the first size items in the first dimension.

template<unsigned dimensions, class T>
StridedArrayView<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::exceptSuffix(std::size_t size) const new in Git master

View except the last size items in the first dimension.

Equivalent to data.slice({}, data.size()[0] - size). On multi-dimensional views slices just the top-level dimension, use exceptSuffix(const Containers::Size<dimensions>&) const to slice in all dimensions.

template<unsigned dimensions, class T>
StridedArrayView<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::except(std::size_t count) const

View except the last size items in the first dimension.

template<unsigned dimensions, class T> template<unsigned newDimensions = dimensions>
StridedArrayView<newDimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::exceptSuffix(const Containers::Size<dimensions>& size) const new in Git master

View except the last size items in all dimensions.

Equivalent to data.slice<newDimensions>({}, end), where end is data.size()[i] - size[i] for all dimensions.

template<unsigned dimensions, class T> template<unsigned newDimensions = dimensions>
StridedArrayView<newDimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::except(const Containers::Size<dimensions>& count) const

View except the last size items in the first dimension.

template<unsigned dimensions, class T>
StridedArrayView<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::every(std::ptrdiff_t skip) const new in 2019.10

Pick every Nth element.

Multiplies stride() with skip and adjusts size() accordingly. Negative skip is equivalent to first calling flipped() and then this function with a positive value. On multi-dimensional views affects just the top-level dimension, use every(const Containers::Stride<dimensions>&) const to pick in all dimensions.

template<unsigned dimensions, class T>
StridedArrayView<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::every(const Containers::Stride<dimensions>& skip) const new in 2019.10

Pick every Nth element.

Multiplies stride() with skip and adjusts size() accordingly. Negative skip is equivalent to first calling flipped() and then this function with a positive value.

template<unsigned dimensions, class T> template<unsigned dimensionA, unsigned dimensionB>
StridedArrayView<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::transposed() const new in 2019.10

Transpose two dimensions.

Exchanges dimensions dimensionA and dimensionB by swapping their size and stride values. Together with flipped() can be used to do arbitrary 90° rotations of the view. This is a non-destructive operation on the view, transposing it again will go back to the original form.

template<unsigned dimensions, class T> template<unsigned dimension>
StridedArrayView<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::flipped() const new in 2019.10

Flip a dimension.

Flips given dimension by making its stride negative and adjusting the internal base data pointer. Together with transposed() can be used to do arbitrary 90° rotations of the view. This is a non-destructive operation on the view, flipping it again will go back to the original form.

template<unsigned dimensions, class T> template<unsigned dimension>
StridedArrayView<dimensions, T> Corrade::Containers::StridedArrayView<dimensions, T>::broadcasted(std::size_t size) const new in 2019.10

Broadcast a dimension.

Stretches the initial value to size in given dimension by setting its stride to 0 and size to size. To avoid destructive operations on the view, the function expects that size in given dimension is 1. If you need to broadcast a dimension that has more elements, slice() it first.

template<unsigned dimensions, class T> template<unsigned dimension, unsigned count>
StridedArrayView<dimensions+count - 1, T> Corrade::Containers::StridedArrayView<dimensions, T>::expanded(const Containers::Size<count>& size) const new in Git master

Expand a dimension.

Expands given dimension into multiple. The product of size is expected to be equal to size in the original dimension. The resulting view has sizes and strides before dimension unchanged, after that count - 1 new dimensions gets inserted, where each has size from size and stride equal to size times stride of the next dimension, then a dimension with size equal to last element of size and its original stride, and after that all other dimensions with sizes and strides unchanged again.

See collapsed() for an inverse of this operation.

template<unsigned dimensions, class T> template<unsigned dimension, unsigned count>
StridedArrayView<dimensions - count+1, T> Corrade::Containers::StridedArrayView<dimensions, T>::collapsed() const new in Git master

Collapse dimensions.

Assuming dimensions from dimension up to dimension + count - all have strides equal to size times stride of the next dimension, returns a view that has them all collapsed into one with its size equal to a product of sizes of these dimensions and stride equal to stride of the last dimension in this range.

See expanded() for an inverse of this operation and asContiguous() for a variant that collapses all dimensions from given index, requiring the stride of last one to be equal to the type size.

template<unsigned dimensions, class T> template<class T>
StridedArrayView1D<T> stridedArrayView(ArrayView<typename StridedArrayView1D<T>::ErasedType> data, T* member, std::size_t size, std::ptrdiff_t stride) constexpr new in 2020.06

Make an one-dimensional strided view.

Convenience alternative to StridedArrayView::StridedArrayView(ArrayView<ErasedType>, T*, const Containers::Size<dimensions>&, const Containers::Stride<dimensions>&). The following two lines are equivalent:

Containers::ArrayView<Position> data;

Containers::StridedArrayView1D<float> a{data, &data[0].x, 9, sizeof(Position)};
auto b = Containers::stridedArrayView(data, &data[0].x, 9, sizeof(Position));

See also StridedArrayView::slice() const for slicing into struct members.

template<unsigned dimensions, class T> template<class T>
StridedArrayView1D<T> stridedArrayView(ArrayView<T> data, std::size_t size, std::ptrdiff_t stride) constexpr new in Git master

Make an one-dimensional strided view with explicit size and stride.

Convenience alternative to StridedArrayView::StridedArrayView(ArrayView<T>, const Containers::Size<dimensions>&, const Containers::Stride<dimensions>&). The following two lines are equivalent, skipping all odd items in the array:

Containers::ArrayView<float> data;

Containers::StridedArrayView1D<float> a{data, 5, 8};
auto b = Containers::stridedArrayView(data, 5, 8);

template<unsigned dimensions, class T> template<class T>
StridedArrayView1D<T> stridedArrayView(T* data, std::size_t size) constexpr new in Git master

Make an one-dimensional strided view on an array of specific length.

Convenience alternative to StridedArrayView::StridedArrayView(T*, std::size_t). The following two lines are equivalent:

std::uint32_t* data = ;

Containers::StridedArrayView1D<std::uint32_t> a{data, 5};
auto b = Containers::stridedArrayView(data, 5);

template<unsigned dimensions, class T> template<std::size_t size, class T>
StridedArrayView1D<T> stridedArrayView(T(&data)[size]) constexpr new in 2019.10

Make an one-dimensional strided view on a fixed-size array.

Convenience alternative to StridedArrayView::StridedArrayView(U(&)[size]). The following two lines are equivalent:

std::uint32_t data[15];

Containers::StridedArrayView1D<std::uint32_t> a{data};
auto b = Containers::stridedArrayView(data);

template<unsigned dimensions, class T> template<class T>
StridedArrayView1D<const T> stridedArrayView(std::initializer_list<T> list) new in 2020.06

Make an one-dimensional strided view on an initializer list.

Not present as a constructor in order to avoid accidental dangling references with r-value initializer lists. See ArrayView documentation for more information.

template<unsigned dimensions, class T> template<class T>
StridedArrayView1D<T> stridedArrayView(ArrayView<T> view) constexpr new in 2019.10

Make an one-dimensional strided view on ArrayView.

Convenience alternative to StridedArrayView::StridedArrayView(ArrayView<U>). The following two lines are equivalent:

Containers::ArrayView<std::uint32_t> data;

Containers::StridedArrayView1D<std::uint32_t> a{data};
auto b = Containers::stridedArrayView(data);

template<unsigned dimensions, class T> template<std::size_t size, class T>
StridedArrayView1D<T> stridedArrayView(StaticArrayView<size, T> view) constexpr new in 2019.10

Make an one-dimensional strided view on StaticArrayView.

Convenience alternative to StridedArrayView::StridedArrayView(StaticArrayView<size, U>). The following two lines are equivalent:

Containers::StaticArrayView<15, std::uint32_t> data;

Containers::StridedArrayView1D<std::uint32_t> a{data};
auto b = Containers::stridedArrayView(data);

template<unsigned dimensions, class T> template<unsigned dimensions, class T>
StridedArrayView<dimensions, T> stridedArrayView(StridedArrayView<dimensions, T> view) constexpr new in 2019.10

Make a strided view on a strided view.

Equivalent to the implicit StridedArrayView copy constructor — it shouldn't be an error to call stridedArrayView() on itself.

template<unsigned dimensions, class T> template<class T, class U = decltype(stridedArrayView(Implementation::ErasedArrayViewConverter<typename std::remove_reference<T && >::type>::from(std::declval<T && >())))>
U stridedArrayView(T&& other) constexpr new in 2019.10

Make an one-dimensional strided view on an external type / from an external representation.

template<unsigned dimensions, class T> template<class U, unsigned dimensions, class T>
StridedArrayView<dimensions, U> arrayCast(const StridedArrayView<dimensions, T>& view)

Reinterpret-cast a strided array view.

Size of the new array is the same as original. Expects that both types are standard layout and sizeof(U) is not larger than any stride() of the original array. Works with negative and zero strides as well, however note that no type compatibility checks can be done for zero strides, so be extra careful in that case. Example usage:

struct Pixel {
    std::uint8_t r, g, b, a;
};

Pixel pixels[]{{0x33, 0xff, 0x99, 0x66}, {0x11, 0xab, 0x33, 0xff}};

auto red = Containers::StridedArrayView1D<std::uint8_t>{pixels, &pixels[0].r, 2, 4};
auto rgba = Containers::arrayCast<Pixel>(red);

template<unsigned dimensions, class T> template<class U, unsigned dimensions>
StridedArrayView<dimensions, U> arrayCast(const StridedArrayView<dimensions, const void>& view) new in 2020.06

Reinterpret-cast a void strided array view.

Size of the new array is the same as original. Expects that the target type is standard layout and sizeof(U) is not larger than any stride() of the original array. Works with negative and zero strides as well, however note that no type compatibility checks can be done for zero strides, so be extra careful in that case.

template<unsigned dimensions, class T> template<class U, unsigned dimensions>
StridedArrayView<dimensions, U> arrayCast(const StridedArrayView<dimensions, void>& view) new in 2020.06

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

template<unsigned dimensions, class T> template<unsigned newDimensions, class U, unsigned dimensions, class T>
StridedArrayView<newDimensions, U> arrayCast(const StridedArrayView<dimensions, T>& view) new in 2019.10

Reinterpret-cast and inflate or flatten a strided array view.

If newDimensions > dimensions, inflates the last dimension into the new type U, its element count being ratio of T and U sizes. The newDimensions template parameter is expected to always be one more than dimensions. This operation can be used for example to peek into individual channels pixel data:

struct Rgb {
    std::uint8_t r, g, b;
};

Containers::ArrayView<Rgb> pixels;

Containers::StridedArrayView2D<Rgb> view{pixels, {128, 128}};
Containers::StridedArrayView3D<std::uint8_t> rgb =
    Containers::arrayCast<3, std::uint8_t>(view);

If newDimensions < dimensions, flattens the last dimension into a contiguous new type U, expecting the last dimension to be contiguous and its stride equal to size of U. The newDimensions template parameter is expected to always be one less than dimensions.

Lastly, if newDimensions == dimensions, the last dimension is reinterpreted as U, expecting it to be contiguous and its total byte size being divisible by the size of U. The resulting last dimension has a size that's a ratio of T and U sizes and stride equivalent to U, being again contiguous.

Expects that both types are standard layout and sizeof(U) is not larger than any stride() of the original array. Works with negative and zero strides as well, however note that no type compatibility checks can be done for zero strides, so be extra careful in that case.

template<unsigned dimensions, class T> template<unsigned newDimensions, class U, unsigned dimensions>
StridedArrayView<newDimensions, U> arrayCast(const StridedArrayView<dimensions, const void>& view, std::size_t lastDimensionSize) new in 2020.06

Reinterpret-cast and inflate a void strided array view.

Inflates the last dimension into the new type U, its element count being lastDimensionSize. The newDimensions template parameter is expected to always be one more than dimensions. For flattening the view (inverse of this operation) you need to cast to a concrete type first.

Expects that the target type is standard layout and sizeof(U) is not larger than any stride() of the original array. Works with negative and zero strides as well, however note that no type compatibility checks can be done for zero strides, so be extra careful in that case.

template<unsigned dimensions, class T> template<unsigned newDimensions, class U, unsigned dimensions>
StridedArrayView<newDimensions, U> arrayCast(const StridedArrayView<dimensions, void>& view, std::size_t lastDimensionSize) new in 2020.06

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