template<std::size_t, class>
Death::Containers::StaticArray class

Compile-time-sized array.

Like Array, but with compile-time size information. Useful as a more featureful alternative to plain C arrays or std::array, especially when it comes to initialization. A non-owning version of this container is a StaticArrayView.

Usage

The StaticArray class provides an access and slicing API similar to Array, which in turn shares the basic workflow patterns with ArrayView, see its usage docs for details. The main difference is that StaticArray doesn't do any heap allocation and thus has no concept of a deleter, and it has additional compile-time-sized overloads of slice(), prefix(), suffix(), exceptPrefix() and exceptSuffix(), mirroring the APIs of StaticArrayView.

Array initialization

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

Usage in constexpr contexts

In order to implement the StaticArray(NoInitT) constructor for arbitrary types, internally the data has to be a union array. That would however lose trivial copyability and possibility to use the type in constexpr contexts, so to solve that, types that have a trivial default constructor or a constructor taking NoInitT use a specialized internal representation without a union. StaticArray of such types is then a constexpr type and is trivially copyable if the underlying type is trivially copyable.

Conversion to array views

Arrays are implicitly convertible to ArrayView / StaticArrayView as described in the following table. The conversion is only allowed if T* is implicitly convertible to U* (or both are the same type) and both have the same size.

Owning array typeNon-owning view type
Array<size, T>ArrayView<size, U>
Array<size, T>ArrayView<size, const U>
const Array<size, T>ArrayView<size, const U>
Array<size, T>ArrayView<U>
Array<size, T>ArrayView<const U>
const Array<size, T>ArrayView<const U>

Public types

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

Constructors, destructors, conversion operators

StaticArray(DefaultInitT) explicit constexpr
Construct a default-initialized array.
StaticArray(ValueInitT) explicit constexpr
Construct a value-initialized array.
StaticArray(NoInitT) explicit
Construct an array without initializing its contents.
template<class ... Args>
StaticArray(DirectInitT, Args && ... args) explicit
Construct a direct-initialized array.
template<class ... Args>
StaticArray(InPlaceInitT, Args && ... args) explicit constexpr
Construct an in-place-initialized array.
template<std::size_t size>
StaticArray(InPlaceInitT, const T(&data)[size]) constexpr
In-place construct an array by copying the elements from a fixed-size array.
template<std::size_t size>
StaticArray(InPlaceInitT, T( && data)[size]) constexpr
In-place construct an array by moving the elements from a fixed-size array.
StaticArray() constexpr
Construct a value-initialized array.
template<class ... Args>
StaticArray(Args && ... args) constexpr
Construct an in-place-initialized array.
template<std::size_t size>
StaticArray(const T(&data)[size]) constexpr
In-place construct an array by copying the elements from a fixed-size array.
template<std::size_t size>
StaticArray(T( && data)[size]) constexpr
In-place construct an array by moving the elements from a fixed-size array.
template<class U, class = decltype(Implementation::StaticArrayViewConverter<size_, T, U>::to(std::declval<StaticArrayView<size_, T>>()))>
operator U()
Convert to external view representation.
template<class U, class = decltype(Implementation::StaticArrayViewConverter<size_, const T, U>::to(std::declval<StaticArrayView<size_, const T>>()))>
operator U() const constexpr
operator bool() const explicit constexpr
Whether the array is non-empty.
operator T*() &
Conversion to array type.
operator const T*() const & constexpr

Public functions

