Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/Convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
#include <string_view>

namespace OpenShock::Convert {
namespace OpenShock::Convert { // TODO: C++23 make this use std::from_chars instead
void FromInt8(int8_t val, std::string& str);
void FromUint8(uint8_t val, std::string& str);
void FromInt16(int16_t val, std::string& str);
Expand All @@ -15,6 +15,7 @@ namespace OpenShock::Convert {
void FromUint32(uint32_t val, std::string& str);
void FromInt64(int64_t val, std::string& str);
void FromUint64(uint64_t val, std::string& str);
void FromSizeT(size_t val, std::string& str);
void FromBool(bool val, std::string& str);
void FromGpioNum(gpio_num_t val, std::string& str);

Expand All @@ -26,6 +27,7 @@ namespace OpenShock::Convert {
bool ToUint32(std::string_view str, uint32_t& val);
bool ToInt64(std::string_view str, int64_t& val);
bool ToUint64(std::string_view str, uint64_t& val);
bool ToSizeT(std::string_view str, size_t& val);
bool ToBool(std::string_view str, bool& val);
bool ToGpioNum(std::string_view str, gpio_num_t& val);
} // namespace OpenShock::Convert
2 changes: 1 addition & 1 deletion include/radio/rmt/internal/Shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OpenShock::Rmt::Internal {
template<size_t N, typename T>
constexpr void EncodeBits(rmt_data_t* sequence, T data, const rmt_data_t& rmtOne, const rmt_data_t& rmtZero)
{
static_assert(std::is_unsigned<T>::value, "T must be an unsigned integer");
static_assert(std::is_unsigned_v<T>, "T must be an unsigned integer");
static_assert(N > 0, "N must be greater than 0");
static_assert(N < std::numeric_limits<T>::digits, "N must be less or equal to the number of bits in T");

Expand Down
18 changes: 3 additions & 15 deletions include/util/DigitCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@

namespace OpenShock::Util {
template<typename T>
constexpr std::size_t Digits10CountMax()
{
static_assert(std::is_integral<T>::value);
uint64_t num = std::numeric_limits<T>::max();

std::size_t digits = std::is_signed<T>::value ? 2 : 1;
while (num >= 10) {
num /= 10;
digits++;
}

return digits;
}
inline constexpr int Digits10CountMax = std::numeric_limits<T>::digits10 + (std::is_signed_v<T> ? 2 : 1);

template<typename T>
constexpr std::size_t Digits10Count(T val)
{
static_assert(std::is_integral<T>::value);
static_assert(std::is_integral_v<T>);

std::size_t digits = 1;

if (std::is_signed<T>::value && val < 0) {
if constexpr (std::is_signed_v<T> && val < 0) {
digits++;
val = -val;
}
Expand Down
Loading
Loading