Corrade::Containers namespace

Container implementations.

Contents

Implementations for various containers which don't have equivalents in STL.

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)

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.
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 NoInitT
No initialization tag type.
struct NullOptT
Null optional initialization tag type.
template<class T>
class Optional
Optional value.
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.
struct ValueInitT
Value initialization tag type.

Typedefs

template<class T>
using ArrayReference = ArrayView<T> deprecated
Array view with size information.

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 view on an array of specific length.
template<std::size_t size, class T>
auto arrayView(T(&data)[size]) -> ArrayView<T> constexpr
Make view on fixed-size array.
template<std::size_t size, class T>
auto arrayView(StaticArrayView<size, T> view) -> ArrayView<T> constexpr
Make view on StaticArrayView.
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
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 static view on an array.
template<std::size_t size, class T>
auto staticArrayView(T(&data)[size]) -> StaticArrayView<size, T> constexpr
Make static view on a fixed-size array.
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<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.

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.
DirectInitT DirectInit constexpr
Direct initialization tag.
InPlaceInitT InPlaceInit constexpr
In-place initialization tag.

Typedef documentation

template<class T>
using Corrade::Containers::ArrayReference = ArrayView<T>

Array view with size information.

Function documentation

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

Make view on Array.

Convenience alternative to calling Array::operator ArrayView<U>() 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 calling Array::operator ArrayView<U>() 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 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 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 view on StaticArrayView.

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

std::uint32_t data[15];

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

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)

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

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 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 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<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];
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 usage:

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 EnumSet<Feature> Features;
CORRADE_ENUMSET_OPERATORS(Features)

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

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

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

// 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<std::size_t size, class T>
ArrayView<T> Corrade::Containers::arrayView(StaticArray<size, T>& array) constexpr

Make view on StaticArray.

Convenience alternative to calling StaticArray::operator ArrayView<U>() 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 calling StaticArray::operator ArrayView<U>() 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 calling StaticArray::operator StaticArrayView<size_, U>() 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 calling StaticArray::operator StaticArrayView<size_, U>() 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.

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.

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.