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

Fixed-size array view.

Equivalent to ArrayView, but with compile-time size information. 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);

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.
operator bool() const explicit
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*
Pointer to (one item after) last element.
auto cend() const -> T*
auto slice(T* begin, T* end) const -> ArrayView<T>
Array slice.
auto slice(std::size_t begin, std::size_t end) const -> ArrayView<T>
template<std::size_t viewSize>
auto slice(T* begin) const -> StaticArrayView<viewSize, T>
Fixed-size array slice.
template<std::size_t viewSize>
auto slice(std::size_t begin) const -> StaticArrayView<viewSize, T>
auto prefix(T* end) const -> ArrayView<T>
Array prefix.
auto prefix(std::size_t end) const -> ArrayView<T>
auto suffix(T* begin) const -> ArrayView<T>
Array suffix.
auto suffix(std::size_t begin) const -> ArrayView<T>

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>
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>::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::StaticArrayView<size_, T>::slice(T* begin, T* end) const

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

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

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

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

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::StaticArrayView<size_, T>::suffix(T* begin) const

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

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>
StaticArrayView<size, T> 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> template<std::size_t size, class T>
StaticArrayView<size, T> 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<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];
a = Containers::arrayCast<char>(data); // a.size() == 60