Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
adding FASTFLOAT_IF_CONSTEXPR17
  • Loading branch information
lemire committed Mar 9, 2025
commit b29208f93d73863358bdb1ca8d7c29ff3ce28a25
6 changes: 3 additions & 3 deletions include/fast_float/ascii_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ parse_number_string(UC const *p, UC const *pend,
return report_parse_error<UC>(
p, parse_error::missing_integer_or_dot_after_sign);
}
if (basic_json_fmt) {
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
if (!is_integer(*p)) { // a sign must be followed by an integer
return report_parse_error<UC>(p,
parse_error::missing_integer_after_sign);
Expand Down Expand Up @@ -328,7 +328,7 @@ parse_number_string(UC const *p, UC const *pend,
UC const *const end_of_integer_part = p;
int64_t digit_count = int64_t(end_of_integer_part - start_digits);
answer.integer = span<UC const>(start_digits, size_t(digit_count));
if (basic_json_fmt) {
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
// at least 1 digit in integer part, without leading zeros
if (digit_count == 0) {
return report_parse_error<UC>(p, parse_error::no_digits_in_integer_part);
Expand Down Expand Up @@ -357,7 +357,7 @@ parse_number_string(UC const *p, UC const *pend,
answer.fraction = span<UC const>(before, size_t(p - before));
digit_count -= exponent;
}
if (basic_json_fmt) {
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
// at least 1 digit in fractional part
if (has_decimal_point && exponent == 0) {
return report_parse_error<UC>(p,
Expand Down
6 changes: 6 additions & 0 deletions include/fast_float/constexpr_feature_detect.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 0
#endif

#if defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
#define FASTFLOAT_IF_CONSTEXPR17(x) if constexpr (x)
#else
#define FASTFLOAT_IF_CONSTEXPR17(x) if (x)
#endif

// Testing for relevant C++20 constexpr library features
#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED && FASTFLOAT_HAS_BIT_CAST && \
defined(__cpp_lib_constexpr_algorithms) && \
Expand Down