Corrade::Containers namespace

Container implementations.

Contents

Implementations for various containers which don't have direct equivalents in STL or are better tailored to specific use cases than general standard implementations.

This library is built if WITH_UTILITY is enabled when building Corrade. To use this library with CMake, you need to request the Containers component of the Corrade package and link to the Corrade::Containers target:

find_package(Corrade REQUIRED Containers)

# ...
target_link_libraries(your-app Corrade::Containers)

Parts of this library are additionally available in a form of single-header libraries. See also Downloading and building Corrade and Using Corrade with CMake for more information.

Classes

template<class T, class D = void(*)(T*, std::size_t)>
class Array
Array wrapper with size information.
template<class T>
class ArrayView
Array view with size information.
template<>
class ArrayView<const void>
Constant void array view with size information.
template<>
class ArrayView<void>
Void array view with size information.
struct DefaultInitT
Default initialization tag type.
struct DirectInitT
Direct initialization tag type.
template<class T, typename std::underlying_type<T>::type fullValue = typename std::underlying_type<T>::type(~0)>
class EnumSet
Set of enum values.
struct InPlaceInitT
In-place initialization tag type.
template<class T>
class LinkedList
Linked list.
template<class Derived, class List = LinkedList<Derived>>
class LinkedListItem
Item of LinkedList.
struct NoCreateT
No creation tag type.
struct NoInitT
No initialization tag type.
struct NullOptT
Null optional initialization tag type.
template<class T>
class Optional
Lightweight optional value.
template<class T>
class Pointer
Lightweight unique pointer.
template<class T>
class Reference
Lightweight non-owning reference wrapper.
class ScopeGuard
Scope guard.
template<std::size_t size_, class T>
class StaticArray
Static array wrapper.
template<std::size_t size_, class T>
class StaticArrayView
Fixed-size array view.
template<unsigned dimensions, class T>
class StridedArrayView
Multi-dimensional array view with size and stride information.
template<unsigned dimensions, class T>
class StridedDimensions
Helper for specifying sizes and strides for StridedArrayView.
template<unsigned dimensions, class T>
class StridedIterator
Strided array view iterator.
struct ValueInitT
Value initialization tag type.

Typedefs

using ScopedExit = ScopeGuard deprecated
Scope guard.
template<class T>
using StridedArrayView1D = StridedArrayView<1, T>
One-dimensional strided array view.
template<class T>
using StridedArrayView2D = StridedArrayView<2, T>
Two-dimensional strided array view.
template<class T>
using StridedArrayView3D = StridedArrayView<3, T>
Three-dimensional strided array view.
template<class T>
using StridedArrayView4D = StridedArrayView<4, T>
Four-dimensional strided array view.

Functions

template<class T, class D>
auto arrayView(Array<T, D>& array) -> ArrayView<T>
Make view on Array.
template<class T, class D>
auto arrayView(const Array<T, D>& array) -> ArrayView<const T>
Make view on const Array.
template<class U, class T, class D>
auto arrayCast(Array<T, D>& array) -> ArrayView<U>
Reinterpret-cast an array.
template<class U, class T, class D>
auto arrayCast(const Array<T, D>& array) -> ArrayView<const U>
template<class T>
auto arraySize(const Array<T>& view) -> std::size_t
Array size.
template<class T>
auto arrayView(T* data, std::size_t size) -> ArrayView<T> constexpr
Make a view on an array of specific length.
template<std::size_t size, class T>
auto arrayView(T(&data)[size]) -> ArrayView<T> constexpr
Make a view on fixed-size array.
template<std::size_t size, class T>
auto arrayView(StaticArrayView<size, T> view) -> ArrayView<T> constexpr
Make a view on StaticArrayView.
template<class T>
auto arrayView(ArrayView<T> view) -> ArrayView<T> constexpr
Make a view on a view.
template<class T, class U = decltype(Implementation::ErasedArrayViewConverter<typename std::remove_reference<T && >::type>::from(std::declval<T && >()))>
auto arrayView(T&& other) -> U constexpr
Make a view on an external type / from an external representation.
template<class U, class T>
auto arrayCast(ArrayView<T> view) -> ArrayView<U>
Reinterpret-cast an array view.
template<class T>
auto arraySize(ArrayView<T> view) -> std::size_t constexpr
Array view size.
template<std::size_t size_, class T>
auto arraySize(StaticArrayView<size_, T>) -> std::size_t constexpr
template<std::size_t size_, class T>
auto arraySize(T(&)[size_]) -> std::size_t constexpr
template<std::size_t size, class T>
auto staticArrayView(T* data) -> StaticArrayView<size, T> constexpr
Make a static view on an array.
template<std::size_t size, class T>
auto staticArrayView(T(&data)[size]) -> StaticArrayView<size, T> constexpr
Make a static view on a fixed-size array.
template<std::size_t size, class T>
auto staticArrayView(StaticArrayView<size, T> view) -> StaticArrayView<size, T> constexpr
Make a static view on a view.
template<class T, class U = decltype(Implementation::ErasedStaticArrayViewConverter<typename std::remove_reference<T && >::type>::from(std::declval<T && >()))>
auto staticArrayView(T&& other) -> U constexpr
Make a static view on an external type / from an external representation.
template<class U, std::size_t size, class T>
auto arrayCast(StaticArrayView<size, T> view) -> StaticArrayView<size*sizeof(T)/sizeof(U), U>
Reinterpret-cast a static array view.
template<class U, std::size_t size, class T>
auto arrayCast(T(&data)[size]) -> StaticArrayView<size*sizeof(T)/sizeof(U), U>
Reinterpret-cast a statically sized array.
template<class T, typename std::underlying_type<T>::type fullValue>
auto enumSetDebugOutput(Utility::Debug& debug, EnumSet<T, fullValue> value, const char* empty, std::initializer_list<T> enums) -> Utility::Debug&
Print enum set to debug output.
template<class T>
auto optional(T&& value) -> Optional<typename std::decay<T>::type>
Make an optional.
template<class T, class ... Args>
auto optional(Args && ... args) -> Optional<T>
Make an optional.
template<class T>
auto optional(T&& other) -> auto
Make an optional from external representation.
template<class T>
auto pointer(T* pointer) -> Pointer<T>
Make a unique pointer.
template<class T>
auto pointer(T&& other) -> auto
Make a unique pointer from external representation.
template<class U, class T>
auto pointerCast(Pointer<T>&& pointer) -> Pointer<U>
Downcast a pointer.
template<class T, class ... Args>
auto pointer(Args && ... args) -> Pointer<T>
Make a unique pointer.
template<std::size_t size, class T>
auto arrayView(StaticArray<size, T>& array) -> ArrayView<T> constexpr
Make view on StaticArray.
template<std::size_t size, class T>
auto arrayView(const StaticArray<size, T>& array) -> ArrayView<const T> constexpr
Make view on const StaticArray.
template<std::size_t size, class T>
auto staticArrayView(StaticArray<size, T>& array) -> StaticArrayView<size, T> constexpr
Make static view on StaticArray.
template<std::size_t size, class T>
auto staticArrayView(const StaticArray<size, T>& array) -> StaticArrayView<size, const T> constexpr
Make static view on const StaticArray.
template<class U, std::size_t size, class T>
auto arrayCast(StaticArray<size, T>& array) -> StaticArrayView<size*sizeof(T)/sizeof(U), U>
Reinterpret-cast a static array.
template<class U, std::size_t size, class T>
auto arrayCast(const StaticArray<size, T>& array) -> StaticArrayView<size*sizeof(T)/sizeof(U), const U>
template<std::size_t size_, class T>
auto arraySize(const StaticArray<size_, T>&) -> std::size_t constexpr
Static array size.
template<std::size_t size, class T>
auto stridedArrayView(T(&data)[size]) -> StridedArrayView1D<T> constexpr
Make a strided view on fixed-size array.
template<class T>
auto stridedArrayView(ArrayView<T> view) -> StridedArrayView1D<T> constexpr
Make a strided view on ArrayView.
template<std::size_t size, class T>
auto stridedArrayView(StaticArrayView<size, T> view) -> StridedArrayView1D<T> constexpr
Make a strided view on StaticArrayView.
template<unsigned dimensions, class T>
auto stridedArrayView(StridedArrayView<dimensions, T> view) -> StridedArrayView<dimensions, T> constexpr
Make a view on a view.
template<class T, class U = decltype(stridedArrayView(Implementation::ErasedArrayViewConverter<typename std::remove_reference<T && >::type>::from(std::declval<T && >())))>
auto stridedArrayView(T&& other) -> U constexpr
Make a strided view on an external type / from an external representation.
template<class U, unsigned dimensions, class T>
auto arrayCast(const StridedArrayView<dimensions, T>& view) -> StridedArrayView<dimensions, U>
Reinterpret-cast a strided array view.
template<unsigned newDimensions, class U, unsigned dimensions, class T>
auto arrayCast(const StridedArrayView<dimensions, T>& view) -> StridedArrayView<newDimensions, U>
Reinterpret-cast and flatten or inflate a strided array view.

