| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
Reserve capacity in from_json() object conversion when the target container supports it (#5472) * Reserve capacity in from_json() object conversion when supported The object-to-container from_json() overload filled the target container one element at a time without reserving capacity, even when the target type supports reserve() (e.g. std::unordered_map) and the number of elements is already known. This caused unnecessary rehashing while parsing large objects into such containers. Add a reserve-detecting overload (from_json_object_impl), mirroring the priority_tag-based SFINAE technique already used by the array conversion path (from_json_array_impl), so that reserve(size()) is called up front when available and the loop falls back unchanged otherwise (e.g. for std::map). Fixes #5406 Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Update doc example outputs for new object-conversion iteration order Reserving capacity in from_json()'s object-conversion path before inserting elements changes libstdc++'s std::unordered_map bucket layout, which changes the iteration order used by get__ValueType_const.cpp, get_to.cpp and operator__ValueType.cpp to print the elements of a converted std::unordered_map<std::string, json>. Verified against a clean develop checkout (built with the same GCC/libstdc++ used in CI) that the old order was produced without this PR's change and the new order is produced with it, and that the three affected examples now match their updated expected output byte-for-byte. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Factor out a reserve-dispatch helper instead of duplicating the object from_json loop Addresses review feedback from @gregmarr on PR #5472: the emplace loop no longer needs to exist twice for the reserve/no-reserve cases. A small from_json_object_reserve() overload pair (SFINAE-dispatched on whether reserve() exists, mirroring the priority_tag technique used elsewhere) either calls reserve() or is a no-op; from_json_object_impl() calls it once. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Inline from_json_object_impl into from_json now that it is called only once Addresses review feedback from @gregmarr on PR #5472: with the reserve loop de-duplicated, from_json_object_impl no longer needs to be a separate function that from_json immediately delegates to. Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 7 小时前 | |
Speed up whitespace skipping in the lexer (#5490) * Speed up whitespace skipping in the lexer lexer::skip_whitespace() called get() for every whitespace byte, and get() checks the (almost always false, once past the first character) next_unget flag on every call. skip_whitespace() now reads its first character with get() (needed to honor a pending unget() left over from finishing the previous token, e.g. scan_number() always ungets the character that terminated the number) and every further whitespace character with a new get_ignoring_pending_unget() variant that skips that branch, since nothing in the loop calls unget(). This is a narrower fix than the full contiguous-buffer bulk-skip suggested in the issue (scan a run of whitespace directly in the adapter's buffer and update position counters once per run). That approach depends on bulk-scan adapter infrastructure (supports_bulk_scan/bulk_data()/bulk_skip()) introduced by the open, unmerged parser-performance PR #5283, which this change intentionally does not depend on or replicate. Building new bulk-scan adapter infrastructure from scratch was judged out of scope/riskier than warranted here, so this change is limited to the safe, always-correct improvement of removing redundant per-character bookkeeping from the existing byte-at-a-time loop; full bulk-skipping is left as future work once #5283 (or equivalent adapter support) lands. Line/column/byte-offset bookkeeping is untouched and verified bit-for-bit identical before and after this change, including for pretty-printed (dump(4)) input with embedded newlines. Fixes #5412 Stacked on top of the PR for #5411 (branch issue-5411-lexer-skip-conversion). Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Fix codegen regression in skip_whitespace() from #5490 Benchmarking found the get()/get_ignoring_pending_unget() split in skip_whitespace() made long whitespace runs (e.g. indentation in pretty-printed JSON) 1.75x-3.2x SLOWER instead of faster, reproducible with both Apple Clang and GCC. Root cause: rewriting the loop from a plain do-while into an initial get() followed by a while-loop defeated the compiler's ability to keep the input adapter's read/end pointers in registers across iterations; both compilers instead reloaded them from memory on every character. The function split itself was not the problem (it still fully inlines); the loop's control-flow shape was. The fix keeps the same two-function structure but restores a do-while shape (guarded by an if for the "first char not whitespace" case), which lets both compilers hoist the pointers back into registers, matching or beating pre-#5490 performance. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Share the position-counter bump between get() and get_ignoring_pending_unget() Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Extract current_is_whitespace() to deduplicate skip_whitespace()'s two whitespace checks Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Use a raw string literal for the multi-line error-position test input Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Fix clang-tidy raw-string-literal finding and guard a new test against JSON_NOEXCEPTION The issue #5412 whitespace-skipping test added a check_error() helper that relies on catching json::parse_error to verify the exception message; under JSON_NOEXCEPTION, JSON_THROW aborts instead of throwing, which crashed ci_test_noexceptions (and cascaded into the other ci_cmake_options jobs). Guard the whole section with #if !defined(JSON_NOEXCEPTION), matching the existing pattern used by sibling tests in this file. Also switch one escaped string literal to a raw string literal to satisfy clang-tidy's modernize-raw-string-literal check. Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 7 小时前 | |
Route hand-rolled diagnostic pragmas through Hedley (#5485) * Route hand-rolled diagnostic pragmas through Hedley Several places in the library hand-roll compiler diagnostic suppression with raw `#pragma`/`#ifdef __GNUC__`/`#ifdef __clang__` guards instead of using the Hedley primitives already bundled and used elsewhere (JSON_HEDLEY_DIAGNOSTIC_PUSH/POP, JSON_HEDLEY_PRAGMA, ...). Converted six of the seven listed push/pop pairs to use those primitives instead of raw `#pragma GCC diagnostic`/`#pragma clang diagnostic` text: - include/nlohmann/json.hpp (~3770, ~3863): -Wfloat-equal - include/nlohmann/detail/conversions/to_chars.hpp (~1078): -Wfloat-equal - include/nlohmann/detail/output/binary_writer.hpp (~1844): -Wfloat-equal - include/nlohmann/detail/iterators/iteration_proxy.hpp (~211): -Wmismatched-tags - include/nlohmann/detail/exceptions.hpp (~36): -Wweak-vtables iteration_proxy.hpp did not previously include macro_scope.hpp itself (it only compiled because some other header included earlier in json.hpp happened to pull macro_scope.hpp in first); it now includes it directly like the other detail headers that use Hedley macros, so it is self-contained. Each push/pop pair now uses JSON_HEDLEY_DIAGNOSTIC_PUSH/POP unconditionally (a no-op on compilers that don't need it) and wraps the actual `#pragma ... diagnostic ignored` text in JSON_HEDLEY_PRAGMA so it goes through Hedley's _Pragma()-based emission instead of a raw #pragma line, while keeping the original `#ifdef __GNUC__` / `#if defined(__clang__)` guard around the ignored-pragma itself. Deviation from the issue's suggested transformation: the issue's example replaces the `#ifdef __GNUC__` guard with `#if JSON_HEDLEY_HAS_WARNING("-Wfloat-equal")`. JSON_HEDLEY_HAS_WARNING is implemented purely via Clang's `__has_warning` builtin and evaluates to 0 on real GCC (`#define JSON_HEDLEY_HAS_WARNING(warning) (0)` when `__has_warning` is not defined), so adopting it verbatim would silently stop suppressing -Wfloat-equal on GCC -- a real regression, not just a style change. The existing `#ifdef __GNUC__` / `#if defined(__clang__)` guards were kept for the ignored-pragma to stay behavior-preserving, and only the push/pop/pragma-emission mechanism was routed through Hedley. Two of the seven locations from the issue (the -Wignored-attributes push at the very top of json.hpp and its matching pop after `#include <nlohmann/detail/macro_unscope.hpp>`) were intentionally left unconverted: - The push, at the very top of json.hpp, runs before `detail/macro_scope.hpp` (and therefore hedley.hpp) has been included anywhere in the translation unit, so JSON_HEDLEY_DIAGNOSTIC_PUSH is not yet defined at that point. - The pop runs after `macro_unscope.hpp`, which -- via hedley_undef.hpp -- has already #undef'd every JSON_HEDLEY_* macro (by design, see #5408) precisely so they don't leak to users, so JSON_HEDLEY_DIAGNOSTIC_POP is no longer defined by the time the pop is reached either. Making this one pair work would require either hoisting the ~2000 line vendored hedley.hpp to the very top of the amalgamated single header (a much bigger structural change to single_include than a pure mechanism swap) or special-casing this one pop ahead of the general macro cleanup. Both are riskier than the mechanical, behavior-preserving change requested, so this pair was left as-is. ## Validation - Compiled include/nlohmann/json.hpp and single_include/nlohmann/json.hpp with `-Wall -Wextra -Wfloat-equal -Wmismatched-tags -Wweak-vtables` (clang, which self-identifies as __GNUC__ too): no warnings, same as before the change. - Compiled and ran tests/src/unit-to_chars.cpp, unit-conversions.cpp, unit-iterators1.cpp, unit-iterators2.cpp, and unit-class_parser.cpp against the fixed include/: all pass. - Compiled unit-msgpack.cpp, unit-bjdata.cpp, and unit-ubjson.cpp (which exercise binary_writer.hpp's write_compact_float extensively): all compile cleanly; the vast majority of assertions pass (the only failures are pre-existing environment issues unrelated to this change -- missing generated test-data files, not code correctness). - Ran `make amalgamate`; the single_include diff is limited to exactly the lines touched in include/, with no unrelated reordering. - No real (non-Apple) GCC was available in this environment to test directly; the `_Pragma("GCC diagnostic ...")` text emitted by JSON_HEDLEY_PRAGMA is byte-identical to the prior `#pragma GCC diagnostic ...` text, and the `#ifdef __GNUC__` guard is unchanged, so GCC's behavior is expected to be identical. CI covers the GCC matrix. This PR is stacked on top of #5475 (issue-5408-hedley-undef-leak) since both touch the same files; only the last commit here is new. Fixes #5409. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Guard JSON_HEDLEY_DIAGNOSTIC_PUSH/POP with the same compiler check as the pragma they bracket Addresses review feedback from @gregmarr on PR #5485: the push/pop calls were unconditional, so compilers other than the one the ignored-pragma targets (e.g. MSVC, or GCC where the pair only applies under __clang__) now did a needless push/pop with nothing suppressed in between. Move the existing #ifdef __GNUC__ / #if defined(__clang__) guard to also cover the push/pop, restoring the original zero-overhead behavior on other compilers while still emitting the pragma itself through Hedley. Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 7 小时前 | |
avoid sign extension in char_traits<signed char>::to_int_type (#5336) * avoid sign extension in char_traits<signed char>::to_int_type Signed-off-by: Angadi Yashaswini <angadi@digiscrypt.com> * spell out-of-range signed char constants as negative values (MSVC C4309) Signed-off-by: Angadi Yashaswini <angadi@digiscrypt.com> --------- Signed-off-by: Angadi Yashaswini <angadi@digiscrypt.com> | 1 个月前 | |
Route hand-rolled diagnostic pragmas through Hedley (#5485) * Route hand-rolled diagnostic pragmas through Hedley Several places in the library hand-roll compiler diagnostic suppression with raw `#pragma`/`#ifdef __GNUC__`/`#ifdef __clang__` guards instead of using the Hedley primitives already bundled and used elsewhere (JSON_HEDLEY_DIAGNOSTIC_PUSH/POP, JSON_HEDLEY_PRAGMA, ...). Converted six of the seven listed push/pop pairs to use those primitives instead of raw `#pragma GCC diagnostic`/`#pragma clang diagnostic` text: - include/nlohmann/json.hpp (~3770, ~3863): -Wfloat-equal - include/nlohmann/detail/conversions/to_chars.hpp (~1078): -Wfloat-equal - include/nlohmann/detail/output/binary_writer.hpp (~1844): -Wfloat-equal - include/nlohmann/detail/iterators/iteration_proxy.hpp (~211): -Wmismatched-tags - include/nlohmann/detail/exceptions.hpp (~36): -Wweak-vtables iteration_proxy.hpp did not previously include macro_scope.hpp itself (it only compiled because some other header included earlier in json.hpp happened to pull macro_scope.hpp in first); it now includes it directly like the other detail headers that use Hedley macros, so it is self-contained. Each push/pop pair now uses JSON_HEDLEY_DIAGNOSTIC_PUSH/POP unconditionally (a no-op on compilers that don't need it) and wraps the actual `#pragma ... diagnostic ignored` text in JSON_HEDLEY_PRAGMA so it goes through Hedley's _Pragma()-based emission instead of a raw #pragma line, while keeping the original `#ifdef __GNUC__` / `#if defined(__clang__)` guard around the ignored-pragma itself. Deviation from the issue's suggested transformation: the issue's example replaces the `#ifdef __GNUC__` guard with `#if JSON_HEDLEY_HAS_WARNING("-Wfloat-equal")`. JSON_HEDLEY_HAS_WARNING is implemented purely via Clang's `__has_warning` builtin and evaluates to 0 on real GCC (`#define JSON_HEDLEY_HAS_WARNING(warning) (0)` when `__has_warning` is not defined), so adopting it verbatim would silently stop suppressing -Wfloat-equal on GCC -- a real regression, not just a style change. The existing `#ifdef __GNUC__` / `#if defined(__clang__)` guards were kept for the ignored-pragma to stay behavior-preserving, and only the push/pop/pragma-emission mechanism was routed through Hedley. Two of the seven locations from the issue (the -Wignored-attributes push at the very top of json.hpp and its matching pop after `#include <nlohmann/detail/macro_unscope.hpp>`) were intentionally left unconverted: - The push, at the very top of json.hpp, runs before `detail/macro_scope.hpp` (and therefore hedley.hpp) has been included anywhere in the translation unit, so JSON_HEDLEY_DIAGNOSTIC_PUSH is not yet defined at that point. - The pop runs after `macro_unscope.hpp`, which -- via hedley_undef.hpp -- has already #undef'd every JSON_HEDLEY_* macro (by design, see #5408) precisely so they don't leak to users, so JSON_HEDLEY_DIAGNOSTIC_POP is no longer defined by the time the pop is reached either. Making this one pair work would require either hoisting the ~2000 line vendored hedley.hpp to the very top of the amalgamated single header (a much bigger structural change to single_include than a pure mechanism swap) or special-casing this one pop ahead of the general macro cleanup. Both are riskier than the mechanical, behavior-preserving change requested, so this pair was left as-is. ## Validation - Compiled include/nlohmann/json.hpp and single_include/nlohmann/json.hpp with `-Wall -Wextra -Wfloat-equal -Wmismatched-tags -Wweak-vtables` (clang, which self-identifies as __GNUC__ too): no warnings, same as before the change. - Compiled and ran tests/src/unit-to_chars.cpp, unit-conversions.cpp, unit-iterators1.cpp, unit-iterators2.cpp, and unit-class_parser.cpp against the fixed include/: all pass. - Compiled unit-msgpack.cpp, unit-bjdata.cpp, and unit-ubjson.cpp (which exercise binary_writer.hpp's write_compact_float extensively): all compile cleanly; the vast majority of assertions pass (the only failures are pre-existing environment issues unrelated to this change -- missing generated test-data files, not code correctness). - Ran `make amalgamate`; the single_include diff is limited to exactly the lines touched in include/, with no unrelated reordering. - No real (non-Apple) GCC was available in this environment to test directly; the `_Pragma("GCC diagnostic ...")` text emitted by JSON_HEDLEY_PRAGMA is byte-identical to the prior `#pragma GCC diagnostic ...` text, and the `#ifdef __GNUC__` guard is unchanged, so GCC's behavior is expected to be identical. CI covers the GCC matrix. This PR is stacked on top of #5475 (issue-5408-hedley-undef-leak) since both touch the same files; only the last commit here is new. Fixes #5409. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Guard JSON_HEDLEY_DIAGNOSTIC_PUSH/POP with the same compiler check as the pragma they bracket Addresses review feedback from @gregmarr on PR #5485: the push/pop calls were unconditional, so compilers other than the one the ignored-pragma targets (e.g. MSVC, or GCC where the pair only applies under __clang__) now did a needless push/pop with nothing suppressed in between. Move the existing #ifdef __GNUC__ / #if defined(__clang__) guard to also cover the push/pop, restoring the original zero-overhead behavior on other compilers while still emitting the pragma itself through Hedley. Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 7 小时前 | |
:page_facing_up: adjust year (#5044) Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 8 个月前 | |
Route hand-rolled diagnostic pragmas through Hedley (#5485) * Route hand-rolled diagnostic pragmas through Hedley Several places in the library hand-roll compiler diagnostic suppression with raw `#pragma`/`#ifdef __GNUC__`/`#ifdef __clang__` guards instead of using the Hedley primitives already bundled and used elsewhere (JSON_HEDLEY_DIAGNOSTIC_PUSH/POP, JSON_HEDLEY_PRAGMA, ...). Converted six of the seven listed push/pop pairs to use those primitives instead of raw `#pragma GCC diagnostic`/`#pragma clang diagnostic` text: - include/nlohmann/json.hpp (~3770, ~3863): -Wfloat-equal - include/nlohmann/detail/conversions/to_chars.hpp (~1078): -Wfloat-equal - include/nlohmann/detail/output/binary_writer.hpp (~1844): -Wfloat-equal - include/nlohmann/detail/iterators/iteration_proxy.hpp (~211): -Wmismatched-tags - include/nlohmann/detail/exceptions.hpp (~36): -Wweak-vtables iteration_proxy.hpp did not previously include macro_scope.hpp itself (it only compiled because some other header included earlier in json.hpp happened to pull macro_scope.hpp in first); it now includes it directly like the other detail headers that use Hedley macros, so it is self-contained. Each push/pop pair now uses JSON_HEDLEY_DIAGNOSTIC_PUSH/POP unconditionally (a no-op on compilers that don't need it) and wraps the actual `#pragma ... diagnostic ignored` text in JSON_HEDLEY_PRAGMA so it goes through Hedley's _Pragma()-based emission instead of a raw #pragma line, while keeping the original `#ifdef __GNUC__` / `#if defined(__clang__)` guard around the ignored-pragma itself. Deviation from the issue's suggested transformation: the issue's example replaces the `#ifdef __GNUC__` guard with `#if JSON_HEDLEY_HAS_WARNING("-Wfloat-equal")`. JSON_HEDLEY_HAS_WARNING is implemented purely via Clang's `__has_warning` builtin and evaluates to 0 on real GCC (`#define JSON_HEDLEY_HAS_WARNING(warning) (0)` when `__has_warning` is not defined), so adopting it verbatim would silently stop suppressing -Wfloat-equal on GCC -- a real regression, not just a style change. The existing `#ifdef __GNUC__` / `#if defined(__clang__)` guards were kept for the ignored-pragma to stay behavior-preserving, and only the push/pop/pragma-emission mechanism was routed through Hedley. Two of the seven locations from the issue (the -Wignored-attributes push at the very top of json.hpp and its matching pop after `#include <nlohmann/detail/macro_unscope.hpp>`) were intentionally left unconverted: - The push, at the very top of json.hpp, runs before `detail/macro_scope.hpp` (and therefore hedley.hpp) has been included anywhere in the translation unit, so JSON_HEDLEY_DIAGNOSTIC_PUSH is not yet defined at that point. - The pop runs after `macro_unscope.hpp`, which -- via hedley_undef.hpp -- has already #undef'd every JSON_HEDLEY_* macro (by design, see #5408) precisely so they don't leak to users, so JSON_HEDLEY_DIAGNOSTIC_POP is no longer defined by the time the pop is reached either. Making this one pair work would require either hoisting the ~2000 line vendored hedley.hpp to the very top of the amalgamated single header (a much bigger structural change to single_include than a pure mechanism swap) or special-casing this one pop ahead of the general macro cleanup. Both are riskier than the mechanical, behavior-preserving change requested, so this pair was left as-is. ## Validation - Compiled include/nlohmann/json.hpp and single_include/nlohmann/json.hpp with `-Wall -Wextra -Wfloat-equal -Wmismatched-tags -Wweak-vtables` (clang, which self-identifies as __GNUC__ too): no warnings, same as before the change. - Compiled and ran tests/src/unit-to_chars.cpp, unit-conversions.cpp, unit-iterators1.cpp, unit-iterators2.cpp, and unit-class_parser.cpp against the fixed include/: all pass. - Compiled unit-msgpack.cpp, unit-bjdata.cpp, and unit-ubjson.cpp (which exercise binary_writer.hpp's write_compact_float extensively): all compile cleanly; the vast majority of assertions pass (the only failures are pre-existing environment issues unrelated to this change -- missing generated test-data files, not code correctness). - Ran `make amalgamate`; the single_include diff is limited to exactly the lines touched in include/, with no unrelated reordering. - No real (non-Apple) GCC was available in this environment to test directly; the `_Pragma("GCC diagnostic ...")` text emitted by JSON_HEDLEY_PRAGMA is byte-identical to the prior `#pragma GCC diagnostic ...` text, and the `#ifdef __GNUC__` guard is unchanged, so GCC's behavior is expected to be identical. CI covers the GCC matrix. This PR is stacked on top of #5475 (issue-5408-hedley-undef-leak) since both touch the same files; only the last commit here is new. Fixes #5409. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Guard JSON_HEDLEY_DIAGNOSTIC_PUSH/POP with the same compiler check as the pragma they bracket Addresses review feedback from @gregmarr on PR #5485: the push/pop calls were unconditional, so compilers other than the one the ignored-pragma targets (e.g. MSVC, or GCC where the pair only applies under __clang__) now did a needless push/pop with nothing suppressed in between. Move the existing #ifdef __GNUC__ / #if defined(__clang__) guard to also cover the push/pop, restoring the original zero-overhead behavior on other compilers while still emitting the pragma itself through Hedley. Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 7 小时前 | |
:page_facing_up: adjust year (#5044) Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 8 个月前 | |
Fix ADL leak of nlohmann::detail through basic_json's default base class (#5238) | 2 个月前 | |
Make contains(json_pointer) return false instead of throwing on unrepresentable array-index tokens (#5495) contains(const json_pointer&) is documented to never throw, but a purely numeric reference token that is syntactically a valid array index yet numerically too large to be represented (exceeding size_type's max, or exceeding ULLONG_MAX and causing strtoull() to set errno to ERANGE) made it fall through to array_index(), which throws out_of_range.410/404. Pre-check the token's magnitude the same way array_index() does, but return false instead of throwing, mirroring how the surrounding code already rejects other malformed tokens (leading zero, non-digit characters, "-") without throwing. operator[]/at() are untouched and keep throwing for these inputs. Fixes #5395 Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 7 小时前 | |
:page_facing_up: adjust year (#5044) Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 8 个月前 | |
Fix nvcc CUDA 12.0/12.1 C++20 ranges parse error (#3907) (#5248) * Test ci_cuda_example against a CUDA version matrix at C++20 (#3907) The ci_cuda_example job compiled against the json-ci image's CUDA 11.0 toolkit at cuda_std_11, which cannot exercise #3907 (a c++20 parse error in iteration_proxy.hpp's enable_borrowed_range reported under nvcc). Switch the job to pull official nvidia/cuda devel images directly and matrix across CUDA 11.8-12.6 at cuda_std_20 so CI can empirically confirm which versions are actually affected before any source-level fix is attempted. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Fix nvcc CUDA 12.0/12.1 C++20 ranges parse error (#3907) The diagnostic matrix in this PR confirmed the affected range exactly: nvcc 12.0.1 and 12.1.1 both fail with "expected initializer before '<' token" on iteration_proxy.hpp's enable_borrowed_range variable template specialization at -std=c++20; 12.2.2 and newer already build cleanly. Guard JSON_HAS_RANGES off for that narrow nvcc version range, matching the existing GCC-11/libstdc++ carve-outs in the same ifdef chain, and regenerate single_include accordingly. Broaden the CUDA smoke test to also exercise comparisons (operator==/operator<=>, gated independently by JSON_HAS_THREE_WAY_COMPARISON) and range-based iteration, not just dump()/erase(), so the fix's actual scope is evidenced by CI rather than assumed from the single reported symptom. Have tests/cuda_example/CMakeLists.txt pick the newest C++ standard the detected nvcc version actually supports (20/17/11) instead of hard-requiring C++20, so older toolkits build at a lower standard instead of failing CMake configure outright. This is test-project-local only; the JSON_HAS_RANGES guard is what protects real client code, since a header can't control what -std= flag it's compiled with. Right-size the CI matrix from the 8-version diagnostic sweep down to 11.8.0 (C++17 fallback path) / 12.1.1 (permanent #3907 regression guard) / 12.6.3 (recent coverage), and update the compiler-version table in the quality assurance docs to match. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Fix ci_cuda_example CUDA 11.8 build after C++17 fallback (#3907) The 11.8.0 leg's graceful C++17 fallback (added in the previous commit) worked correctly, but the broadened smoke test used the <=> operator unconditionally, which isn't valid syntax pre-C++20 — nvcc rejected it with "expected an expression" once the CMake logic picked cuda_std_17 for the older toolkit. Gate those two lines behind JSON_HAS_THREE_WAY_COMPARISON like the library itself does internally. Sanity-compiled the file as plain C++ at both -std=c++17 (skips the guarded block) and -std=c++20 (includes it) locally; the actual nvcc build is verified via CI on PR #5248. Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 1 个月前 | |
Add std::format and fmt support (#5224) * :sparkles: add std::format and fmt support Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :recycle: reorganize PR Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :green_heart: fix build Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :green_heart: fix build Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :green_heart: fix build Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 2 个月前 | |
:page_facing_up: adjust year (#5044) Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 8 个月前 | |
:page_facing_up: adjust year (#5044) Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 8 个月前 | |
:page_facing_up: adjust year (#5044) Signed-off-by: Niels Lohmann <mail@nlohmann.me> | 8 个月前 | |
Compare integers with floats exactly instead of widening the integer (#5459) The mixed number arms of JSON_IMPLEMENT_OPERATOR cast the integer to number_float_t before comparing. Past the float's mantissa that cast is lossy: 2^63-2 and 2^63-1 both round to 2^63, so each compares equal to that float while differing from each other. Equality is therefore intransitive and the ordering is not a strict weak ordering, which makes std::sort over such values, or using them as keys in std::set or std::map, undefined behavior. Compare the two exactly instead. The integer's range is a power of two the float represents exactly, so a float outside it is ordered by magnitude alone; inside it, truncating the float is exact, and the integer parts and then any fractional part decide. The helper hands back a pair whose comparison with the original operator reproduces that ordering, which keeps every operator's return type as it was, including partial_ordering for the spaceship. A NaN operand is returned in both members, so NaN stays false for the relational operators and unordered for <=>. Values a float represents exactly still compare equal, so json(1) == json(1.0) is unchanged. Signed-off-by: qatcod <79017227+qatcod@users.noreply.github.com> | 4 天前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 7 小时前 | ||
| 7 小时前 | ||
| 7 小时前 | ||
| 1 个月前 | ||
| 7 小时前 | ||
| 8 个月前 | ||
| 7 小时前 | ||
| 8 个月前 | ||
| 2 个月前 | ||
| 7 小时前 | ||
| 8 个月前 | ||
| 1 个月前 | ||
| 2 个月前 | ||
| 8 个月前 | ||
| 8 个月前 | ||
| 8 个月前 | ||
| 4 天前 |