auto data() -> T*
Array data.
auto data() const -> const T* constexpr
auto size() const -> std::size_t constexpr
Array size.
auto empty() const -> bool constexpr
Whether the array is empty.
auto begin() -> T*
Pointer to the first element.
auto begin() const -> const T* constexpr
auto cbegin() const -> const T* constexpr
auto end() -> T*
Pointer to (one item after) the last element.
auto end() const -> const T* constexpr
auto cend() const -> const T* constexpr
auto front() -> T&
First element.
auto front() const -> const T& constexpr
auto back() -> T&
Last element.
auto back() const -> const T& constexpr
auto operator[](std::size_t i) -> T&
Element access.
auto operator[](std::size_t i) const -> const T& constexpr
auto slice(T* begin, T* end) -> ArrayView<T>
View on a slice.
auto slice(const T* begin, const T* end) const -> ArrayView<const T> constexpr
auto slice(std::size_t begin, std::size_t end) -> ArrayView<T> constexpr
auto slice(std::size_t begin, std::size_t end) const -> ArrayView<const T> constexpr
auto sliceSize(T* begin, std::size_t size) -> ArrayView<T>
View on a slice of given size.
auto sliceSize(const T* begin, std::size_t size) const -> ArrayView<const T> constexpr
auto sliceSize(std::size_t begin, std::size_t size) -> ArrayView<T>
auto sliceSize(std::size_t begin, std::size_t size) const -> ArrayView<const T> constexpr
template<std::size_t size__>
auto slice(T* begin) -> StaticArrayView<size__, T>
Fixed-size view on a slice.
template<std::size_t size__>
auto slice(const T* begin) const -> StaticArrayView<size__, const T> constexpr
template<std::size_t size__>
auto slice(std::size_t begin) -> StaticArrayView<size__, T>
template<std::size_t size__>
auto slice(std::size_t begin) const -> StaticArrayView<size__, const T> constexpr
template<std::size_t begin_, std::size_t end_>
auto slice() -> StaticArrayView<end_ - begin_, T>
Fixed-size view on a slice.
template<std::size_t begin_, std::size_t end_>
auto slice() const -> StaticArrayView<end_ - begin_, const T> constexpr
template<std::size_t begin_, std::size_t size__>
auto sliceSize() -> StaticArrayView<size__, T>
Fixed-size view on a slice of given size.
template<std::size_t begin_, std::size_t size__>
auto sliceSize() const -> StaticArrayView<size__, const T> constexpr
auto prefix(T* end) -> ArrayView<T>
View on a prefix until a pointer.
auto prefix(const T* end) const -> ArrayView<const T> constexpr
auto suffix(T* begin) -> ArrayView<T>
View on a suffix after a pointer.
auto suffix(const T* begin) const -> ArrayView<const T> constexpr
auto prefix(std::size_t size) -> ArrayView<T>
View on the first size items.
auto prefix(std::size_t size) const -> ArrayView<const T> constexpr
template<std::size_t size__>
auto prefix() -> StaticArrayView<size__, T>
Fixed-size view on the first size__ items.
template<std::size_t size__>
auto prefix() const -> StaticArrayView<size__, const T> constexpr
auto exceptPrefix(std::size_t size) -> ArrayView<T>
View except the first size items.
auto exceptPrefix(std::size_t size) const -> ArrayView<const T> constexpr
template<std::size_t size__>
auto exceptPrefix() -> StaticArrayView<size_ - size__, T>
Fixed-size view except the first size__ items.
template<std::size_t size__>
auto exceptPrefix() const -> StaticArrayView<size_ - size__, const T> constexpr
auto exceptSuffix(std::size_t size) -> ArrayView<T>
View except the last size items.
auto exceptSuffix(std::size_t size) const -> ArrayView<const T> constexpr
template<std::size_t size__>
auto exceptSuffix() -> StaticArrayView<size_ - size__, T>
Fixed-size view except the last size__ items.
template<std::size_t size__>
auto exceptSuffix() const -> StaticArrayView<size_ - size__, const T> constexpr
template<std::size_t viewSize>
auto prefix() -> StaticArrayView<viewSize, T>
template<std::size_t viewSize>
auto prefix() const -> StaticArrayView<viewSize, const T> constexpr

Enum documentation

template<std::size_t _1, class _2>
enum Death::Containers::StaticArray<_1, _2>::(anonymous) : std::size_t

Enumerators
Size

Array size

Function documentation

template<std::size_t _1, class _2>
Death::Containers::StaticArray<_1, _2>::StaticArray(DefaultInitT) explicit constexpr

Construct a default-initialized array.

Creates array of given size, the contents are default-initialized (i.e., trivial types are not initialized). Because of the differing behavior for trivial types it's better to explicitly use either the StaticArray(ValueInitT) or the StaticArray(NoInitT) variant instead.

