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

Fixed-size array view.

Equivalent to ArrayView, but with compile-time size information. Similar to a fixed-size std::span from C++2a. Convertible from and to ArrayView. Example usage:

Containers::ArrayView<int> data;

// Take elements 7 to 11
Containers::StaticArrayView<5, int> fiveInts = data.slice<5>(7);

// Convert back to ArrayView
Containers::ArrayView<int> fiveInts2 = data; // fiveInts2.size() == 5
Containers::ArrayView<int> threeInts = data.slice(2, 5);

STL compatibility

See ArrayView STL compatibility for more information.

Public types

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

Constructors, destructors, conversion operators

StaticArrayView(std::nullptr_t) constexpr noexcept
Conversion from nullptr
StaticArrayView() constexpr noexcept
Default constructor.
StaticArrayView(T* data) explicit constexpr noexcept
Construct static view on an array.
template<class U>
StaticArrayView(U(&data)[size_]) constexpr noexcept
Construct static view on a fixed-size array.
template<class U>
StaticArrayView(StaticArrayView<size_, U> view) constexpr noexcept
Construct static view on StaticArrayView.
template<class U, class = decltype(Implementation::StaticArrayViewConverter<size_, T, typename std::decay<U && >::type>::from(std::declval<U && >()))>
StaticArrayView(U&& other) constexpr noexcept
Construct a view on an external type / from an external representation.
template<class U, class = decltype(Implementation::StaticArrayViewConverter<size_, T, U>::to(std::declval<StaticArrayView<size_, T>>()))>
operator U() const constexpr
Convert the view to external representation.
operator bool() const explicit constexpr
Whether the array is non-empty.
operator T*() const constexpr
Conversion to array type.

Public functions

auto data() const -> T* constexpr
Array data.
auto size() const -> std::size_t constexpr
Array size.
auto empty() const -> bool constexpr
Whether the array is empty.
auto begin() const -> T* constexpr
Pointer to first element.
auto cbegin() const -> T* constexpr
auto end() const -> T* constexpr
Pointer to (one item after) last element.
auto cend() const -> T* constexpr
auto front() const -> T&
First element.
auto back() const -> T&
Last element.
auto slice(T* begin, T* end) const -> ArrayView<T> constexpr
Array slice.
auto slice(std::size_t begin, std::size_t end) const -> ArrayView<T> constexpr
template<std::size_t viewSize>
auto slice(T* begin) const -> StaticArrayView<viewSize, T> constexpr
Static array slice.
template<std::size_t viewSize>
auto slice(std::size_t begin) const -> StaticArrayView<viewSize, T> constexpr
template<std::size_t begin_, std::size_t end_>
auto slice() const -> StaticArrayView<end_ - begin_, T> constexpr
Static array slice.
auto prefix(T* end) const -> ArrayView<T> constexpr
Array prefix.
auto prefix(std::size_t end) const -> ArrayView<T> constexpr
template<std::size_t end_>
auto prefix() const -> StaticArrayView<end_, T> constexpr
Static array prefix.
auto suffix(T* begin) const -> ArrayView<T> constexpr
Array suffix.
auto suffix(std::size_t begin) const -> ArrayView<T> constexpr
template<std::size_t begin_>
auto suffix() const -> StaticArrayView<size_ - begin_, T> constexpr
Static array suffix.
auto except(std::size_t count) const -> ArrayView<T> constexpr
Array prefix except the last count items.
template<std::size_t count>
auto except() const -> StaticArrayView<size_ - count, T> constexpr
Static array prefix except the last count items.

Enum documentation

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

Enumerators
Size

Array view size

Function documentation

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

Default constructor.

Creates empty view. Copy non-empty StaticArrayView onto the instance to make it useful.

template<std::size_t size_, class T>
Corrade::Containers::StaticArrayView<size_, T>::StaticArrayView(T* data) explicit constexpr noexcept

Construct static view on an array.

Parameters
data Data pointer

template<std::size_t size_, class T> template<class U>
Corrade::Containers::StaticArrayView<size_, T>::StaticArrayView(U(&data)[size_]) constexpr noexcept

Construct static view on a fixed-size array.

Parameters
data Fixed-size array

Enabled only if T* is implicitly convertible to U*. Note that, similarly as with raw pointers, you need to ensure that both types have the same size.

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

Construct static view on 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, class = decltype(Implementation::StaticArrayViewConverter<size_, T, typename std::decay<U && >::type>::from(std::declval<U && >()))>
Corrade::Containers::StaticArrayView<size_, T>::StaticArrayView(U&& other) constexpr noexcept

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

template<std::size_t size_, class T> template<class U, class = decltype(Implementation::StaticArrayViewConverter<size_, T, U>::to(std::declval<StaticArrayView<size_, T>>()))>
Corrade::Containers::StaticArrayView<size_, T>::operator U() const constexpr

Convert the view to external representation.

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

Pointer to first element.

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

Pointer to (one item after) last element.

template<std::size_t size_, class T>
T* Corrade::Containers::StaticArrayView<size_, T>::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 size_, class T>
T& Corrade::Containers::StaticArrayView<size_, T>::front() const

First element.

Expects there is at least one element.

template<std::size_t size_, class T>
T& Corrade::Containers::StaticArrayView<size_, T>::back() const

Last element.

Expects there is at least one element.

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

Array slice.

Both arguments are expected to be in range.

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

Static 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, T> Corrade::Containers::StaticArrayView<size_, T>::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 size_, class T> template<std::size_t begin_, std::size_t end_>
StaticArrayView<end_ - begin_, T> Corrade::Containers::StaticArrayView<size_, T>::slice() const constexpr

Static array slice.

Expects (at compile time) that begin < end_ and end_ is not larger than Size.

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

Array prefix.

Equivalent to data.slice(data.begin(), end). If end is nullptr, returns zero-sized nullptr array.

template<std::size_t size_, class T>
ArrayView<T> Corrade::Containers::StaticArrayView<size_, T>::prefix(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 size_, class T> template<std::size_t end_>
StaticArrayView<end_, T> Corrade::Containers::StaticArrayView<size_, T>::prefix() const constexpr

Static array prefix.

Equivalent to data.slice<0, end_>().

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

Array suffix.

Equivalent to data.slice(begin, data.end()). If begin is nullptr and the original array isn't, returns zero-sized nullptr array.

template<std::size_t size_, class T>
ArrayView<T> Corrade::Containers::StaticArrayView<size_, T>::suffix(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 size_, class T> template<std::size_t begin_>
StaticArrayView<size_ - begin_, T> Corrade::Containers::StaticArrayView<size_, T>::suffix() const constexpr

Static array suffix.

Equivalent to data.slice<begin_, Size>().

template<std::size_t size_, class T>
ArrayView<T> Corrade::Containers::StaticArrayView<size_, T>::except(std::size_t count) const constexpr

Array prefix except the last count items.

Equivalent to data.slice(0, data.size() - count).

template<std::size_t size_, class T> template<std::size_t count>
StaticArrayView<size_ - count, T> Corrade::Containers::StaticArrayView<size_, T>::except() const constexpr

Static array prefix except the last count items.

Equivalent to data.slice<0, Size - count>().

template<std::size_t size_, class T> template<std::size_t size, class T>
StaticArrayView<size, T> 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> template<std::size_t size, class T>
StaticArrayView<size, T> 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> template<std::size_t size, class T>
StaticArrayView<size, T> 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<std::size_t size_, class T> template<class T, class U = decltype(Implementation::ErasedStaticArrayViewConverter<typename std::remove_reference<T && >::type>::from(std::declval<T && >()))>
U staticArrayView(T&& other) constexpr

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

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