template<std::size_t size_, class T>
Corrade::Containers::StaticArray class

Static array wrapper.

Template parameters
size_ Array size
T Element type

Provides statically-sized array wrapper with API similar to Array. Useful as more featureful alternative to plain C arrays or std::array.

Usage example:

// Create default-initialized array with 5 integers and set them to some value
Containers::StaticArray<5, int> a;
int b = 0;
for(auto& i: a) i = b++; // a = {0, 1, 2, 3, 4}

// Create array from given values
Containers::StaticArray<4, int> b{3, 18, -157, 0};
b[3] = 25; // b = {3, 18, -157, 25}

Array initialization

The array is by default default-initialized, which means that trivial types are not initialized at all and default constructor is called on other types. It is possible to initialize the array in a different way using so-called tags:

Example:

// These two are equivalent
Containers::StaticArray<5, int> a1;
Containers::StaticArray<5, int> a2{Containers::DefaultInit};

// Array of 100 zeros
Containers::StaticArray<100, int> b{Containers::ValueInit};

// Array of 4 values initialized in-place (these two are equivalent)
Containers::StaticArray<4, int> c1{3, 18, -157, 0};
Containers::StaticArray<4, int> c2{Containers::InPlaceInit, 3, 18, -157, 0};

// Array of type with no default constructor
struct Vec3 {
    Vec3(float, float, float);
};
Containers::StaticArray<5, Vec3> d{Containers::DirectInit, 5.2f, 0.4f, 1.0f};

// Manual construction of each element
struct Foo {
    Foo(int index);
};
Containers::StaticArray<5, Foo> e{Containers::NoInit};
int index = 0;
for(Foo& f: e) new(&f) Foo(index++);

Public types

enum (anonymous): std::size_t { Size = size_ }
using Type = T
Element type.

Constructors, destructors, conversion operators

StaticArray(DefaultInitT) explicit
Construct default-initialized array.
StaticArray(ValueInitT) explicit
Construct value-initialized array.
StaticArray(NoInitT) explicit
Construct the array without initializing its contents.
template<class... Args>
StaticArray(DirectInitT, Args&&... args) explicit
Construct direct-initialized array.
template<class... Args>
StaticArray(InPlaceInitT, Args&&... args) explicit
Construct in-place-initialized array.
StaticArray() explicit
Construct default-initialized array.
template<class... Args>
StaticArray(Args&&... args) explicit
Construct in-place-initialized array.
StaticArray(const StaticArray<size_, T>&) deleted
Copying is not allowed.
StaticArray(StaticArray<size_, T>&&) deleted
Moving is not allowed.
template<class U>
operator ArrayView<U>() noexcept
Convert to ArrayView.
template<class U>
operator ArrayView<const U>() const noexcept
Convert to const ArrayView.
operator ArrayView<const void>() const noexcept
template<class U>
operator StaticArrayView<size_, U>() noexcept
Convert to StaticArrayView.
template<class U>
operator StaticArrayView<size_, const U>() const noexcept
Convert to const StaticArrayView.
operator T*() &
Conversion to array type.
operator const T*() const &

Public functions

auto operator=(const StaticArray<size_, T>&) -> StaticArray<size_, T>& deleted
Copying is not allowed.
auto operator=(StaticArray<size_, T>&&) -> StaticArray<size_, T>& deleted
Moving is not allowed.
auto data() -> T*
Array data.
auto data() const -> const T*
auto size() const -> std::size_t constexpr
Array size.
auto empty() const -> bool constexpr
Whether the array is empty.
auto begin() -> T*
Pointer to first element.
auto begin() const -> const T*
auto cbegin() const -> const T*
auto end() -> T*
Pointer to (one item after) last element.
auto end() const -> const T*
auto cend() const -> const T*
auto slice(T* begin, T* end) -> ArrayView<T>
Reference to array slice.
auto slice(const T* begin, const T* end) const -> ArrayView<const T>
auto slice(std::size_t begin, std::size_t end) -> ArrayView<T>
auto slice(std::size_t begin, std::size_t end) const -> ArrayView<const T>
template<std::size_t viewSize>
auto slice(T* begin) -> StaticArrayView<viewSize, T>
Fixed-size array slice.
template<std::size_t viewSize>
auto slice(const T* begin) const -> StaticArrayView<viewSize, const T>
template<std::size_t viewSize>
auto slice(std::size_t begin) -> StaticArrayView<viewSize, T>
template<std::size_t viewSize>
auto slice(std::size_t begin) const -> StaticArrayView<viewSize, const T>
auto prefix(T* end) -> ArrayView<T>
Array prefix.
auto prefix(const T* end) const -> ArrayView<const T>
auto prefix(std::size_t end) -> ArrayView<T>
auto prefix(std::size_t end) const -> ArrayView<const T>
auto suffix(T* begin) -> ArrayView<T>
Array suffix.
auto suffix(const T* begin) const -> ArrayView<const T>
auto suffix(std::size_t begin) -> ArrayView<T>
auto suffix(std::size_t begin) const -> ArrayView<const T>

Enum documentation

template<std::size_t size_, class T>
enum Corrade::Containers::StaticArray<size_, T>::(anonymous): std::size_t

Enumerators
Size

Array size

Function documentation

template<std::size_t size_, class T>
Corrade::Containers::StaticArray<size_, T>::StaticArray(DefaultInitT) explicit

Construct default-initialized array.

Creates array of given size, the contents are default-initialized (i.e. builtin types are not initialized).

template<std::size_t size_, class T>
Corrade::Containers::StaticArray<size_, T>::StaticArray(ValueInitT) explicit

Construct value-initialized array.

Creates array of given size, the contents are value-initialized (i.e. builtin types are zero-initialized). For other than builtin types this is the same as StaticArray().