template<std::size_t _1, class _2>
Death::Containers::StaticArray<_1, _2>::StaticArray(ValueInitT) explicit constexpr

Construct a value-initialized array.

Creates array of given size, the contents are value-initialized (i.e., trivial types are zero-initialized, default constructor called otherwise). This is the same as StaticArray().

template<std::size_t _1, class _2>
Death::Containers::StaticArray<_1, _2>::StaticArray(NoInitT) explicit

Construct an array without initializing its contents.

Creates array of given size, the contents are not initialized. Useful if you will be overwriting all elements later anyway or if you need to call custom constructors in a way that's not expressible via any other StaticArray constructor.

For trivial types is equivalent to StaticArray(DefaultInitT). For non-trivial types, the class will explicitly call the destructor on all elements — which means that for non-trivial types you're expected to construct all elements using placement new (or for example std::uninitialized_copy()) in order to avoid calling destructors on uninitialized memory.

template<std::size_t _1, class _2> template<class ... Args>
Death::Containers::StaticArray<_1, _2>::StaticArray(DirectInitT, Args && ... args) explicit

Construct a 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 _1, class _2> template<class ... Args>
Death::Containers::StaticArray<_1, _2>::StaticArray(InPlaceInitT, Args && ... args) explicit constexpr

Construct an in-place-initialized array.

The arguments are forwarded to the array constructor. Note that the variadic template means you can't use {} for nested type initializers — see StaticArray(InPlaceInitT, const T(&)[size]) or StaticArray(InPlaceInitT, T(&&)[size]) for an alternative. Same as StaticArray(Args&&... args).

To prevent accidents, compared to regular C array initialization the constructor expects the number of arguments to match the size exactly. I.e., it's not possible to omit a suffix of the array to implicitly value-initialize it.

template<std::size_t _1, class _2> template<std::size_t size>
Death::Containers::StaticArray<_1, _2>::StaticArray(InPlaceInitT, const T(&data)[size]) constexpr

In-place construct an array by copying the elements from a fixed-size array.

Compared to StaticArray(InPlaceInitT, Args&&... args) doesn't require the elements to have explicitly specified type. The array elements are copied to the array constructor, if you have a non-copyable type or want to move the elements, use StaticArray(InPlaceInitT, T(&&)[size]) instead. Same as StaticArray(const T(&)[size]).

To prevent accidents, compared to regular C array initialization the constructor expects the number of arguments to match the size exactly. I.e., it's not possible to omit a suffix of the array to implicitly value-initialize it.

template<std::size_t _1, class _2> template<std::size_t size>
Death::Containers::StaticArray<_1, _2>::StaticArray(InPlaceInitT, T( && data)[size]) constexpr

In-place construct an array by moving the elements from a fixed-size array.

Compared to StaticArray(InPlaceInitT, Args&&... args) doesn't require the elements to have an explicitly specified type. Same as StaticArray(T(&&)[size]).

template<std::size_t _1, class _2>
Death::Containers::StaticArray<_1, _2>::StaticArray() constexpr

Construct a value-initialized array.

Alias to StaticArray(ValueInitT).

template<std::size_t _1, class _2> template<class ... Args>
Death::Containers::StaticArray<_1, _2>::StaticArray(Args && ... args) constexpr

Construct an in-place-initialized array.

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

template<std::size_t _1, class _2> template<std::size_t size>
Death::Containers::StaticArray<_1, _2>::StaticArray(const T(&data)[size]) constexpr

In-place construct an array by copying the elements from a fixed-size array.

Alias to StaticArray(InPlaceInitT, const T(&)[size]).

template<std::size_t _1, class _2> template<std::size_t size>
Death::Containers::StaticArray<_1, _2>::StaticArray(T( && data)[size]) constexpr

In-place construct an array by moving the elements from a fixed-size array.

Alias to StaticArray(InPlaceInitT, T(&&)[size]).

