Corrade::Containers namespace

Container implementations.

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>
struct ArrayAllocator new in Git master
Allocator for growable arrays.
template<class T>
struct ArrayMallocAllocator new in Git master
New-based allocator for growable arrays.
template<class T>
struct ArrayNewAllocator new in Git master
New-based allocator for growable arrays.
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> new in 2019.10
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 StridedArrayView<dimensions, const void> new in Git master
Multi-dimensional const void array view with size and stride information.
template<unsigned dimensions>
class StridedArrayView<dimensions, void> new in Git master
Multi-dimensional void array view with size and stride information.
template<unsigned dimensions, class T>
class StridedDimensions new in 2019.10
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 in 2019.01
Scope guard.
template<class T>
using StridedArrayView1D = StridedArrayView<1, T> new in 2019.10
One-dimensional strided array view.
template<class T>
using StridedArrayView2D = StridedArrayView<2, T> new in 2019.10
Two-dimensional strided array view.
template<class T>
using StridedArrayView3D = StridedArrayView<3, T> new in 2019.10
Three-dimensional strided array view.
template<class T>
using StridedArrayView4D = StridedArrayView<4, T> new in 2019.10
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 U>
auto arrayCast(ArrayView<void> view) -> ArrayView<U> new in Git master
Reinterpret-cast a void 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<class T>
auto stridedArrayView(ArrayView<typename StridedArrayView1D<T>::ErasedType> data, T* member, std::size_t size, std::ptrdiff_t stride) -> StridedArrayView1D<T> constexpr new in Git master
Make an one-dimensional strided view.
template<std::size_t size, class T>
auto stridedArrayView(T(&data)[size]) -> StridedArrayView1D<T> constexpr new in 2019.10
Make a strided view on a fixed-size array.
template<class T>
auto stridedArrayView(ArrayView<T> view) -> StridedArrayView1D<T> constexpr new in 2019.10
Make a strided view on ArrayView.
template<std::size_t size, class T>
auto stridedArrayView(StaticArrayView<size, T> view) -> StridedArrayView1D<T> constexpr new in 2019.10
Make a strided view on StaticArrayView.
template<unsigned dimensions, class T>
auto stridedArrayView(StridedArrayView<dimensions, T> view) -> StridedArrayView<dimensions, T> constexpr new in 2019.10
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 new in 2019.10
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<class U, unsigned dimensions>
auto arrayCast(const StridedArrayView<dimensions, void>& view) -> StridedArrayView<dimensions, U> new in Git master
Reinterpret-cast a void strided array view.
template<class U, unsigned dimensions>
auto arrayCast(const StridedArrayView<dimensions, const void>& view) -> StridedArrayView<dimensions, U> new in Git master
template<unsigned newDimensions, class U, unsigned dimensions, class T>
auto arrayCast(const StridedArrayView<dimensions, T>& view) -> StridedArrayView<newDimensions, U> new in 2019.10
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.

Growable array utilities

See Growable arrays for more information.

template<class U, class T>
auto arrayAllocatorCast(Array<T>&& array) -> Array<U> new in Git master
Reinterpret-cast a growable array.
template<class U, template<class> class Allocator, class T>
auto arrayAllocatorCast(Array<T>&& array) -> Array<U> new in Git master
template<class T, class Allocator = ArrayAllocator<T>>
auto arrayIsGrowable(Array<T>& array) -> bool new in Git master
Whether the array is growable.
template<class T, class Allocator = ArrayAllocator<T>>
auto arrayCapacity(Array<T>& array) -> std::size_t new in Git master
Array capacity.
template<class T, class Allocator = ArrayAllocator<T>>
auto arrayReserve(Array<T>& array, std::size_t capacity) -> std::size_t new in Git master
Reserve given capacity in an array.
template<class T, class Allocator = ArrayAllocator<T>>
void arrayResize(Array<T>& array, DefaultInitT, std::size_t size) new in Git master
Resize an array to given size, default-initializing new elements.
template<class T, class Allocator = ArrayAllocator<T>>
void arrayResize(Array<T>& array, ValueInitT, std::size_t size) new in Git master
Resize an array to given size, value-initializing new elements.
template<class T, class Allocator = ArrayAllocator<T>>
void arrayResize(Array<T>& array, std::size_t size) new in Git master
Resize an array to given size, value-initializing new elements.
template<class T, class Allocator = ArrayAllocator<T>>
void arrayResize(Array<T>& array, NoInitT, std::size_t size) new in Git master
Resize an array to given size, keeping new elements uninitialized.
template<class T, class... Args>
void arrayResize(Array<T>& array, DirectInitT, std::size_t size, Args && ... args) new in Git master
Resize an array to given size, constructing new elements using provided arguments.
template<class T, class Allocator, class... Args>
void arrayResize(Array<T>& array, DirectInitT, std::size_t size, Args && ... args) new in Git master
template<class T, class Allocator = ArrayAllocator<T>>
void arrayAppend(Array<T>& array, const T& value) new in Git master
Copy-append an item to an array.
template<class T, class... Args>
void arrayAppend(Array<T>& array, InPlaceInitT, Args && ... args) new in Git master
In-place append an item to an array.
template<class T, class Allocator, class... Args>
void arrayAppend(Array<T>& array, InPlaceInitT, Args && ... args) new in Git master
template<class T, class Allocator = ArrayAllocator<T>>
void arrayAppend(Array<T>& array, T&& value) new in Git master
Move-append an item to an array.
template<class T, class Allocator = ArrayAllocator<T>>
void arrayAppend(Array<T>& array, Containers::ArrayView<const T> values) new in Git master
Append a list of items to an array.
template<class T, class Allocator = ArrayAllocator<T>>
void arrayAppend(Array<T>& array, std::initializer_list<T> values) new in Git master
template<class T, class Allocator = ArrayAllocator<T>>
void arrayRemoveSuffix(Array<T>& array, std::size_t count = 1) new in Git master
Remove a suffix from the array.
template<class T, class Allocator = ArrayAllocator<T>>
void arrayShrink(Array<T>& array) new in Git master
Convert an array back to non-growable.

