lambda in constructor

This commit is contained in:
Kizarm 2024-08-21 13:42:01 +02:00
parent f653fe0914
commit d849a2d1fb

View file

@ -22,7 +22,8 @@ static constexpr unsigned slen (const char * const str) {
while (str[n]) n++; while (str[n]) n++;
return n; return n;
} }
static constexpr unsigned char compress (const unsigned n) { static const TABLE<unsigned char, array_size (morse_code)> compressed_table
([](const unsigned n) -> auto {
const char * const ptr = morse_code [n]; const char * const ptr = morse_code [n];
const unsigned len = slen (ptr); const unsigned len = slen (ptr);
unsigned char mb = 0u; unsigned char mb = 0u;
@ -32,8 +33,7 @@ static constexpr unsigned char compress (const unsigned n) {
if (ptr [n] == '-') mb |= (1u << n); if (ptr [n] == '-') mb |= (1u << n);
} }
return mb; return mb;
} });
static const TABLE<unsigned char, array_size (morse_code)> compressed_table (compress);
extern void print_morse_table (const TABLE<unsigned char, array_size(morse_code)> & tab); extern void print_morse_table (const TABLE<unsigned char, array_size(morse_code)> & tab);
Morse::Morse(const GpioClass & pin, const unsigned int ms) noexcept : unit (ms), led (pin), Morse::Morse(const GpioClass & pin, const unsigned int ms) noexcept : unit (ms), led (pin),