Variables

NullOptT NullOpt constexpr
Null optional initialization tag.
DefaultInitT DefaultInit constexpr
Default initialization tag.
ValueInitT ValueInit constexpr
Value initialization tag.
NoInitT NoInit constexpr
No initialization tag.
NoCreateT NoCreate constexpr
No creation tag.
DirectInitT DirectInit constexpr
Direct initialization tag.
InPlaceInitT InPlaceInit constexpr
In-place initialization tag.

Typedef documentation

typedef ScopeGuard Corrade::Containers::ScopedExit

Scope guard.

template<class T>
using Corrade::Containers::StridedArrayView1D = StridedArrayView<1, T>

One-dimensional strided array view.

Convenience alternative to StridedArrayView<1, T>. See StridedArrayView for more information.

template<class T>
using Corrade::Containers::StridedArrayView2D = StridedArrayView<2, T>

Two-dimensional strided array view.

Convenience alternative to StridedArrayView<2, T>. See StridedArrayView for more information.

template<class T>
using Corrade::Containers::StridedArrayView3D = StridedArrayView<3, T>

Three-dimensional strided array view.

Convenience alternative to StridedArrayView<3, T>. See StridedArrayView for more information.

template<class T>
using Corrade::Containers::StridedArrayView4D = StridedArrayView<4, T>

Four-dimensional strided array view.

Convenience alternative to StridedArrayView<4, T>. See StridedArrayView for more information.

Function documentation

template<class T, class D>
ArrayView<T> Corrade::Containers::arrayView(Array<T, D>& array)

Make view on Array.

Convenience alternative to converting to an ArrayView explicitly. The following two lines are equivalent:

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

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

template<class T, class D>
ArrayView<const T> Corrade::Containers::arrayView(const Array<T, D>& array)

Make view on const Array.

Convenience alternative to converting to an ArrayView explicitly. The following two lines are equivalent:

const Containers::Array<std::uint32_t> data;

Containers::ArrayView<const std::uint32_t> a{data};
auto b = Containers::arrayView(data);

template<class U, class T, class D>
ArrayView<U> Corrade::Containers::arrayCast(Array<T, D>& array)

Reinterpret-cast an array.

See arrayCast(ArrayView<T>) for more information.

template<class U, class T, class D>
ArrayView<const U> Corrade::Containers::arrayCast(const Array<T, D>& array)

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>
std::size_t Corrade::Containers::arraySize(const Array<T>& view)

Array size.

See arraySize(ArrayView<T>) for more information.

template<class T>
ArrayView<T> Corrade::Containers::arrayView(T* data, std::size_t size) constexpr

Make a view on an array of specific length.

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

std::uint32_t* data;

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

template<std::size_t size, class T>
ArrayView<T> Corrade::Containers::arrayView(T(&data)[size]) constexpr

Make a view on fixed-size array.

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

std::uint32_t data[15];

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

template<std::size_t size, class T>
ArrayView<T> Corrade::Containers::arrayView(StaticArrayView<size, T> view) constexpr