template<std::size_t _1, class _2> template<class U, class = decltype(Implementation::StaticArrayViewConverter<size_, const T, U>::to(std::declval<StaticArrayView<size_, const T>>()))>
Death::Containers::StaticArray<_1, _2>::operator U() const 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 _1, class _2>
Death::Containers::StaticArray<_1, _2>::operator const T*() const & 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 _1, class _2>
const T* Death::Containers::StaticArray<_1, _2>::data() const 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 _1, class _2>
std::size_t Death::Containers::StaticArray<_1, _2>::size() const constexpr

Array size.

Equivalent to Size.

template<std::size_t _1, class _2>
bool Death::Containers::StaticArray<_1, _2>::empty() const constexpr

Whether the array is empty.

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

template<std::size_t _1, class _2>
const T* Death::Containers::StaticArray<_1, _2>::begin() const 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 _1, class _2>
const T* Death::Containers::StaticArray<_1, _2>::cbegin() const 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 _1, class _2>
const T* Death::Containers::StaticArray<_1, _2>::end() const 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 _1, class _2>
const T* Death::Containers::StaticArray<_1, _2>::cend() const 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 _1, class _2>
const T& Death::Containers::StaticArray<_1, _2>::front() const 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 _1, class _2>
const T& Death::Containers::StaticArray<_1, _2>::back() const 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 _1, class _2>
T& Death::Containers::StaticArray<_1, _2>::operator[](std::size_t i)

Element access.

Expects that i is less than size().

template<std::size_t _1, class _2>
const T& Death::Containers::StaticArray<_1, _2>::operator[](std::size_t i) const 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 _1, class _2>
ArrayView<T> Death::Containers::StaticArray<_1, _2>::slice(T* begin, T* end)

View on a slice.

Equivalent to StaticArrayView::slice(T*, T*) const and overloads.

template<std::size_t _1, class _2>
ArrayView<const T> Death::Containers::StaticArray<_1, _2>::slice(const T* begin, const T* end) const 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 _1, class _2>
ArrayView<T> Death::Containers::StaticArray<_1, _2>::slice(std::size_t begin, std::size_t end) 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 _1, class _2>
ArrayView<const T> Death::Containers::StaticArray<_1, _2>::slice(std::size_t begin, std::size_t end) const 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 _1, class _2>
ArrayView<T> Death::Containers::StaticArray<_1, _2>::sliceSize(T* begin, std::size_t size)

View on a slice of given size.

Equivalent to StaticArrayView::sliceSize(T*, std::size_t) const and overloads.

template<std::size_t _1, class _2>
ArrayView<const T> Death::Containers::StaticArray<_1, _2>::sliceSize(const T* begin, std::size_t size) const 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 _1, class _2>
ArrayView<T> Death::Containers::StaticArray<_1, _2>::sliceSize(std::size_t begin, std::size_t size)

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 _1, class _2>
ArrayView<const T> Death::Containers::StaticArray<_1, _2>::sliceSize(std::size_t begin, std::size_t size) const 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 _1, class _2> template<std::size_t size__>
StaticArrayView<size__, T> Death::Containers::StaticArray<_1, _2>::slice(T* begin)

Fixed-size view on a slice.

Equivalent to StaticArrayView::slice(T*) const and overloads.

template<std::size_t _1, class _2> template<std::size_t size__>
StaticArrayView<size__, const T> Death::Containers::StaticArray<_1, _2>::slice(const T* begin) const 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 _1, class _2> template<std::size_t size__>
StaticArrayView<size__, T> Death::Containers::StaticArray<_1, _2>::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 _1, class _2> template<std::size_t size__>
StaticArrayView<size__, const T> Death::Containers::StaticArray<_1, _2>::slice(std::size_t begin) const 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 _1, class _2> template<std::size_t begin_, std::size_t end_>
StaticArrayView<end_ - begin_, T> Death::Containers::StaticArray<_1, _2>::slice()

Fixed-size view on a slice.

Equivalent to StaticArrayView::slice() const.

template<std::size_t _1, class _2> template<std::size_t begin_, std::size_t end_>
StaticArrayView<end_ - begin_, const T> Death::Containers::StaticArray<_1, _2>::slice() const 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 _1, class _2> template<std::size_t begin_, std::size_t size__>
StaticArrayView<size__, T> Death::Containers::StaticArray<_1, _2>::sliceSize()

