MaxMatrix
Drive chained 8x8 LED dot matrix modules with MAX7219.
Loading...
Searching...
No Matches
array.h File Reference

A C array that knows its size, as std::array, and make_array(), which takes the size from the values. More...

#include <stddef.h>
#include "MaxMatrixAttributes.h"

Go to the source code of this file.

Classes

struct  max_matrix::array< T, N >
 A C array of N elements that knows its size. More...
struct  max_matrix::internal::ArrayElement< T, Value, Braced >
 Converts a value of make_array() that would narrow, a number, into an element. More...
struct  max_matrix::internal::ArrayElement< T, Value, decltype(T{DeclVal< Value >()})>
 A value of make_array() that becomes an element without narrowing: one of the type, a smaller number, or a char* for a char const*, which the range check could not cast back. More...

Functions

template<typename T>
T max_matrix::internal::ValueOutOfRange ()
 Declared only, so that make_array() stops the build with its name.
template<typename Value>
constexpr bool max_matrix::internal::IsNegative (Value value)
 Returns whether value is below 0, without comparing a type that has no sign with 0, which -Wtype-limits reports.
template<typename T>
T && max_matrix::internal::DeclVal ()
 Declared only: in a decltype, a value of type T, where nothing is evaluated, as std::declval(), which avr-gcc lacks.
template<typename T, typename... Values>
constexpr array< T, sizeof...(Values)> max_matrix::make_array (Values... values)
 Returns an array of T of its values, with the size taken from them.

Detailed Description

A C array that knows its size, as std::array, and make_array(), which takes the size from the values.

Function Documentation

◆ IsNegative()

template<typename Value>
bool max_matrix::internal::IsNegative ( Value value)
constexpr

Returns whether value is below 0, without comparing a type that has no sign with 0, which -Wtype-limits reports.

Parameters
[in]valueThe value.

◆ make_array()

template<typename T, typename... Values>
array< T, sizeof...(Values)> max_matrix::make_array ( Values... values)
constexpr

Returns an array of T of its values, with the size taken from them.

What C++17 deduces from std::array a{...}, and gnu++11 cannot. A font or a bitmap in PROGMEM is written so, its values as MD_MAX72XX writes them:

constexpr auto kHeart PROGMEM{
max_matrix::make_array<uint8_t>(0x0C, 0x1E, 0x3C, 0x1E, 0x0C)};
constexpr array< T, sizeof...(Values)> make_array(Values... values)
Returns an array of T of its values, with the size taken from them.
Definition array.h:185

A value that does not fit T, as 256 or -1 for a uint8_t, stops the build with an error that names ValueOutOfRange, also in a sketch, which Arduino compiles with -Wno-error=narrowing, so that braces would only warn.

Note
For values known when compiling, as a table in PROGMEM has to be made: made at start-up, it would be written to flash, which avr-gcc refuses.
Template Parameters
TThe type of the elements.
Parameters
[in]valuesThe elements, each what becomes a T without narrowing, as a char* for a char const*, or a number that fits one.
Differs from the standard:
std::experimental::make_array<T>() refuses a number of another type even where it fits, so that every value of a font would have to be written as a uint8_t. T cannot be left out.

◆ ValueOutOfRange()

template<typename T>
T max_matrix::internal::ValueOutOfRange ( )

Declared only, so that make_array() stops the build with its name.

A value that does not fit calls it, and a call of a function that is not constexpr ends the evaluation when compiling with an error.