Make a view on StaticArrayView.

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

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

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

template<class T>
ArrayView<T> Corrade::Containers::arrayView(ArrayView<T> view) constexpr

Make a view on a view.

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

template<class T, class U = decltype(Implementation::ErasedArrayViewConverter<typename std::remove_reference<T && >::type>::from(std::declval<T && >()))>
U Corrade::Containers::arrayView(T&& other) constexpr

Make a view on an external type / from an external representation.

template<class U, class T>
ArrayView<U> Corrade::Containers::arrayCast(ArrayView<T> view)

Reinterpret-cast an array view.

Size of the new array is calculated as view.size()*sizeof(T)/sizeof(U). Expects that both types are standard layout and the total byte size doesn't change. Example usage:

std::int32_t data[15];
auto a = Containers::arrayView(data); // a.size() == 15
auto b = Containers::arrayCast<char>(a); // b.size() == 60

template<class T>
std::size_t Corrade::Containers::arraySize(ArrayView<T> view) constexpr

Array view size.

Alias to ArrayView::size(), useful as a shorthand in cases like this:

std::int32_t a[5];

std::size_t size = Containers::arraySize(a); // size == 5

template<std::size_t size_, class T>
std::size_t Corrade::Containers::arraySize(StaticArrayView<size_, T>) constexpr

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

template<std::size_t size_, class T>
std::size_t Corrade::Containers::arraySize(T(&)[size_]) constexpr

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

template<std::size_t size, class T>
StaticArrayView<size, T> Corrade::Containers::staticArrayView(T* data) constexpr

Make a static view on an array.

Convenience alternative to StaticArrayView::StaticArrayView(T*). The following two lines are equivalent:

std::uint32_t* data;

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

template<std::size_t size, class T>
StaticArrayView<size, T> Corrade::Containers::staticArrayView(T(&data)[size]) constexpr

Make a static view on a fixed-size array.

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

std::uint32_t data[15];

Containers::StaticArrayView<15, std::uint32_t> a{data};
auto b = Containers::staticArrayView(data);

template<std::size_t size, class T>
StaticArrayView<size, T> Corrade::Containers::staticArrayView(StaticArrayView<size, T> view) constexpr

Make a static view on a view.

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

template<class T, class U = decltype(Implementation::ErasedStaticArrayViewConverter<typename std::remove_reference<T && >::type>::from(std::declval<T && >()))>
U Corrade::Containers::staticArrayView(T&& other) constexpr

Make a static view on an external type / from an external representation.

template<class U, std::size_t size, class T>
StaticArrayView<size*sizeof(T)/sizeof(U), U> Corrade::Containers::arrayCast(StaticArrayView<size, T> view)

Reinterpret-cast a static array view.

Size of the new array is calculated as view.size()*sizeof(T)/sizeof(U). Expects that both types are standard layout and the total byte size doesn't change. Example usage:

std::int32_t data[15];
auto a = Containers::staticArrayView(data); // a.size() == 15
Containers::StaticArrayView<60, char> b = Containers::arrayCast<char>(a);

template<class U, std::size_t size, class T>
StaticArrayView<size*sizeof(T)/sizeof(U), U> Corrade::Containers::arrayCast(T(&data)[size])

Reinterpret-cast a statically sized array.

Calls arrayCast(StaticArrayView<size, T>) with the argument converted to StaticArrayView of the same type and size. Example usage:

std::int32_t data[15];
auto a = Containers::arrayCast<char>(data); // a.size() == 60

template<class T, typename std::underlying_type<T>::type fullValue>
Utility::Debug& Corrade::Containers::enumSetDebugOutput(Utility::Debug& debug, EnumSet<T, fullValue> value, const char* empty, std::initializer_list<T> enums)

Print enum set to debug output.

Parameters
debug Debug output
value Value to be printed
empty What to print in case of an empty enum set
enums Recognized enum values

Assuming underlying enum type has already implemented operator<< for Utility::Debug, this function is able to print value of given enum set. Example definition:

