24 template <__TEMPLATE_AUTO_UINT8 base,
typename T,
25 if_is_integer_t<T> Enable =
true,
26 enable_if_t<2 == base, bool> IsEnabled =
true>
29 template <__TEMPLATE_AUTO_UINT8 base,
typename T,
30 if_is_integer_t<T> Enable =
true,
31 enable_if_t<8 == base, bool> IsEnabled =
true>
34 template <__TEMPLATE_AUTO_UINT8 base,
typename T,
35 if_is_integer_t<T> Enable =
true,
36 enable_if_t<10 == base, bool> IsEnabled =
true>
39 template <__TEMPLATE_AUTO_UINT8 base,
typename T,
40 if_is_integer_t<T> Enable =
true,
41 enable_if_t<16 == base, bool> IsEnabled =
true>
45 if_is_integer_t<T> Enable =
true>
46 extern T power(T b, T n);
48 [[noreturn]]
static inline void unreachable()
53#if defined(_MSC_VER) && !defined(__clang__)
56 __builtin_unreachable();
72 bool strToInt(
char const buffer[], int32_t & dest);
85 bool strToInt(
char const buffer[], uint32_t & dest);
87 bool copyStr(
char buffer[],
size_t bufferSize,
char const * str);
89 bool copyStrUpr(
char buffer[],
size_t bufferSize,
char const * str);
90 bool copyStrLwr(
char buffer[],
size_t bufferSize,
char const * str);
95 template <
bool prfx =
true,
97 if_is_any_unsigned_t<T> Enable =
true>
98 extern int toHex(
char * buff,
size_t len, T number);
109 bool copyStr_P(
char buffer[],
size_t bufferSize,
char const * str);
110 bool copyStr_P(
char buffer[],
size_t bufferSize, __FlashStringHelper
const * str);
112 bool copyStrUpr_P(
char buffer[],
size_t bufferSize,
char const * str);
113 bool copyStrUpr_P(
char buffer[],
size_t bufferSize, __FlashStringHelper
const * str);
115 bool copyStrLwr_P(
char buffer[],
size_t bufferSize,
char const * str);
116 bool copyStrLwr_P(
char buffer[],
size_t bufferSize, __FlashStringHelper
const * str);
128 bool applyTemplate_P(
char buffer[],
size_t bufferSize,
char const * templateStr, int32_t num);
129 bool applyTemplate_P(
char buffer[],
size_t bufferSize, __FlashStringHelper
const * templateStr, int32_t num);
130 bool applyTemplate_P(
char buffer[],
size_t bufferSize,
char const * templateStr, uint32_t num);
131 bool applyTemplate_P(
char buffer[],
size_t bufferSize, __FlashStringHelper
const * templateStr, uint32_t num);
145 bool applyTemplate_P(
char buffer[],
size_t bufferSize,
char const * templateStr,
char const * flashStr);
146 bool applyTemplate_P(
char buffer[],
size_t bufferSize, __FlashStringHelper
const * templateStr,
char const * flashStr);
147 bool applyTemplate_P(
char buffer[],
size_t bufferSize,
char const * templateStr, __FlashStringHelper
const * flashStr);
148 bool applyTemplate_P(
char buffer[],
size_t bufferSize, __FlashStringHelper
const * templateStr, __FlashStringHelper
const * flashStr);
160 bool applyTemplate(
char buffer[],
size_t bufferSize,
char const * templateStr,
char const * str);
161 bool applyTemplate(
char buffer[],
size_t bufferSize, __FlashStringHelper
const * templateStr,
char const * str);
163 extern bool isAlphaNumeric(uint8_t src);
173 template <
typename T>
174 extern void swap(T &a, T &b);
191 template <
typename Tout,
193 if_is_any_number_t<Tout> outEnable =
true,
194 if_is_any_number_t<Tin> inEnable =
true>
197 if __if_constexpr ((is_unsigned_v<Tout>) && (is_signed_v<Tin>))
222 template <
typename Tout,
224 if_is_any_number_t<Tout> outEnable =
true,
225 if_is_any_number_t<Tin> inEnable =
true>
228 if __if_constexpr ((is_unsigned_v<Tout>) && (is_signed_v<Tin>))
248 template <
typename Tout,
251 if_is_any_number_t<Tout> outEnable =
true,
252 if_is_any_number_t<Tin1> in1Enable =
true,
253 if_is_any_number_t<Tin2> in2Enable =
true>
257 if __if_constexpr (is_unsigned_v<Tout>)
260 if __if_constexpr (is_signed_v<Tin1>)
266 if __if_constexpr (is_signed_v<Tin2>)
273 if __if_constexpr ((is_signed_v<Tin1>) && (is_unsigned_v<Tin2>))
279 if (((make_unsigned_t<Tin1>)a) > b)
return b;
282 else if __if_constexpr ((is_unsigned_v<Tin1>) && (is_signed_v<Tin2>))
288 if (a > ((make_unsigned_t<Tin2>)b))
return b;
309 template <
typename Tout,
312 if_is_any_number_t<Tout> outEnable =
true,
313 if_is_any_number_t<Tin1> in1Enable =
true,
314 if_is_any_number_t<Tin2> in2Enable =
true>
318 if __if_constexpr ((is_signed_v<Tin1>) && (is_unsigned_v<Tin2>))
324 if (((make_unsigned_t<Tin1>)a) > b)
return b;
328 else if __if_constexpr ((is_unsigned_v<Tin1>) && (is_signed_v<Tin2>))
334 if (a > (make_unsigned_t<Tin2>(b)))
return b;
356 template <
typename Tout,
358 if_is_any_number_t<Tout> outEnable =
true,
359 if_is_any_number_t<Tin> inEnable =
true>
362 if ((is_unsigned_v<Tout>) && (is_signed_v<Tin>))
383 template <
typename Tout,
385 if_is_any_number_t<Tout> outEnable =
true,
386 if_is_any_number_t<Tin> inEnable =
true>
389 if ((is_unsigned_v<Tout>) && (is_signed_v<Tin>))
417 template <
typename Tin,
421 if_is_any_number_t<Tin> inEnable =
true,
422 if_is_any_number_t<Tmin> minEnable =
true,
423 if_is_any_number_t<Tmax> maxEnable =
true,
424 if_is_any_number_t<Tout> outEnable =
true>
425 inline Tout
clamp(Tin input, Tmin minimum, Tmax maximum)
442 template <
typename Tout,
444 if_is_any_number_t<Tout> outEnable =
true,
445 if_is_any_number_t<Tin> inEnable =
true>
446 inline Tout
clamp(Tin input, Tout minimum, Tout maximum)
448 if __if_constexpr ((is_unsigned_v<Tout>) && (is_signed_v<Tin>))
450 if (input < 0)
return minimum;
453 if (input < minimum)
return minimum;
454 if (input > maximum)
return maximum;
470 template <
typename Tout,
472 if_is_any_number_t<Tout> outEnable =
true,
473 if_is_any_number_t<Tin> inEnable =
true>
474 inline constexpr Tout
clamp_CX(Tin input, Tout minimum, Tout maximum)
476 if ((is_unsigned_v<Tout>) && (is_signed_v<Tin>))
478 if (input < 0)
return minimum;
481 if (input < minimum)
return minimum;
482 if (input > maximum)
return maximum;
500 template <
typename Value, Value LowerLimit, Value UpperLimit,
501 if_is_integer_t<Value> =
true>
505 clamped_value(Value&& value) : value_{
clamp(value, LowerLimit, UpperLimit)} {}
509 constexpr operator Value&() {
return value_; }
510 constexpr operator Value()
const {
return value_; }
516# if defined(NEEDS_UTIL_BITSET_TEMPLATE)
517 template <
typename BitsetType = uint8_t,
518 if_is_integer_t<BitsetType> =
true>
520 typedef uint8_t BitsetType;
534 constexpr reference(reference
const &) =
default;
535 constexpr reference(bitset & __b,
size_t __pos): __bitset(&__b), pos(__pos)
541 reference & operator=(
bool value)
noexcept
543 __bitset->set(this->pos, value);
548 reference & operator=(reference
const & ref)
noexcept
550 __bitset->set(this->pos, ref.__bitset->test(ref.pos));
554 constexpr bool operator~()
const noexcept
556 return !__bitset->test(this->pos);
559 constexpr operator bool()
const noexcept
561 return __bitset->test(this->pos);
565 reference & flip()
noexcept
567 __bitset->set(this->pos, !__bitset->test(this->pos));
580 constexpr bitset(uint8_t size)
noexcept: width(size)
585 constexpr bitset(uint8_t size, BitsetType val)
noexcept: width(size), bits(val)
592 bitset & operator&=(bitset
const & rhs)
noexcept
594 this->bits &= rhs.bits;
599 bitset & operator|=(bitset
const & rhs)
noexcept
601 this->bits |= rhs.bits;
606 bitset & operator^=(bitset
const & rhs)
noexcept
608 this->bits ^= rhs.bits;
613 bitset & operator<<=(
size_t shift)
noexcept
615 this->bits <<= shift;
620 bitset & operator>>=(
size_t shift)
noexcept
622 this->bits >>= shift;
627 bitset operator<<(
size_t shift)
const noexcept
629 return bitset(*
this) <<= shift;
633 bitset operator>>(
size_t shift)
const noexcept
635 return bitset(*
this) >>= shift;
639 bitset & set() noexcept
641 for (
size_t __position = 0; __position < this->width; __position++)
643 this->set(__position,
true);
650 bitset & set(
size_t __position,
bool val =
true)
652 if (__position > this->width)
return *
this;
654 if (val) bits |= (1 << __position);
655 else bits &= ~(1 << __position);
661 bitset & reset() noexcept
668 bitset & reset(
size_t __position)
670 this->set(__position, 0);
673 constexpr bitset operator~() const noexcept;
676 bitset & flip() noexcept
678 for (
size_t __position = 0; __position < this->width; __position++)
680 this->flip(__position);
687 bitset & flip(
size_t __position)
689 this->set(__position, !this->test(__position));
694 constexpr bool operator[](
size_t __position)
const
696 return !!(bits & (1 << __position));
707 size_t count() const noexcept
711 for (
size_t i = 0; i < this->width; i++)
713 bitcount += this->test(i);
719 constexpr size_t size() const noexcept
724 constexpr bool operator==(bitset
const & rhs)
const noexcept
726 return ((this->width == rhs.width) && (this->bits == rhs.bits));
729 constexpr bool test(
size_t __position)
const
731 return !!(bits & (1 << __position));
735 bool all() const noexcept
737 size_t const allbits = ~0U >> ((8 *
sizeof(BitsetType)) - this->width);
738 return !!(bits & allbits);
741 constexpr bool any() const noexcept
746 constexpr bool none() const noexcept