Typedef documentation

typedef ScopeGuard Corrade::Containers::ScopedExit

Scope guard.

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

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> new in 2019.10

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> new in 2019.10

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> new in 2019.10

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 U>
ArrayView<U> Corrade::Containers::arrayCast(ArrayView<void> view) new in Git master

Reinterpret-cast a void array view.

Size of the new array is calculated as view.size()/sizeof(U). Expects that the target type is standard layout and the total byte size doesn't change.

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(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<class T>
StridedArrayView1D<T> Corrade::Containers::stridedArrayView(ArrayView<typename StridedArrayView1D<T>::ErasedType> data, T* member, std::size_t size, std::ptrdiff_t stride) constexpr new in Git master

Make an one-dimensional strided view.

Convenience alternative to StridedArrayView::StridedArrayView(ArrayView<ErasedType>, T*, const Size&, const Stride&). 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));

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

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

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 new in 2019.10

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 new in 2019.10

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 new in 2019.10

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. 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<class U, unsigned dimensions>
StridedArrayView<dimensions, U> Corrade::Containers::arrayCast(const StridedArrayView<dimensions, void>& view) new in Git master

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

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);

template<class U, class T>
Array<U> Corrade::Containers::arrayAllocatorCast(Array<T>&& array) new in Git master

Reinterpret-cast a growable array.

If the array is growable using ArrayMallocAllocator (which is aliased to ArrayAllocator for all trivially-copyable types), the deleter is a simple call to a typeless std::free(). This makes it possible to change the array type without having to use a different deleter, losing the growable property in the process. Example usage:

Containers::Array<char> data;
Containers::Array<float> floats =
    Containers::arrayAllocatorCast<float>(std::move(data));
arrayAppend(floats, 37.0f);

Equivalently to to arrayCast(), the size of the new array is calculated as view.size()*sizeof(T)/sizeof(U). Expects that both types are trivially copyable and standard layout and the total byte size doesn't change.

template<class U, template<class> class Allocator, class T>
Array<U> Corrade::Containers::arrayAllocatorCast(Array<T>&& array) 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<class T, class Allocator = ArrayAllocator<T>>
bool Corrade::Containers::arrayIsGrowable(Array<T>& array) new in Git master

Whether the array is growable.

Returns true if the array is growable and using given Allocator, false otherwise. Note that even non-growable arrays are usable with the arrayAppend(), arrayReserve(), ... family of utilities — these will reallocate the array using provided allocator if needed.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
std::size_t Corrade::Containers::arrayCapacity(Array<T>& array) new in Git master

Array capacity.

For a growable array returns its capacity, for a non-growable array returns Array::size().

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
std::size_t Corrade::Containers::arrayReserve(Array<T>& array, std::size_t capacity) new in Git master

Reserve given capacity in an array.

Returns New capacity of the array

If array capacity is already large enough, the function returns the current capacity. Otherwise the memory is reallocated to desired capacity, with the Array::size() staying the same, and capacity returned back. Note that in case the array is non-growable of sufficient size, it's kept as such, without being reallocated to a growable version.

Complexity is at most $ \mathcal{O}(n) $ in the size of the original container, $ \mathcal{O}(1) $ if the capacity is already large enough or if the reallocation can be done in-place.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
void Corrade::Containers::arrayResize(Array<T>& array, DefaultInitT, std::size_t size) new in Git master

Resize an array to given size, default-initializing new elements.

If the array is growable and capacity is large enough, calls a destructor on elements that get cut off the end (if any, and if T is not trivially destructible, in which case nothing is done) and returns. Otherwise, the memory is reallocated to desired size. After that, new elements at the end of the array are default-initialized using placement-new (and nothing done for trivial types). Note that in case the array is non-growable of exactly the requested size, it's kept as such, without being reallocated to a growable version.

Complexity is at most $ \mathcal{O}(n) $ in the size of the new container, $ \mathcal{O}(1) $ if current container size is already exactly of given size.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
void Corrade::Containers::arrayResize(Array<T>& array, ValueInitT, std::size_t size) new in Git master

Resize an array to given size, value-initializing new elements.

Similar to arrayResize(Array<T>&, DefaultInitT, std::size_t) except that the new elements at the end are not default-initialized, but value-initialized (i.e., trivial types zero-initialized and default constructor called otherwise).

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
void Corrade::Containers::arrayResize(Array<T>& array, std::size_t size) new in Git master

Resize an array to given size, value-initializing new elements.

Alias to arrayResize(Array<T>&, ValueInitT, std::size_t).

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
void Corrade::Containers::arrayResize(Array<T>& array, NoInitT, std::size_t size) new in Git master

Resize an array to given size, keeping new elements uninitialized.

Similar to arrayResize(Array<T>&, DefaultInitT, std::size_t) except that the new elements at the end are not default-initialized, but left in an uninitialized state instead.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class... Args>
void Corrade::Containers::arrayResize(Array<T>& array, DirectInitT, std::size_t size, Args && ... args) new in Git master

Resize an array to given size, constructing new elements using provided arguments.

Similar to arrayResize(Array<T>&, DefaultInitT, std::size_t) except that the new elements at the end are constructed using placement-new with provided args.

template<class T, class Allocator, class... Args>
void Corrade::Containers::arrayResize(Array<T>& array, DirectInitT, std::size_t size, Args && ... args) 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.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
void Corrade::Containers::arrayAppend(Array<T>& array, const T& value) new in Git master

Copy-append an item to an array.

If the array is not growable or the capacity is not large enough, the array capacity is grown first. Then, value is copy-constructed at the end of the array and Array::size() increased by 1.

Amortized complexity is $ \mathcal{O}(1) $ providing the allocator growth ratio is exponential.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class... Args>
void Corrade::Containers::arrayAppend(Array<T>& array, InPlaceInitT, Args && ... args) new in Git master

In-place append an item to an array.

Similar to arrayAppend(Array<T>&, const T&) except that the new element is constructed using placement-new with provided args.

template<class T, class Allocator, class... Args>
void Corrade::Containers::arrayAppend(Array<T>& array, InPlaceInitT, Args && ... args) 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.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
void Corrade::Containers::arrayAppend(Array<T>& array, T&& value) new in Git master

Move-append an item to an array.

Calls arrayAppend(Array<T>&, InPlaceInitT, Args&&... args) with value.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
void Corrade::Containers::arrayAppend(Array<T>& array, Containers::ArrayView<const T> values) new in Git master

Append a list of items to an array.

Like arrayAppend(Array<T>&, const T&), but inserting multiple values at once.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
void Corrade::Containers::arrayAppend(Array<T>& array, std::initializer_list<T> values) 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.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
void Corrade::Containers::arrayRemoveSuffix(Array<T>& array, std::size_t count = 1) new in Git master

Remove a suffix from the array.

Expects that count is not larger than Array::size(). If the array is not growable, all its elements except the suffix are first reallocated to a growable version. Otherwise, a destructor is called on removed elements and the Array::size() is decreased by count.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

template<class T, class Allocator = ArrayAllocator<T>>
void Corrade::Containers::arrayShrink(Array<T>& array) new in Git master

Convert an array back to non-growable.

Allocates memory that's exactly large enough to fit Array::size() elements, move-constructs the elements there and frees the old memory using Array::deleter(). If the array is not growable, it's assumed to be already as small as possible, and nothing is done.

Complexity is at most $ \mathcal{O}(n) $ in the size of the container, $ \mathcal{O}(1) $ if the array is already non-growable.

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

Convenience overload allowing to specify just the allocator template, with array type being inferred.

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.