enum class Feature: unsigned int {
    Fast = 1 << 0,
    Cheap = 1 << 1,
    Tested = 1 << 2,
    Popular = 1 << 3
};

// already defined to print values as e.g. Feature::Fast and Features(0xabcd)
// for unknown values
Utility::Debug& operator<<(Utility::Debug&, Feature);

typedef Containers::EnumSet<Feature> Features;
CORRADE_ENUMSET_OPERATORS(Features)

Utility::Debug& operator<<(Utility::Debug& debug, Features value) {
    return Containers::enumSetDebugOutput(debug, value, "Features{}", {
        Feature::Fast,
        Feature::Cheap,
        Feature::Tested,
        Feature::Popular});
}

The usage would be then straightforward:

// prints Feature::Fast|Feature::Cheap
Utility::Debug{} << (Feature::Fast|Feature::Cheap);

// prints Feature::Popular|Feature(0xdead)
Utility::Debug{} << (Feature::Popular|Feature(0xdead));

// prints Features{}
Utility::Debug{} << Features{};

template<class T>
Optional<typename std::decay<T>::type> Corrade::Containers::optional(T&& value)

Make an optional.

Convenience alternative to Optional::Optional(const T&) or Optional::Optional(T&&). The following two lines are equivalent:

std::string value;

auto a = Containers::Optional<std::string>{value};
auto b = Containers::optional(value);

template<class T, class ... Args>
Optional<T> Corrade::Containers::optional(Args && ... args)

Make an optional.

Convenience alternative to Optional::Optional(InPlaceInitT, Args&&... args). The following two lines are equivalent:

auto a = Containers::Optional<std::string>{Containers::InPlaceInit, 'a', 'b'};
auto b = Containers::optional<std::string>('a', 'b');

template<class T>
auto Corrade::Containers::optional(T&& other)

Make an optional from external representation.

template<class T>
Pointer<T> Corrade::Containers::pointer(T* pointer)

Make a unique pointer.

Convenience alternative to Pointer::Pointer(T*). The following two lines are equivalent:

std::string* ptr;

auto a = Containers::Pointer<std::string>{ptr};
auto b = Containers::pointer(ptr);

template<class T>
auto Corrade::Containers::pointer(T&& other)

Make a unique pointer from external representation.

template<class U, class T>
Pointer<U> Corrade::Containers::pointerCast(Pointer<T>&& pointer)

Downcast a pointer.

While upcasting (derived to base) is handled implicitly with Pointer::Pointer(Pointer<U>&&), downcasting needs to be done explicitly. Performs static_cast<U>(), calling Pointer::release() on pointer. You have to ensure the pointer is actually of type U, as only the inheritance relation between T and U is checked at compile time, not the actual type stored in pointer.

Casting with dynamic_cast<U>() is not supported, as it would lead to a destructive behavior in case the instance is not of type U. The standard library provides std::dynamic_pointer_cast() and friends for this case, but they return a std::shared_ptr in order to behave non-destructively.

template<class T, class ... Args>
Pointer<T> Corrade::Containers::pointer(Args && ... args)

Make a unique pointer.

Convenience alternative to Pointer::Pointer(InPlaceInitT, Args&&... args), similar to std::make_unique() from C++14. The following two lines are equivalent:

auto a = Containers::Pointer<std::string>{Containers::InPlaceInit, 'a', 'b'};
auto b = Containers::pointer<std::string>('a', 'b');

template<std::size_t size, class T>
ArrayView<T> Corrade::Containers::arrayView(StaticArray<size, T>& array) constexpr

Make view on StaticArray.

Convenience alternative to converting to an ArrayView explicitly. The following two lines are equivalent:

Containers::StaticArray<5, std::uint32_t> data;

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

template<std::size_t size, class T>
ArrayView<const T> Corrade::Containers::arrayView(const StaticArray<size, T>& array) constexpr

Make view on const StaticArray.

Convenience alternative to converting to an ArrayView explicitly. The following two lines are equivalent:

const Containers::StaticArray<5, std::uint32_t> data;

