diff --git a/include/simdjson/compiler_check.h b/include/simdjson/compiler_check.h index bf121dd9a..dba8ab2aa 100644 --- a/include/simdjson/compiler_check.h +++ b/include/simdjson/compiler_check.h @@ -32,4 +32,12 @@ #error simdjson requires a compiler compliant with the C++11 standard #endif +#ifndef SIMDJSON_IF_CONSTEXPR +#if SIMDJSON_CPLUSPLUS17 +#define SIMDJSON_IF_CONSTEXPR if constexpr +#else +#define SIMDJSON_IF_CONSTEXPR if +#endif +#endif + #endif // SIMDJSON_COMPILER_CHECK_H diff --git a/src/generic/stage1/json_structural_indexer.h b/src/generic/stage1/json_structural_indexer.h index 3217ee9e9..471f566b6 100644 --- a/src/generic/stage1/json_structural_indexer.h +++ b/src/generic/stage1/json_structural_indexer.h @@ -62,8 +62,8 @@ public: template simdjson_inline int write_indexes(uint32_t idx, uint64_t& bits) { write_index(idx, bits, START); - if constexpr (N > 1) { - write_indexes(idx, bits); + SIMDJSON_IF_CONSTEXPR (N > 1) { + write_indexes<(N-1>0?START+1:START), (N-1>=0?N-1:1)>(idx, bits); } return START+N; } @@ -71,9 +71,9 @@ public: template simdjson_inline int write_indexes_stepped(uint32_t idx, uint64_t& bits, int cnt) { write_indexes(idx, bits); - if constexpr ((START+STEP) < END) { + SIMDJSON_IF_CONSTEXPR ((START+STEP) < END) { if (simdjson_unlikely((START+STEP) < cnt)) { - write_indexes_stepped(idx, bits, cnt); + write_indexes_stepped<(START+STEP(idx, bits, cnt); } } return ((END-START) % STEP) == 0 ? END : (END-START) - ((END-START) % STEP) + STEP; @@ -107,7 +107,7 @@ public: static constexpr const int STEP_UNTIL = 24; write_indexes_stepped<0, STEP_UNTIL, STEP>(idx, bits, cnt); - if constexpr (STEP_UNTIL < 64) { + SIMDJSON_IF_CONSTEXPR (STEP_UNTIL < 64) { if (simdjson_unlikely(STEP_UNTIL < cnt)) { for (int i=STEP_UNTIL; ierror |= this->prev_incomplete; } -#ifndef SIMDJSON_IF_CONSTEXPR -#if SIMDJSON_CPLUSPLUS17 -#define SIMDJSON_IF_CONSTEXPR if constexpr -#else -#define SIMDJSON_IF_CONSTEXPR if -#endif -#endif - simdjson_inline void check_next_input(const simd8x64& input) { if(simdjson_likely(is_ascii(input))) { this->error |= this->prev_incomplete; diff --git a/tests/dom/integer_tests.cpp b/tests/dom/integer_tests.cpp index 41271a8fb..c9ba1998d 100644 --- a/tests/dom/integer_tests.cpp +++ b/tests/dom/integer_tests.cpp @@ -32,7 +32,7 @@ static bool parse_and_validate(const std::string src, T expected) { const padded_string pstr{src}; simdjson::dom::parser parser; - if constexpr (std::is_same::value) { + SIMDJSON_IF_CONSTEXPR (std::is_same::value) { int64_t actual{}; ASSERT_SUCCESS( parser.parse(pstr)["key"].get(actual) ); std::cout << std::boolalpha << "test: " << (expected == actual) << std::endl;