Additional compile time cleanup. When FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN is enabled we assume that we are in parser code with external loop that checks bounds.

Function cpp20_and_in_constexpr() now is really compile time evaluated. TODO fix warnings.
This commit is contained in:
IRainman 2025-03-07 14:51:20 +03:00
parent bc3f331938
commit aba93f306f
3 changed files with 20 additions and 5 deletions

View File

@ -515,6 +515,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
UC const *const start_num = p; UC const *const start_num = p;
// use SIMD if possible
while (p != pend && *p == UC('0')) { while (p != pend && *p == UC('0')) {
++p; ++p;
} }

View File

@ -68,7 +68,7 @@ using from_chars_result = from_chars_result_t<char>;
template <typename UC> struct parse_options_t { template <typename UC> struct parse_options_t {
FASTFLOAT_CONSTEXPR20 explicit parse_options_t(chars_format fmt = chars_format::general, FASTFLOAT_CONSTEXPR20 explicit parse_options_t(chars_format fmt = chars_format::general,
UC dot = UC('.'), unsigned char b = 10) noexcept UC dot = UC('.'), uint8_t b = 10) noexcept
: format(fmt), decimal_point(dot), base(b) {} : format(fmt), decimal_point(dot), base(b) {}
/** Which number formats are accepted */ /** Which number formats are accepted */
@ -84,7 +84,7 @@ template <typename UC> struct parse_options_t {
/** The character used as decimal point */ /** The character used as decimal point */
const UC decimal_point; const UC decimal_point;
/** The base used for integers */ /** The base used for integers */
const unsigned char base; const uint8_t base; /* only allowed from 2 to 36 */
}; };
using parse_options = parse_options_t<char>; using parse_options = parse_options_t<char>;
@ -224,7 +224,7 @@ using parse_options = parse_options_t<char>;
namespace fast_float { namespace fast_float {
fastfloat_really_inline constexpr bool cpp20_and_in_constexpr() noexcept { fastfloat_really_inline FASTFLOAT_CONSTEVAL20 bool cpp20_and_in_constexpr() noexcept {
#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED #if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED
return std::is_constant_evaluated(); return std::is_constant_evaluated();
#else #else
@ -1024,6 +1024,8 @@ to_float(
#endif #endif
} }
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
template <typename = void> struct space_lut { template <typename = void> struct space_lut {
static constexpr bool value[] = { static constexpr bool value[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -1049,6 +1051,8 @@ template <typename UC> constexpr bool is_space(UC c) {
return c < 256 && space_lut<>::value[uint8_t(c)]; return c < 256 && space_lut<>::value[uint8_t(c)];
} }
#endif
template <typename UC> static constexpr uint64_t int_cmp_zeros() { template <typename UC> static constexpr uint64_t int_cmp_zeros() {
static_assert((sizeof(UC) == 1) || (sizeof(UC) == 2) || (sizeof(UC) == 4), static_assert((sizeof(UC) == 1) || (sizeof(UC) == 2) || (sizeof(UC) == 4),
"Unsupported character size"); "Unsupported character size");

View File

@ -314,12 +314,15 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
first++; first++;
} }
} }
#endif
if (first == last) { if (first == last) {
answer.ec = std::errc::invalid_argument; answer.ec = std::errc::invalid_argument;
answer.ptr = first; answer.ptr = first;
return answer; return answer;
} }
#else
// We are in parser code with external loop that checks bounds.
[[assume((first < last))]];
#endif
parsed_number_string_t<UC> const pns = parsed_number_string_t<UC> const pns =
parse_number_string<UC>(first, last, options); parse_number_string<UC>(first, last, options);
if (!pns.valid) { if (!pns.valid) {
@ -369,8 +372,15 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
first++; first++;
} }
} }
#else
// We are in parser code with external loop that checks bounds.
[[assume((first < last))]];
#endif #endif
if (first == last || options.base < 2 || options.base > 36) { if (
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
first == last
#endif
options.base < 2 || options.base > 36) {
from_chars_result_t<UC> answer; from_chars_result_t<UC> answer;
answer.ec = std::errc::invalid_argument; answer.ec = std::errc::invalid_argument;
answer.ptr = first; answer.ptr = first;