Useful if you want to create an array of primitive types and set them to zero.

template<std::size_t size_, class T>
Corrade::Containers::StaticArray<size_, T>::StaticArray(NoInitT) explicit

Construct the array without initializing its contents.

Creates array of given size, the contents are not initialized. Initialize the values using placement new.

Useful if you will be overwriting all elements later anyway.

template<std::size_t size_, class T> template<class... Args>
Corrade::Containers::StaticArray<size_, T>::StaticArray(DirectInitT, Args&&... args) explicit

Construct direct-initialized array.

Constructs the array using the StaticArray(NoInitT) constructor and then initializes each element with placement new using forwarded args.

template<std::size_t size_, class T> template<class... Args>
Corrade::Containers::StaticArray<size_, T>::StaticArray(InPlaceInitT, Args&&... args) explicit

Construct in-place-initialized array.

The arguments are forwarded to the array constructor.

template<std::size_t size_, class T>
Corrade::Containers::StaticArray<size_, T>::StaticArray() explicit

Construct default-initialized array.

Alias to StaticArray(DefaultInitT).

template<std::size_t size_, class T> template<class... Args>
Corrade::Containers::StaticArray<size_, T>::StaticArray(Args&&... args) explicit

Construct in-place-initialized array.

Alias to StaticArray(InPlaceInitT, Args&&... args).

template<std::size_t size_, class T> template<class U>
Corrade::Containers::StaticArray<size_, T>::operator ArrayView<U>() noexcept

Convert to ArrayView.

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

template<std::size_t size_, class T> template<class U>
Corrade::Containers::StaticArray<size_, T>::operator ArrayView<const U>() const noexcept

Convert to const ArrayView.

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

template<std::size_t size_, class T>
Corrade::Containers::StaticArray<size_, T>::operator ArrayView<const void>() const noexcept

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> template<class U>
Corrade::Containers::StaticArray<size_, T>::operator StaticArrayView<size_, U>() noexcept

Convert to StaticArrayView.

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

template<std::size_t size_, class T> template<class U>
Corrade::Containers::StaticArray<size_, T>::operator StaticArrayView<size_, const U>() const noexcept

Convert to const StaticArrayView.

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

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

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>
const T* Corrade::Containers::StaticArray<size_, T>::data() const

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::StaticArray<size_, T>::size() const constexpr

Array size.

Equivalent to Size.

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

Whether the array is empty.

Always true (it's not possible to create zero-sized C array).

template<std::size_t size_, class T>
const T* Corrade::Containers::StaticArray<size_, T>::begin() const

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>
const T* Corrade::Containers::StaticArray<size_, 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<std::size_t size_, class T>
const T* Corrade::Containers::StaticArray<size_, T>::end() const

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>
const T* Corrade::Containers::StaticArray<size_, 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<std::size_t size_, class T>
ArrayView<T> Corrade::Containers::StaticArray<size_, T>::slice(T* begin, T* end)

Reference to array slice.

Equivalent to ArrayView::slice().

template<std::size_t size_, class T>
ArrayView<const T> Corrade::Containers::StaticArray<size_, T>::slice(const T* begin, const T* end) const

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>
ArrayView<T> Corrade::Containers::StaticArray<size_, T>::slice(std::size_t begin, std::size_t end)

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>
ArrayView<const T> Corrade::Containers::StaticArray<size_, T>::slice(std::size_t begin, std::size_t end) const

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> template<std::size_t viewSize>
StaticArrayView<viewSize, T> Corrade::Containers::StaticArray<size_, T>::slice(T* begin)

Fixed-size array slice.

Both begin and begin + viewSize are expected to be in range.

template<std::size_t size_, class T> template<std::size_t viewSize>
StaticArrayView<viewSize, const T> Corrade::Containers::StaticArray<size_, T>::slice(const T* begin) const

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> template<std::size_t viewSize>
StaticArrayView<viewSize, T> Corrade::Containers::StaticArray<size_, T>::slice(std::size_t begin)

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> template<std::size_t viewSize>
StaticArrayView<viewSize, const T> Corrade::Containers::StaticArray<size_, T>::slice(std::size_t begin) const

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>
ArrayView<T> Corrade::Containers::StaticArray<size_, T>::prefix(T* end)

Array prefix.

Equivalent to ArrayView::prefix().

template<std::size_t size_, class T>
ArrayView<const T> Corrade::Containers::StaticArray<size_, T>::prefix(const T* end) const

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>
ArrayView<T> Corrade::Containers::StaticArray<size_, T>::prefix(std::size_t end)

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>
ArrayView<const T> Corrade::Containers::StaticArray<size_, T>::prefix(std::size_t end) const

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>
ArrayView<T> Corrade::Containers::StaticArray<size_, T>::suffix(T* begin)

Array suffix.

Equivalent to ArrayView::suffix().

template<std::size_t size_, class T>
ArrayView<const T> Corrade::Containers::StaticArray<size_, T>::suffix(const T* begin) const

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>
ArrayView<T> Corrade::Containers::StaticArray<size_, T>::suffix(std::size_t begin)

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>
ArrayView<const T> Corrade::Containers::StaticArray<size_, T>::suffix(std::size_t begin) const

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> template<std::size_t size, class T>
ArrayView<T> 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> template<std::size_t size, class T>
ArrayView<const T> 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> template<std::size_t size, class T>
StaticArrayView<size, T> 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> template<std::size_t size, class T>
StaticArrayView<size, const T> 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<std::size_t size_, class T> template<class U, std::size_t size, class T>
StaticArrayView<size*sizeof(T)/sizeof(U), U> arrayCast(StaticArray<size, T>& array)

Reinterpret-cast a static array.

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

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

Static array size.

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