MaxMatrix
Drive chained 8x8 LED dot matrix modules with MAX7219.
Loading...
Searching...
No Matches
max_matrix::span< T > Class Template Reference

A view of size() elements that another owns: a font, a bitmap, a text or a buffer. More...

#include <span.h>

Public Types

using element_type = T
using size_type = size_t

Public Member Functions

constexpr span ()=default
 Makes a span of no elements.
constexpr span (T *data, size_type size)
 Makes a span of size elements from data on.
template<size_t N>
constexpr span (T(&elements)[N])
 Makes a span of a C array, as a text in quotes is.
template<typename Element, size_t N, typename = internal::IfPointerConverts<T, Element>>
constexpr span (array< Element, N > &elements)
 Makes a span of an array.
template<typename Element, size_t N, typename = internal::IfPointerConverts<T, Element const>>
constexpr span (array< Element, N > const &elements)
 Makes a span of an array.
template<typename Element, typename = internal::IfPointerConverts<T, Element>>
constexpr span (span< Element > const &other)
 Makes a span of what other views, as one of uint8_t into one of uint8_t const.
MAXMATRIX_NODISCARD constexpr T * data () const
 Returns the address of the first element.
MAXMATRIX_NODISCARD constexpr size_type size () const
 Returns the number of elements.
constexpr T & operator[] (size_type index) const
 Returns the element at index, unchecked.
MAXMATRIX_NODISCARD constexpr span first (size_type count) const
 Returns a span of the first count elements.
MAXMATRIX_NODISCARD constexpr span subspan (size_type offset) const
 Returns a span of the elements from offset on.

Detailed Description

template<typename T>
class max_matrix::span< T >

A view of size() elements that another owns: a font, a bitmap, a text or a buffer.

It is made of an array, which gives its size, so that a function that takes one cannot read past the end:

matrix.SetText("Hi"); // the span takes the 3 chars of "Hi", its NUL counted

It owns nothing; what it views has to live as long as it is used.

Template Parameters
TThe type of the elements, const for a view that cannot write.
Differs from the standard:
Only a size known at run time, and only data(), size(), the index operator, first() and subspan(): nothing in the library needs more yet.

Member Typedef Documentation

◆ element_type

template<typename T>
using max_matrix::span< T >::element_type = T

The type of an element.

◆ size_type

template<typename T>
using max_matrix::span< T >::size_type = size_t

The type of a size and an index.

Constructor & Destructor Documentation

◆ span() [1/5]

template<typename T>
max_matrix::span< T >::span ( T * data,
size_type size )
inlineconstexpr

Makes a span of size elements from data on.

Parameters
[in]dataThe first element.
[in]sizeThe number of elements.

◆ span() [2/5]

template<typename T>
template<size_t N>
max_matrix::span< T >::span ( T(&) elements[N])
inlineconstexpr

Makes a span of a C array, as a text in quotes is.

Template Parameters
NThe number of elements, which the array says itself.
Parameters
[in]elementsThe array.

◆ span() [3/5]

template<typename T>
template<typename Element, size_t N, typename = internal::IfPointerConverts<T, Element>>
max_matrix::span< T >::span ( array< Element, N > & elements)
inlineconstexpr

Makes a span of an array.

Template Parameters
ElementThe type of its elements, T or T without const.
NThe number of elements, which the array says itself.
Parameters
[in]elementsThe array.

◆ span() [4/5]

template<typename T>
template<typename Element, size_t N, typename = internal::IfPointerConverts<T, Element const>>
max_matrix::span< T >::span ( array< Element, N > const & elements)
inlineconstexpr

Makes a span of an array.

Template Parameters
ElementThe type of its elements, T or T without const.
NThe number of elements, which the array says itself.
Parameters
[in]elementsThe array.

◆ span() [5/5]

template<typename T>
template<typename Element, typename = internal::IfPointerConverts<T, Element>>
max_matrix::span< T >::span ( span< Element > const & other)
inlineconstexpr

Makes a span of what other views, as one of uint8_t into one of uint8_t const.

Template Parameters
ElementThe type of its elements, T without const.
Parameters
[in]otherThe span.

Member Function Documentation

◆ first()

template<typename T>
MAXMATRIX_NODISCARD constexpr span max_matrix::span< T >::first ( size_type count) const
inlineconstexpr

Returns a span of the first count elements.

Parameters
[in]countThe number of elements, up to size().

◆ operator[]()

template<typename T>
T & max_matrix::span< T >::operator[] ( size_type index) const
inlineconstexpr

Returns the element at index, unchecked.

Parameters
[in]indexThe position, from 0; below size().

◆ subspan()

template<typename T>
MAXMATRIX_NODISCARD constexpr span max_matrix::span< T >::subspan ( size_type offset) const
inlineconstexpr

Returns a span of the elements from offset on.

Parameters
[in]offsetThe position of the first, up to size().

The documentation for this class was generated from the following file: