mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-07 01:06:48 +08:00
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:
parent
bc3f331938
commit
aba93f306f
@ -515,6 +515,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
|
||||
|
||||
UC const *const start_num = p;
|
||||
|
||||
// use SIMD if possible
|
||||
while (p != pend && *p == UC('0')) {
|
||||
++p;
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ using from_chars_result = from_chars_result_t<char>;
|
||||
|
||||
template <typename UC> struct parse_options_t {
|
||||
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) {}
|
||||
|
||||
/** Which number formats are accepted */
|
||||
@ -84,7 +84,7 @@ template <typename UC> struct parse_options_t {
|
||||
/** The character used as decimal point */
|
||||
const UC decimal_point;
|
||||
/** 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>;
|
||||
@ -224,7 +224,7 @@ using parse_options = parse_options_t<char>;
|
||||
|
||||
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
|
||||
return std::is_constant_evaluated();
|
||||
#else
|
||||
@ -1024,6 +1024,8 @@ to_float(
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||
|
||||
template <typename = void> struct space_lut {
|
||||
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,
|
||||
@ -1049,6 +1051,8 @@ template <typename UC> constexpr bool is_space(UC c) {
|
||||
return c < 256 && space_lut<>::value[uint8_t(c)];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <typename UC> static constexpr uint64_t int_cmp_zeros() {
|
||||
static_assert((sizeof(UC) == 1) || (sizeof(UC) == 2) || (sizeof(UC) == 4),
|
||||
"Unsupported character size");
|
||||
|
||||
@ -314,12 +314,15 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
|
||||
first++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (first == last) {
|
||||
answer.ec = std::errc::invalid_argument;
|
||||
answer.ptr = first;
|
||||
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 =
|
||||
parse_number_string<UC>(first, last, options);
|
||||
if (!pns.valid) {
|
||||
@ -369,8 +372,15 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
|
||||
first++;
|
||||
}
|
||||
}
|
||||
#else
|
||||
// We are in parser code with external loop that checks bounds.
|
||||
[[assume((first < last))]];
|
||||
#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;
|
||||
answer.ec = std::errc::invalid_argument;
|
||||
answer.ptr = first;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user