10#ifndef MAXMATRIX_SRC_UTILITY_SPAN_H_
11#define MAXMATRIX_SRC_UTILITY_SPAN_H_
34template <
typename T,
typename Element>
70 constexpr span() =
default;
88 constexpr span(T (&elements)[N])
89 : data_{elements}, size_{N} {}
98 template <
typename Element,
size_t N,
101 : data_{elements.
data()}, size_{N} {}
104 template <
typename Element,
size_t N,
108 : data_{elements.
data()}, size_{N} {}
117 template <
typename Element,
120 : data_{other.
data()}, size_{other.
size()} {}
145 return span{data_, count};
156 return span{data_ + offset, size_ - offset};
The attributes of a later standard, as macros, where the compiler has them.
#define MAXMATRIX_NODISCARD
Marks a function whose result must not be dropped: the compiler warns where it is.
Definition MaxMatrixAttributes.h:37
A C array that knows its size, as std::array, and make_array(), which takes the size from the values.
constexpr span()=default
Makes a span of no elements.
constexpr span(array< Element, N > const &elements)
Makes a span of an array.
Definition span.h:106
size_t size_type
Definition span.h:67
constexpr T & operator[](size_type index) const
Returns the element at index, unchecked.
Definition span.h:133
constexpr span(T *data, size_type size)
Makes a span of size elements from data on.
Definition span.h:78
constexpr span(span< Element > const &other)
Makes a span of what other views, as one of uint8_t into one of uint8_t const.
Definition span.h:119
MAXMATRIX_NODISCARD constexpr span subspan(size_type offset) const
Returns a span of the elements from offset on.
Definition span.h:153
constexpr span(array< Element, N > &elements)
Makes a span of an array.
Definition span.h:100
T element_type
Definition span.h:66
MAXMATRIX_NODISCARD constexpr size_type size() const
Returns the number of elements.
Definition span.h:126
constexpr span(T(&elements)[N])
Makes a span of a C array, as a text in quotes is.
Definition span.h:88
MAXMATRIX_NODISCARD constexpr span first(size_type count) const
Returns a span of the first count elements.
Definition span.h:144
MAXMATRIX_NODISCARD constexpr T * data() const
Returns the address of the first element.
Definition span.h:123
constexpr To * ConvertPointer(To *pointer)
Returns pointer; in a decltype, whether a pointer converts to a To* without a cast,...
Definition span.h:29
decltype(ConvertPointer< T >(static_cast< Element * >(nullptr))) IfPointerConverts
Names a type only if an Element* converts to a T*.
Definition span.h:35
A C array of N elements that knows its size.
Definition array.h:42