Fixed-size view on a slice of given size.

Equivalent to StaticArrayView::sliceSize() const.

template<std::size_t _1, class _2> template<std::size_t begin_, std::size_t size__>
StaticArrayView<size__, const T> Death::Containers::StaticArray<_1, _2>::sliceSize() const 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 _1, class _2>
ArrayView<T> Death::Containers::StaticArray<_1, _2>::prefix(T* end)

View on a prefix until a pointer.

Equivalent to StaticArrayView::prefix(T*) const.

template<std::size_t _1, class _2>
ArrayView<const T> Death::Containers::StaticArray<_1, _2>::prefix(const T* end) const 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 _1, class _2>
ArrayView<T> Death::Containers::StaticArray<_1, _2>::suffix(T* begin)

View on a suffix after a pointer.

Equivalent to StaticArrayView::suffix(T*) const.

template<std::size_t _1, class _2>
ArrayView<const T> Death::Containers::StaticArray<_1, _2>::suffix(const T* begin) const 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 _1, class _2>
ArrayView<T> Death::Containers::StaticArray<_1, _2>::prefix(std::size_t size)

View on the first size items.

Equivalent to StaticArrayView::prefix(std::size_t) const.

template<std::size_t _1, class _2>
ArrayView<const T> Death::Containers::StaticArray<_1, _2>::prefix(std::size_t size) const 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 _1, class _2> template<std::size_t size__>
StaticArrayView<size__, T> Death::Containers::StaticArray<_1, _2>::prefix()

Fixed-size view on the first size__ items.

Equivalent to StaticArrayView::prefix() const and overloads.

template<std::size_t _1, class _2> template<std::size_t size__>
StaticArrayView<size__, const T> Death::Containers::StaticArray<_1, _2>::prefix() const 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 _1, class _2>
ArrayView<T> Death::Containers::StaticArray<_1, _2>::exceptPrefix(std::size_t size)

View except the first size items.

Equivalent to StaticArrayView::exceptPrefix(std::size_t) const.

template<std::size_t _1, class _2>
ArrayView<const T> Death::Containers::StaticArray<_1, _2>::exceptPrefix(std::size_t size) const 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 _1, class _2> template<std::size_t size__>
StaticArrayView<size_ - size__, T> Death::Containers::StaticArray<_1, _2>::exceptPrefix()

Fixed-size view except the first size__ items.

Equivalent to StaticArrayView::exceptPrefix() const and overloads.

template<std::size_t _1, class _2> template<std::size_t size__>
StaticArrayView<size_ - size__, const T> Death::Containers::StaticArray<_1, _2>::exceptPrefix() const 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 _1, class _2>
ArrayView<T> Death::Containers::StaticArray<_1, _2>::exceptSuffix(std::size_t size)

View except the last size items.

Equivalent to StaticArrayView::exceptSuffix(std::size_t) const.

template<std::size_t _1, class _2>
ArrayView<const T> Death::Containers::StaticArray<_1, _2>::exceptSuffix(std::size_t size) const 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 _1, class _2> template<std::size_t size__>
StaticArrayView<size_ - size__, T> Death::Containers::StaticArray<_1, _2>::exceptSuffix()

Fixed-size view except the last size__ items.

Equivalent to StaticArrayView::exceptSuffix() const.

template<std::size_t _1, class _2> template<std::size_t size__>
StaticArrayView<size_ - size__, const T> Death::Containers::StaticArray<_1, _2>::exceptSuffix() const 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 _1, class _2> template<std::size_t size, class T>
ArrayView<T> arrayView(StaticArray<size, T>& array) constexpr

Make a view on a StaticArray.

Convenience alternative to converting to an ArrayView explicitly.

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

Make a view on a const StaticArray.

Convenience alternative to converting to an ArrayView explicitly.

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

Make a static view on a StaticArray.

Convenience alternative to converting to an StaticArrayView explicitly.

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

Make a static view on a const StaticArray.

Convenience alternative to converting to an StaticArrayView explicitly.

template<std::size_t _1, class _2> 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 _1, class _2> 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.