Skip to content

Commit b29208f

Browse files
committed
adding FASTFLOAT_IF_CONSTEXPR17
1 parent 6f0049a commit b29208f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

include/fast_float/ascii_number.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ parse_number_string(UC const *p, UC const *pend,
299299
return report_parse_error<UC>(
300300
p, parse_error::missing_integer_or_dot_after_sign);
301301
}
302-
if (basic_json_fmt) {
302+
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
303303
if (!is_integer(*p)) { // a sign must be followed by an integer
304304
return report_parse_error<UC>(p,
305305
parse_error::missing_integer_after_sign);
@@ -328,7 +328,7 @@ parse_number_string(UC const *p, UC const *pend,
328328
UC const *const end_of_integer_part = p;
329329
int64_t digit_count = int64_t(end_of_integer_part - start_digits);
330330
answer.integer = span<UC const>(start_digits, size_t(digit_count));
331-
if (basic_json_fmt) {
331+
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
332332
// at least 1 digit in integer part, without leading zeros
333333
if (digit_count == 0) {
334334
return report_parse_error<UC>(p, parse_error::no_digits_in_integer_part);
@@ -357,7 +357,7 @@ parse_number_string(UC const *p, UC const *pend,
357357
answer.fraction = span<UC const>(before, size_t(p - before));
358358
digit_count -= exponent;
359359
}
360-
if (basic_json_fmt) {
360+
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
361361
// at least 1 digit in fractional part
362362
if (has_decimal_point && exponent == 0) {
363363
return report_parse_error<UC>(p,

include/fast_float/constexpr_feature_detect.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
#define FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 0
2828
#endif
2929

30+
#if defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
31+
#define FASTFLOAT_IF_CONSTEXPR17(x) if constexpr (x)
32+
#else
33+
#define FASTFLOAT_IF_CONSTEXPR17(x) if (x)
34+
#endif
35+
3036
// Testing for relevant C++20 constexpr library features
3137
#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED && FASTFLOAT_HAS_BIT_CAST && \
3238
defined(__cpp_lib_constexpr_algorithms) && \

0 commit comments

Comments
 (0)