#include <Containers/ArrayView.h>
template<std:: size_t size_, class T>
StaticArrayView class
Compile-time-sized array view.
Like ArrayView, but with compile-time size information. Similar to a fixed-size std::
Usage
The general API is similar to what's shown in ArrayView usage docs, except that here are additional compile-time overloads of slice(), sliceSize(), prefix(), suffix(), exceptPrefix() and exceptSuffix().
Public types
-
enum (anonymous) : std::
size_t { Size = size_ } - using Type = T
- Element type.
Constructors, destructors, conversion operators
-
StaticArrayView(std::
nullptr_t = nullptr) constexpr noexcept - Default constructor.
- StaticArrayView(T* data) explicit constexpr noexcept
- Construct a static view on an array.
-
template<class U>StaticArrayView(U(&data)[size_]) constexpr noexcept
- Construct a static view on a fixed-size array.
-
template<class U>StaticArrayView(StaticArrayView<size_, U> view) constexpr noexcept
- Construct a static view on an StaticArrayView.
-
template<class U, class = decltype(Implementation::StaticArrayViewConverter<size_, T, typename std::StaticArrayView(U&& other) constexpr noexcept
decay<U && >::type>::from(std:: declval<U && >()))> - Construct a view on an external type / from an external representation.
-
template<class U, class = decltype(Implementation::StaticArrayViewConverter<size_, T, U>::to(std::operator U() const constexpr
declval<StaticArrayView<size_, T>>()))> - Convert the view to external representation.
- operator bool() const explicit constexpr
- Whether the view is non-empty.
- operator T*() const constexpr
- Conversion to the underlying type.
Public functions
- auto data() const -> T* constexpr
- View data.
-
auto size() const -> std::
size_t constexpr - View size.
- auto empty() const -> bool constexpr
- Whether the view is empty.
- auto begin() const -> T* constexpr
- Pointer to the first element.
- auto cbegin() const -> T* constexpr
- auto end() const -> T* constexpr
- Pointer to (one item after) the last element.
- auto cend() const -> T* constexpr
- auto front() const -> T& constexpr
- First element.
- auto back() const -> T& constexpr
- Last element.
-
auto operator[](std::
size_t i) const -> T& constexpr - Element access.
- auto slice(T* begin, T* end) const -> ArrayView<T> constexpr
- View slice.
-
auto slice(std::
size_t begin, std:: size_t end) const -> ArrayView<T> constexpr -
auto sliceSize(T* begin,
std::
size_t size) const -> ArrayView<T> constexpr - View slice of given size.
-
auto sliceSize(std::
size_t begin, std:: size_t size) const -> ArrayView<T> constexpr -
template<std::auto slice(T* begin) const -> StaticArrayView<size__, T> constexpr
size_t size__> - Fixed-size view slice.
-
template<std::auto slice(std::
size_t viewSize> size_t begin) const -> StaticArrayView<viewSize, T> constexpr -
template<std::auto slice() const -> StaticArrayView<end_ - begin_, T> constexpr
size_t begin_, std:: size_t end_> - Fixed-size view slice.
-
template<std::auto sliceSize() const -> StaticArrayView<size__, T> constexpr
size_t begin_, std:: size_t size__> - Fixed-size view slice of given size.
- auto prefix(T* end) const -> ArrayView<T> constexpr
- View prefix until a pointer.
- auto suffix(T* begin) const -> ArrayView<T> constexpr
- View suffix after a pointer.
-
auto prefix(std::
size_t size) const -> ArrayView<T> constexpr - View on the first
size
items. -
template<std::auto prefix() const -> StaticArrayView<size__, T> constexpr
size_t size__> - Fixed-size view on the first
size_
items. -
auto exceptPrefix(std::
size_t size__) const -> ArrayView<T> constexpr - View except the first
size
items. -
template<std::auto exceptPrefix() const -> StaticArrayView<size_ - size__, T> constexpr
size_t size__> - Fixed-size view except the first
size__
items. -
auto exceptSuffix(std::
size_t size) const -> ArrayView<T> constexpr - View except the last
size
items. -
template<std::auto exceptSuffix() const -> StaticArrayView<size_ - size__, T> constexpr
size_t size__> - Fixed-size view except the last
size__
items.
Enum documentation
template<std:: size_t size_, class T>
enum Death:: Containers:: StaticArrayView<size_, T>:: (anonymous) : std:: size_t
Enumerators | |
---|---|
Size |
Array size |
Function documentation
template<std:: size_t size_, class T>
Death:: Containers:: StaticArrayView<size_, T>:: StaticArrayView(std:: nullptr_t = nullptr) constexpr noexcept
Default constructor.
Creates a nullptr
view. Copy a non-empty StaticArray or StaticArrayView onto the instance to make it useful.
template<std:: size_t size_, class T>
Death:: Containers:: StaticArrayView<size_, T>:: StaticArrayView(T* data) explicit constexpr noexcept
Construct a static view on an array.
Parameters | |
---|---|
data | Data pointer |
The pointer is assumed to contain at least Size elements, but it can't be checked in any way. Use StaticArrayView(U(&)[size_
template<std:: size_t size_, class T>
template<class U>
Death:: Containers:: StaticArrayView<size_, T>:: StaticArrayView(U(&data)[size_]) constexpr noexcept
Construct a static view on a fixed-size array.
Parameters | |
---|---|
data | Fixed-size array |
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>
Death:: Containers:: StaticArrayView<size_, T>:: StaticArrayView(StaticArrayView<size_, U> view) constexpr noexcept
Construct a static view on an 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* Death:: 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* Death:: 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& Death:: Containers:: StaticArrayView<size_, T>:: front() const constexpr
First element.
Expects there is at least one element.
template<std:: size_t size_, class T>
T& Death:: Containers:: StaticArrayView<size_, T>:: back() const constexpr
Last element.
Expects there is at least one element.
template<std:: size_t size_, class T>
T& Death:: Containers:: StaticArrayView<size_, T>:: operator[](std:: size_t i) const constexpr
Element access.
Expects that i
is less than size().
template<std:: size_t size_, class T>
ArrayView<T> Death:: Containers:: StaticArrayView<size_, T>:: slice(T* begin,
T* end) const constexpr
View slice.
Both arguments are expected to be in range.
template<std:: size_t size_, class T>
ArrayView<T> Death:: 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>
ArrayView<T> Death:: Containers:: StaticArrayView<size_, T>:: sliceSize(T* begin,
std:: size_t size) const constexpr
View slice of given size.
Equivalent to data.slice(begin, begin + size)
.
template<std:: size_t size_, class T>
ArrayView<T> Death:: Containers:: StaticArrayView<size_, T>:: 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 size_, class T>
template<std:: size_t size__>
StaticArrayView<size__, T> Death:: Containers:: StaticArrayView<size_, T>:: slice(T* begin) const constexpr
Fixed-size view slice.
Both begin
and begin + size_
are expected to be in range.
template<std:: size_t size_, class T>
template<std:: size_t viewSize>
StaticArrayView<viewSize, T> Death:: 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.
StaticArrayView<end_ - begin_, T> Death:: Containers:: StaticArrayView<size_, T>:: slice() const constexpr
Fixed-size view slice.
Expects (at compile time) that begin_ < end_
and end_
is not larger than Size.
StaticArrayView<size__, T> Death:: Containers:: StaticArrayView<size_, T>:: sliceSize() const constexpr
Fixed-size view slice of given size.
Expects (at compile time) that begin_ + size_
is not larger than Size.
template<std:: size_t size_, class T>
ArrayView<T> Death:: Containers:: StaticArrayView<size_, T>:: prefix(T* end) const constexpr
View prefix until a pointer.
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> Death:: Containers:: StaticArrayView<size_, T>:: suffix(T* begin) const constexpr
View suffix after a pointer.
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> Death:: Containers:: StaticArrayView<size_, T>:: prefix(std:: size_t size) const constexpr
View on the first size
items.
Equivalent to data.slice(0, size)
.
template<std:: size_t size_, class T>
template<std:: size_t size__>
StaticArrayView<size__, T> Death:: Containers:: StaticArrayView<size_, T>:: prefix() const constexpr
Fixed-size view on the first size_
items.
Equivalent to data.slice<0, size_>()
.
template<std:: size_t size_, class T>
ArrayView<T> Death:: Containers:: StaticArrayView<size_, T>:: exceptPrefix(std:: size_t size__) const constexpr
View except the first size
items.
Equivalent to data.slice(size, data.size())
.
template<std:: size_t size_, class T>
template<std:: size_t size__>
StaticArrayView<size_ - size__, T> Death:: Containers:: StaticArrayView<size_, T>:: exceptPrefix() const constexpr
Fixed-size view except the first size__
items.
Equivalent to data.slice<size__, Size>()
.
template<std:: size_t size_, class T>
ArrayView<T> Death:: Containers:: StaticArrayView<size_, T>:: exceptSuffix(std:: size_t size) const constexpr
View except the last size
items.
Equivalent to data.slice(0, data.size() - size)
.
template<std:: size_t size_, class T>
template<std:: size_t size__>
StaticArrayView<size_ - size__, T> Death:: Containers:: StaticArrayView<size_, T>:: exceptSuffix() const constexpr
Fixed-size view except the last size__
items.
Equivalent to data.slice<0, Size - size__>()
.
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::
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::
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 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.
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.