Containers::ArrayView<const std::uint32_t> a{data};
auto b = Containers::arrayView(data);

template<std::size_t size, class T>
StaticArrayView<size, T> Corrade::Containers::staticArrayView(StaticArray<size, T>& array) constexpr

Make static view on StaticArray.

Convenience alternative to converting to an StaticArrayView explicitly. The following two lines are equivalent:

Containers::StaticArray<5, std::uint32_t> data;

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

template<std::size_t size, class T>
StaticArrayView<size, const T> Corrade::Containers::staticArrayView(const StaticArray<size, T>& array) constexpr

Make static view on const StaticArray.

Convenience alternative to converting to an StaticArrayView explicitly. The following two lines are equivalent:

const Containers::StaticArray<5, std::uint32_t> data;

Containers::StaticArrayView<5, const std::uint32_t> a{data};
auto b = Containers::staticArrayView(data);

template<class U, std::size_t size, class T>
StaticArrayView<size*sizeof(T)/sizeof(U), U> Corrade::Containers::arrayCast(StaticArray<size, T>& array)

Reinterpret-cast a static array.

See arrayCast(StaticArrayView<size, T>) for more information.

template<class U, std::size_t size, class T>
StaticArrayView<size*sizeof(T)/sizeof(U), const U> Corrade::Containers::arrayCast(const StaticArray<size, T>& array)

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

template<std::size_t size_, class T>
std::size_t Corrade::Containers::arraySize(const StaticArray<size_, T>&) constexpr

Static array size.

See arraySize(ArrayView<T>) for more information.

template<std::size_t size, class T>
StridedArrayView1D<T> Corrade::Containers::stridedArrayView(T(&data)[size]) constexpr

Make a strided view on 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<class T>
StridedArrayView1D<T> Corrade::Containers::stridedArrayView(ArrayView<T> view) constexpr

Make a 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<std::size_t size, class T>
StridedArrayView1D<T> Corrade::Containers::stridedArrayView(StaticArrayView<size, T> view) constexpr

Make a 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>
StridedArrayView<dimensions, T> Corrade::Containers::stridedArrayView(StridedArrayView<dimensions, T> view) constexpr

Make a view on a view.

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

template<class T, class U = decltype(stridedArrayView(Implementation::ErasedArrayViewConverter<typename std::remove_reference<T && >::type>::from(std::declval<T && >())))>
U Corrade::Containers::stridedArrayView(T&& other) constexpr

Make a strided view on an external type / from an external representation.

template<class U, unsigned dimensions, class T>
StridedArrayView<dimensions, U> Corrade::Containers::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.

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 newDimensions, class U, unsigned dimensions, class T>
StridedArrayView<newDimensions, U> Corrade::Containers::arrayCast(const StridedArrayView<dimensions, T>& view)

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

If newDimensions is one less than dimensions, flattens the last dimension into a tightly packed new type U, expecting the last dimension to be tightly packed and its stride equal to size of U. If newDimensions is one more than dimensions, inflates the last dimension into the new type U, its element count being ratio of T and U sizes. 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);

Variable documentation

NullOptT Corrade::Containers::NullOpt constexpr

Null optional initialization tag.

Use for explicit initialization of null Optional.

DefaultInitT Corrade::Containers::DefaultInit constexpr

Default initialization tag.

Use for construction using default initialization (builtin types are not initialized, others are default-constructed).

ValueInitT Corrade::Containers::ValueInit constexpr

Value initialization tag.

Use for construction using value initialization (builtin types are zeroed out, others are default-constructed).

NoInitT Corrade::Containers::NoInit constexpr

No initialization tag.

Use for construction with no initialization at all.

NoCreateT Corrade::Containers::NoCreate constexpr

No creation tag.

Use for construction with initialization, but keeping the instance empty (usually equivalent to a moved-out state).

DirectInitT Corrade::Containers::DirectInit constexpr

Direct initialization tag.

Use for construction with direct initialization.

InPlaceInitT Corrade::Containers::InPlaceInit constexpr

In-place initialization tag.

Use for construction in-place.