From 216d034326d105b0e76d2ea4f3702664e48d15a0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 3 Jan 2024 19:03:42 -0800 Subject: [PATCH] Remove limits dependency --- include/fmt/core.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index c68674706e51c..dd47fdd377ddc 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -8,10 +8,10 @@ #ifndef FMT_CORE_H_ #define FMT_CORE_H_ +#include // CHAR_BIT #include // std::byte #include // std::FILE #include // std::strlen -#include // std::numeric_limits #include // std::string #include // std::enable_if @@ -2166,11 +2166,11 @@ FMT_CONSTEXPR auto parse_nonnegative_int(const Char*& begin, const Char* end, } while (p != end && '0' <= *p && *p <= '9'); auto num_digits = p - begin; begin = p; - if (num_digits <= std::numeric_limits::digits10) - return static_cast(value); + int digits10 = sizeof(int) * CHAR_BIT * 3 / 10; + if (num_digits <= digits10) return static_cast(value); // Check for overflow. - const unsigned max = to_unsigned((std::numeric_limits::max)()); - return num_digits == std::numeric_limits::digits10 + 1 && + unsigned max = INT_MAX; + return num_digits == digits10 + 1 && prev * 10ull + unsigned(p[-1] - '0') <= max ? static_cast(value) : error_value; @@ -2198,9 +2198,8 @@ FMT_CONSTEXPR auto do_parse_arg_id(const Char* begin, const Char* end, Char c = *begin; if (c >= '0' && c <= '9') { int index = 0; - constexpr int max = (std::numeric_limits::max)(); if (c != '0') - index = parse_nonnegative_int(begin, end, max); + index = parse_nonnegative_int(begin, end, INT_MAX); else ++begin; if (begin == end || (*begin != '}' && *begin != ':'))