diff --git a/.github/workflows/nlohmannunittests.yml b/.github/workflows/nlohmannunittests.yml index 88849d35..795c5eaa 100644 --- a/.github/workflows/nlohmannunittests.yml +++ b/.github/workflows/nlohmannunittests.yml @@ -41,4 +41,4 @@ jobs: bazelisk-cache: true - name: Run Bazel Test - run: bazel test //nlohmann_json/tests/src:all_nlohmann_tests + run: bazel test //nlohmann_json/tests/src:all diff --git a/.vscode/settings.json b/.vscode/settings.json index 47cb9540..899c4f59 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -103,4 +103,9 @@ ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, + "files.associations": { + "type_traits": "cpp", + "cstddef": "cpp", + "functional": "cpp" + }, } diff --git a/.yamlfmt b/.yamlfmt index 25ed669f..4550fec2 100644 --- a/.yamlfmt +++ b/.yamlfmt @@ -7,3 +7,5 @@ exclude: - nlohmann_json/.github/ISSUE_TEMPLATE/bug.yaml - nlohmann_json/docs/mkdocs/mkdocs.yml - nlohmann_json/.clang-tidy + - nlohmann_json/.github + - nlohmann_json/.cirrus.yml diff --git a/nlohmann_json/.cirrus.yml b/nlohmann_json/.cirrus.yml index b2a78390..be633150 100644 --- a/nlohmann_json/.cirrus.yml +++ b/nlohmann_json/.cirrus.yml @@ -3,15 +3,15 @@ arm_container: check_task: check_script: - - wget https://github.com/Kitware/CMake/releases/download/v3.20.2/cmake-3.20.2.tar.gz - - tar xfz cmake-3.20.2.tar.gz - - cd cmake-3.20.2 - - ./configure - - make cmake ctest -j4 - - cd .. - - mkdir build - - cd build - - ../cmake-3.20.2/bin/cmake .. -DJSON_FastTests=ON - - make -j4 - - cd tests - - ../../cmake-3.20.2/bin/ctest -j4 + - wget https://github.com/Kitware/CMake/releases/download/v3.20.2/cmake-3.20.2.tar.gz + - tar xfz cmake-3.20.2.tar.gz + - cd cmake-3.20.2 + - ./configure + - make cmake ctest -j4 + - cd .. + - mkdir build + - cd build + - ../cmake-3.20.2/bin/cmake .. -DJSON_FastTests=ON + - make -j4 + - cd tests + - ../../cmake-3.20.2/bin/ctest -j4 diff --git a/nlohmann_json/.clang-tidy b/nlohmann_json/.clang-tidy index 4587c964..c3a1244c 100644 --- a/nlohmann_json/.clang-tidy +++ b/nlohmann_json/.clang-tidy @@ -1,5 +1,4 @@ # TODO: The first three checks are only removed to get the CI going. They have to be addressed at some point. -# TODO: portability-avoid-pragma-once: should be fixed eventually Checks: '*, @@ -60,7 +59,6 @@ Checks: '*, -modernize-use-std-numbers, -modernize-use-trailing-return-type, -performance-enum-size, - -portability-avoid-pragma-once, -readability-function-cognitive-complexity, -readability-function-size, -readability-identifier-length, diff --git a/nlohmann_json/.github/CONTRIBUTING.md b/nlohmann_json/.github/CONTRIBUTING.md index 5dfb74b5..ad9820fc 100644 --- a/nlohmann_json/.github/CONTRIBUTING.md +++ b/nlohmann_json/.github/CONTRIBUTING.md @@ -1,7 +1,7 @@ # Contribution Guidelines Thank you for your interest in contributing to this project! What began as an exercise to explore the exciting features -of C++11 has evolved into a [widely used](https://json.nlohmann.me/home/customers/) JSON library. I truly appreciate all +of C++11 has evolved into a [widely-used](https://json.nlohmann.me/home/customers/) JSON library. I truly appreciate all the contributions from the community, whether it's proposing features, identifying bugs, or fixing mistakes! To ensure that our collaboration is efficient and effective, please follow these guidelines. @@ -21,7 +21,7 @@ Clearly describe the issue: - If it is a bug, please describe how to **reproduce** it. If possible, attach a _complete example_ which demonstrates the error. Please also state what you **expected** to happen instead of the error. -- If you propose a change or addition, try to give an **example** what the improved code could look like or how to use +- If you propose a change or addition, try to give an **example** how the improved code could look like or how to use it. - If you found a compilation error, please tell us which **compiler** (version and operating system) you used and paste the (relevant part of) the error messages to the ticket. @@ -66,21 +66,21 @@ certification that he or she has the right to submit the patch for inclusion int ### Describe your changes -This library is primarily maintained as a spare-time project. As such, I cannot make any guarantee how quickly changes +This library is primarily maintained as a spare-time project. As such, I can not make any guarantee how quickly changes are merged and released. Therefore, it is very important to make the review as smooth as possible by explaining not only _what_ you changed, but _why_. This rationale can be very valuable down the road when improvements or bugs are discussed years later. -### Reference an existing issue +### Reference existing issues [Link a pull request to an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue) -to clarify that a fix is forthcoming and which issue can be closed after merging. Only a few cases (e.g., fixing typos) -do not require prior discussions. +to clarify that a fix is forthcoming and which issue can be closed after merging. Only few cases (e.g., fixing typos) +don’t require prior discussions. ### Write tests The library has an extensive test suite that currently covers [100 %](https://coveralls.io/github/nlohmann/json) of the -library's code. These tests are crucial to maintain API stability and give future contributors confidence that they do +library's code. These test are crucial to maintain API stability and give future contributors confidence that they do not accidentally break things. As Titus Winters aptly put it: > If you liked it, you should have put a test on it. @@ -118,14 +118,14 @@ exception into account. #### Coverage If test coverage decreases, an automatic warning comment will be posted on the pull request. You can access a code -coverage report as an artifact to the “Ubuntu” workflow. +coverage report as artifact to the “Ubuntu” workflow. ### Update the documentation The [main documentation](https://json.nlohmann.me) of the library is generated from the files [`docs/mkdocs/docs`](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs). This folder contains dedicated pages for [certain features](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/features), a list of -[all exceptions](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs/home/exceptions.md), and +[all exceptions](https://github.com/nlohmann/json/blob/develop/docs/mkdocs/docs/home/exceptions.md), and an [extensive API documentation](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/api) with details on every public API function. @@ -136,7 +136,7 @@ make install_venv -C docs/mkdocs make serve -C docs/mkdocs ``` -The documentation will then be available at . See the documentation of +The documentation will then available at . See the documentation of [mkdocs](https://www.mkdocs.org) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) for more information. @@ -184,8 +184,8 @@ API of the 3.x.y version is broken. This includes: Although these guidelines may seem restrictive, they are essential for maintaining the library’s utility. Breaking changes may be introduced when they are guarded with a feature macro such as -[`JSON_USE_IMPLICIT_CONVERSIONS`](https://json.nlohmann.me/api/macros/json_use_implicit_conversions/) which allows -selectively changing the behavior of the library. In next steps, the current behavior can then be deprecated. Using +[`JSON_USE_IMPLICIT_CONVERSIONS`](https://json.nlohmann.me/api/macros/json_use_implicit_conversions/) which allows to +selectively change the behavior of the library. In next steps, the current behavior can then be deprecated. Using feature macros then allows users to test their code against the library in the next major release. ### Break C++11 language conformance @@ -211,7 +211,7 @@ The following areas really need contribution and are always welcomed: - Extending the **continuous integration** toward more exotic compilers such as Android NDK, Intel's Compiler, or the bleeding-edge versions Clang. - Improving the efficiency of the **JSON parser**. The current parser is implemented as a naive recursive descent parser - with hand-coded string handling. More sophisticated approaches like LALR parsers would be really appreciated. That + with hand coded string handling. More sophisticated approaches like LALR parsers would be really appreciated. That said, parser generators like Bison or ANTLR do not play nice with single-header files -- I really would like to keep the parser inside the `json.hpp` header, and I am not aware of approaches similar to [`re2c`](http://re2c.org) for parsing. diff --git a/nlohmann_json/.github/PULL_REQUEST_TEMPLATE.md b/nlohmann_json/.github/PULL_REQUEST_TEMPLATE.md index 53709532..4bb90e75 100644 --- a/nlohmann_json/.github/PULL_REQUEST_TEMPLATE.md +++ b/nlohmann_json/.github/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,4 @@ -[Describe your pull request here. Please read the text below the line and make sure you follow the checklist.] +[Describe your pull request here. Please read the text below the line, and make sure you follow the checklist.] - [ ] The changes are described in detail, both the what and why. - [ ] If applicable, an [existing issue](https://github.com/nlohmann/json/issues) is referenced. diff --git a/nlohmann_json/.github/config.yml b/nlohmann_json/.github/config.yml index 7aa59307..4e321747 100644 --- a/nlohmann_json/.github/config.yml +++ b/nlohmann_json/.github/config.yml @@ -8,6 +8,7 @@ sentimentBotToxicityThreshold: .7 sentimentBotReplyComment: > Please be sure to review the [code of conduct](https://github.com/nlohmann/json/blob/develop/.github/CODE_OF_CONDUCT.md) and be respectful of other users. cc/ @nlohmann + # Configuration for request-info - https://github.com/behaviorbot/request-info # *Required* Comment to reply with diff --git a/nlohmann_json/.github/external_ci/appveyor.yml b/nlohmann_json/.github/external_ci/appveyor.yml index d99b8e56..5c6b47a3 100644 --- a/nlohmann_json/.github/external_ci/appveyor.yml +++ b/nlohmann_json/.github/external_ci/appveyor.yml @@ -1,4 +1,4 @@ -version: "{build}" +version: '{build}' # only build PRs and commits to develop branch # (see https://help.appveyor.com/discussions/questions/55079-two-builds-per-commit-to-pull-request) diff --git a/nlohmann_json/.github/labeler.yml b/nlohmann_json/.github/labeler.yml index 6b64013a..024d3e6d 100644 --- a/nlohmann_json/.github/labeler.yml +++ b/nlohmann_json/.github/labeler.yml @@ -1,38 +1,38 @@ version: 1 labels: - - label: "documentation" - files: - - "README.md" - - - label: "documentation" - files: - - "docs/.*" - - - label: "tests" - files: - - "tests/.*" - - - label: "CMake" - files: - - ".*CMakeLists.txt" - - - label: "CMake" - files: - - "cmake/.*" - - - label: "CI" - files: - - "github/workflows/.*" - - - label: "CI" - files: - - "github/external_ci/.*" - - - label: "S" - size-below: 10 - - label: "M" - size-above: 9 - size-below: 100 - - label: "L" - size-above: 100 +- label: "documentation" + files: + - "README.md" + +- label: "documentation" + files: + - "docs/.*" + +- label: "tests" + files: + - "tests/.*" + +- label: "CMake" + files: + - ".*CMakeLists.txt" + +- label: "CMake" + files: + - "cmake/.*" + +- label: "CI" + files: + - "github/workflows/.*" + +- label: "CI" + files: + - "github/external_ci/.*" + +- label: "S" + size-below: 10 +- label: "M" + size-above: 9 + size-below: 100 +- label: "L" + size-above: 100 diff --git a/nlohmann_json/.github/workflows/check_amalgamation.yml b/nlohmann_json/.github/workflows/check_amalgamation.yml index 4cd4bbc0..906a5c5b 100644 --- a/nlohmann_json/.github/workflows/check_amalgamation.yml +++ b/nlohmann_json/.github/workflows/check_amalgamation.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit @@ -34,7 +34,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit diff --git a/nlohmann_json/.github/workflows/cifuzz.yml b/nlohmann_json/.github/workflows/cifuzz.yml index 7a5ca506..256d4986 100644 --- a/nlohmann_json/.github/workflows/cifuzz.yml +++ b/nlohmann_json/.github/workflows/cifuzz.yml @@ -8,28 +8,28 @@ jobs: Fuzzing: runs-on: ubuntu-latest steps: - - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 - with: - egress-policy: audit + - name: Harden Runner + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 + with: + egress-policy: audit - - name: Build Fuzzers - id: build - uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@57fe4475324c5506adbfecdcdd2917f65c86ee9e # master - with: - oss-fuzz-project-name: "json" - dry-run: false - language: c++ - - name: Run Fuzzers - uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@57fe4475324c5506adbfecdcdd2917f65c86ee9e # master - with: - oss-fuzz-project-name: "json" - fuzz-seconds: 300 - dry-run: false - language: c++ - - name: Upload Crash - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - if: failure() && steps.build.outcome == 'success' - with: - name: artifacts - path: ./out/artifacts + - name: Build Fuzzers + id: build + uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@57fe4475324c5506adbfecdcdd2917f65c86ee9e # master + with: + oss-fuzz-project-name: 'json' + dry-run: false + language: c++ + - name: Run Fuzzers + uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@57fe4475324c5506adbfecdcdd2917f65c86ee9e # master + with: + oss-fuzz-project-name: 'json' + fuzz-seconds: 300 + dry-run: false + language: c++ + - name: Upload Crash + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + if: failure() && steps.build.outcome == 'success' + with: + name: artifacts + path: ./out/artifacts diff --git a/nlohmann_json/.github/workflows/codeql-analysis.yml b/nlohmann_json/.github/workflows/codeql-analysis.yml index b607a17c..b7af3212 100644 --- a/nlohmann_json/.github/workflows/codeql-analysis.yml +++ b/nlohmann_json/.github/workflows/codeql-analysis.yml @@ -8,9 +8,9 @@ on: - release/* pull_request: schedule: - - cron: "0 19 * * 1" + - cron: '0 19 * * 1' workflow_dispatch: - + concurrency: group: ${{ github.workflow }}-${{ github.ref || github.run_id }} cancel-in-progress: true @@ -20,29 +20,30 @@ permissions: jobs: CodeQL-Build: + runs-on: ubuntu-latest permissions: security-events: write steps: - - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 - with: - egress-policy: audit - - - name: Checkout repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 - with: - languages: c-cpp - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 + - name: Harden Runner + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 + with: + egress-policy: audit + + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@fc7e4a0fa01c3cca5fd6a1fddec5c0740c977aa2 # v3.28.14 + with: + languages: c-cpp + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@fc7e4a0fa01c3cca5fd6a1fddec5c0740c977aa2 # v3.28.14 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@fc7e4a0fa01c3cca5fd6a1fddec5c0740c977aa2 # v3.28.14 diff --git a/nlohmann_json/.github/workflows/comment_check_amalgamation.yml b/nlohmann_json/.github/workflows/comment_check_amalgamation.yml index fc690da4..4308ed10 100644 --- a/nlohmann_json/.github/workflows/comment_check_amalgamation.yml +++ b/nlohmann_json/.github/workflows/comment_check_amalgamation.yml @@ -19,11 +19,11 @@ jobs: pull-requests: write steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit - - name: "Download artifact" + - name: 'Download artifact' uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 with: script: | @@ -44,7 +44,8 @@ jobs: var fs = require('fs'); fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); - run: unzip pr.zip - - name: "Comment on PR" + + - name: 'Comment on PR' uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/nlohmann_json/.github/workflows/dependency-review.yml b/nlohmann_json/.github/workflows/dependency-review.yml index 4f44295f..70f08cee 100644 --- a/nlohmann_json/.github/workflows/dependency-review.yml +++ b/nlohmann_json/.github/workflows/dependency-review.yml @@ -6,7 +6,7 @@ # PRs introducing known-vulnerable packages will be blocked from merging. # # Source repository: https://github.com/actions/dependency-review-action -name: "Dependency Review" +name: 'Dependency Review' on: [pull_request] permissions: @@ -17,11 +17,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit - - name: "Checkout Repository" + - name: 'Checkout Repository' uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: "Dependency Review" - uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1 + - name: 'Dependency Review' + uses: actions/dependency-review-action@ce3cf9537a52e8119d91fd484ab5b8a807627bf8 # v4.6.0 diff --git a/nlohmann_json/.github/workflows/labeler.yml b/nlohmann_json/.github/workflows/labeler.yml index edeb9012..a71bd0f4 100644 --- a/nlohmann_json/.github/workflows/labeler.yml +++ b/nlohmann_json/.github/workflows/labeler.yml @@ -17,10 +17,10 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit - - uses: srvaroa/labeler@e7bef2249506ba9cbbd3ca5cee256abd9f930b04 # master + - uses: srvaroa/labeler@e216fb40e2e6d3b17d90fb1d950f98bee92f65ce # master env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/nlohmann_json/.github/workflows/macos.yml b/nlohmann_json/.github/workflows/macos.yml index 34c63a9a..dc99a2dd 100644 --- a/nlohmann_json/.github/workflows/macos.yml +++ b/nlohmann_json/.github/workflows/macos.yml @@ -17,47 +17,47 @@ permissions: contents: read jobs: - # macos-11 is deprecated - # macos-11: - # runs-on: macos-11 - # strategy: - # matrix: - # xcode: ['11.7', '12.4', '12.5.1', '13.0'] - # env: - # DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer - # - # steps: - # - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - # - name: Run CMake - # run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON - # - name: Build - # run: cmake --build build --parallel 10 - # - name: Test - # run: cd build ; ctest -j 10 --output-on-failure +# macos-11 is deprecated +# macos-11: +# runs-on: macos-11 +# strategy: +# matrix: +# xcode: ['11.7', '12.4', '12.5.1', '13.0'] +# env: +# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer +# +# steps: +# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 +# - name: Run CMake +# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON +# - name: Build +# run: cmake --build build --parallel 10 +# - name: Test +# run: cd build ; ctest -j 10 --output-on-failure - # macos-12 is deprecated (https://github.com/actions/runner-images/issues/10721) - # macos-12: - # runs-on: macos-12 # https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md - # strategy: - # matrix: - # xcode: ['13.1', '13.2.1', '13.3.1', '13.4.1', '14.0', '14.0.1', '14.1'] - # env: - # DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer - # - # steps: - # - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - # - name: Run CMake - # run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON - # - name: Build - # run: cmake --build build --parallel 10 - # - name: Test - # run: cd build ; ctest -j 10 --output-on-failure +# macos-12 is deprecated (https://github.com/actions/runner-images/issues/10721) +# macos-12: +# runs-on: macos-12 # https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md +# strategy: +# matrix: +# xcode: ['13.1', '13.2.1', '13.3.1', '13.4.1', '14.0', '14.0.1', '14.1'] +# env: +# DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer +# +# steps: +# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 +# - name: Run CMake +# run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON +# - name: Build +# run: cmake --build build --parallel 10 +# - name: Test +# run: cd build ; ctest -j 10 --output-on-failure macos-13: runs-on: macos-13 # https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md strategy: matrix: - xcode: ["14.1", "14.2", "14.3", "14.3.1", "15.0.1", "15.1", "15.2"] + xcode: ['14.1', '14.2', '14.3', '14.3.1', '15.0.1', '15.1', '15.2'] env: DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer @@ -74,7 +74,7 @@ jobs: runs-on: macos-14 # https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md strategy: matrix: - xcode: ["15.3", "15.4"] + xcode: ['15.3', '15.4'] env: DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer @@ -91,7 +91,7 @@ jobs: runs-on: macos-15 # https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md strategy: matrix: - xcode: ["16.0", "16.1", "16.2", "16.3"] + xcode: ['16.0', '16.1', '16.2'] env: DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer diff --git a/nlohmann_json/.github/workflows/publish_documentation.yml b/nlohmann_json/.github/workflows/publish_documentation.yml index 21566519..c0e85ab1 100644 --- a/nlohmann_json/.github/workflows/publish_documentation.yml +++ b/nlohmann_json/.github/workflows/publish_documentation.yml @@ -27,7 +27,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit diff --git a/nlohmann_json/.github/workflows/scorecards.yml b/nlohmann_json/.github/workflows/scorecards.yml index ca0f8454..a95e5fa8 100644 --- a/nlohmann_json/.github/workflows/scorecards.yml +++ b/nlohmann_json/.github/workflows/scorecards.yml @@ -10,7 +10,7 @@ on: # To guarantee Maintained check is occasionally updated. See # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained schedule: - - cron: "20 7 * * 2" + - cron: '20 7 * * 2' push: branches: ["develop"] @@ -36,7 +36,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit @@ -46,7 +46,7 @@ jobs: persist-credentials: false - name: "Run analysis" - uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2 + uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # v2.4.1 with: results_file: results.sarif results_format: sarif @@ -76,6 +76,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 + uses: github/codeql-action/upload-sarif@fc7e4a0fa01c3cca5fd6a1fddec5c0740c977aa2 # v3.28.14 with: sarif_file: results.sarif diff --git a/nlohmann_json/.github/workflows/stale.yml b/nlohmann_json/.github/workflows/stale.yml index 49de023e..f00a973d 100644 --- a/nlohmann_json/.github/workflows/stale.yml +++ b/nlohmann_json/.github/workflows/stale.yml @@ -1,7 +1,7 @@ -name: "Comment and close stale issues and PR" +name: 'Comment and close stale issues and PR' on: schedule: - - cron: "0 0 * * *" + - cron: '0 0 * * *' permissions: contents: read @@ -16,18 +16,18 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit - uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0 with: - stale-issue-label: "state: stale" - stale-pr-label: "state: stale" - exempt-issue-labels: "pinned,security" + stale-issue-label: 'state: stale' + stale-pr-label: 'state: stale' + exempt-issue-labels: 'pinned,security' stale-issue-message: 'This issue has been marked as stale because it has been open for 90 days without activity. If this issue is still relevant, please add a comment or remove the "stale" label. Otherwise, it will be closed in 10 days. Thank you for helping us prioritize our work!' - stale-pr-message: "This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!" - close-issue-message: "This issue has been closed after being marked as stale for 10 days without any further activity. If this was done in error or the issue is still relevant, please feel free to reopen it or create a new issue. We appreciate your understanding and contributions." + stale-pr-message: 'This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!' + close-issue-message: 'This issue has been closed after being marked as stale for 10 days without any further activity. If this was done in error or the issue is still relevant, please feel free to reopen it or create a new issue. We appreciate your understanding and contributions.' days-before-stale: 90 days-before-pr-stale: 30 days-before-close: 10 diff --git a/nlohmann_json/.github/workflows/ubuntu.yml b/nlohmann_json/.github/workflows/ubuntu.yml index 831eebf6..87d0d799 100644 --- a/nlohmann_json/.github/workflows/ubuntu.yml +++ b/nlohmann_json/.github/workflows/ubuntu.yml @@ -23,7 +23,7 @@ jobs: steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Get latest CMake and ninja - uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 + uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - name: Build @@ -46,7 +46,7 @@ jobs: target: [ci_test_amalgamation, ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind] steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit @@ -54,7 +54,7 @@ jobs: run: sudo apt-get update ; sudo apt-get install -y valgrind - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Get latest CMake and ninja - uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 + uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - name: Build @@ -71,7 +71,7 @@ jobs: run: apt-get update ; apt-get install -y git clang-tools iwyu unzip - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Get latest CMake and ninja - uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 + uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - name: Build @@ -88,7 +88,7 @@ jobs: run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Get latest CMake and ninja - uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 + uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - name: Build @@ -98,7 +98,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit @@ -143,12 +143,12 @@ jobs: strategy: matrix: # older GCC docker images (4, 5, 6) fail to check out code - compiler: ['7', '8', '9', '10', '11', '12', '13', '14', '15', 'latest'] + compiler: ['7', '8', '9', '10', '11', '12', '13', '14', 'latest'] container: gcc:${{ matrix.compiler }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Get latest CMake and ninja - uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 + uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - name: Build @@ -165,7 +165,7 @@ jobs: run: apt-get update ; apt-get install -y unzip git - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Get latest CMake and ninja - uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 + uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 - name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10 run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV" if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }} @@ -183,7 +183,7 @@ jobs: steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Get latest CMake and ninja - uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 + uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - name: Build @@ -201,7 +201,7 @@ jobs: run: apt-get update ; apt-get install -y git unzip - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Get latest CMake and ninja - uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 + uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0 - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - name: Build with libc++ @@ -221,21 +221,6 @@ jobs: - name: Build run: cmake --build build --target ci_cuda_example - ci_module_cpp20: - strategy: - matrix: - container: ['gcc:latest', 'silkeh/clang:latest'] - runs-on: ubuntu-latest - container: ${{ matrix.container }} - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Get latest CMake and ninja - uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 - - name: Run CMake - run: cmake -S . -B build -DJSON_CI=On - - name: Build - run: cmake --build build --target ci_module_cpp20 - ci_icpc: runs-on: ubuntu-latest container: ghcr.io/nlohmann/json-ci:v2.2.0 @@ -248,24 +233,6 @@ jobs: . /opt/intel/oneapi/setvars.sh cmake --build build --target ci_icpc - ci_emscripten: - runs-on: ubuntu-latest - steps: - - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 - with: - egress-policy: audit - - - name: Install emscripten - uses: mymindstorm/setup-emsdk@v14 - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Get latest CMake and ninja - uses: lukka/get-cmake@6b3e96a9bc9976b8b546346fdd102effedae0ca8 # v4.02 - - name: Run CMake - run: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -GNinja - - name: Build - run: cmake --build build - ci_test_documentation: runs-on: ubuntu-latest strategy: @@ -273,7 +240,7 @@ jobs: target: [ci_test_examples, ci_test_build_documentation] steps: - name: Harden Runner - uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 + uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1 with: egress-policy: audit diff --git a/nlohmann_json/.github/workflows/windows.yml b/nlohmann_json/.github/workflows/windows.yml index 124b089d..4e21d995 100644 --- a/nlohmann_json/.github/workflows/windows.yml +++ b/nlohmann_json/.github/workflows/windows.yml @@ -37,48 +37,69 @@ jobs: - name: Test run: cd build ; ctest -j 10 -C Debug --output-on-failure - msvc: + msvc2019: + runs-on: windows-2019 strategy: matrix: - runs_on: [windows-2019, windows-2022] build_type: [Debug, Release] architecture: [Win32, x64] - std_version: [default, latest] - runs-on: ${{ matrix.runs_on }} + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Run CMake + run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX" + if: matrix.build_type == 'Release' + - name: Run CMake + run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX" + if: matrix.build_type == 'Debug' + - name: Build + run: cmake --build build --config ${{ matrix.build_type }} --parallel 10 + - name: Test + run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure + + msvc2019_latest: + runs-on: windows-2019 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Set generator - id: generator - run: | - if [ "${{ matrix.runs_on }}" = "windows-2019" ]; then - echo "generator=Visual Studio 16 2019" >> $GITHUB_ENV - else - echo "generator=Visual Studio 17 2022" >> $GITHUB_ENV - fi - shell: bash - - name: Set extra CXX_FLAGS for latest std_version - id: cxxflags - run: | - if [ "${{ matrix.std_version }}" = "latest" ]; then - echo "flags=/permissive- /std:c++latest /utf-8 /W4 /WX" >> $GITHUB_ENV - else - echo "flags=/W4 /WX" >> $GITHUB_ENV - fi - shell: bash - - name: Run CMake (Release) - run: cmake -S . -B build -G "$env:generator" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="$env:flags" - if: matrix.build_type == 'Release' - shell: pwsh - - name: Run CMake (Debug) - run: cmake -S . -B build -G "$env:generator" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="$env:flags" - if: matrix.build_type == 'Debug' - shell: pwsh - - name: Build - run: cmake --build build --config ${{ matrix.build_type }} --parallel 10 - - name: Test - run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Run CMake + run: cmake -S . -B build -G "Visual Studio 16 2019" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX" + - name: Build + run: cmake --build build --config Release --parallel 10 + - name: Test + run: cd build ; ctest -j 10 -C Release --output-on-failure + + msvc2022: + runs-on: windows-2022 + strategy: + matrix: + build_type: [Debug, Release] + architecture: [Win32, x64] + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Run CMake + run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX" + if: matrix.build_type == 'Release' + - name: Run CMake + run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX" + if: matrix.build_type == 'Debug' + - name: Build + run: cmake --build build --config ${{ matrix.build_type }} --parallel 10 + - name: Test + run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure + + msvc2022_latest: + runs-on: windows-2022 + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Run CMake + run: cmake -S . -B build -G "Visual Studio 17 2022" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX" + - name: Build + run: cmake --build build --config Release --parallel 10 + - name: Test + run: cd build ; ctest -j 10 -C Release --output-on-failure clang: runs-on: windows-2019 @@ -97,7 +118,7 @@ jobs: - name: Test run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure - clang-cl-12: + clang-cl-11: runs-on: windows-2019 strategy: matrix: diff --git a/nlohmann_json/BUILD.bazel b/nlohmann_json/BUILD.bazel index 49866c2c..de0ff714 100644 --- a/nlohmann_json/BUILD.bazel +++ b/nlohmann_json/BUILD.bazel @@ -69,3 +69,12 @@ cc_library( visibility = ["//visibility:public"], alwayslink = True, ) + +cc_library( + name = "singleheader-json", + hdrs = [ + "single_include/nlohmann/json.hpp", + ], + includes = ["single_include"], + visibility = ["//visibility:public"], +) diff --git a/nlohmann_json/FILES.md b/nlohmann_json/FILES.md index 91326ab6..a7a35f7f 100644 --- a/nlohmann_json/FILES.md +++ b/nlohmann_json/FILES.md @@ -92,7 +92,7 @@ Further documentation: ### `.github/dependabot.yml` -The configuration of [dependabot](https://github.com/dependabot) which ensures the dependencies (GitHub actions and Python packages used in the CI) remain up to date. +The configuration of [dependabot](https://github.com/dependabot) which ensures the dependencies (GitHub actions and Python packages used in the CI) remain up-to-date. Further documentation: @@ -185,7 +185,7 @@ Further documentation: ### `.reuse/dep5` -The file defines the licenses of certain third-party components in the repository. The root `Makefile` contains a target `reuse` that checks for compliance. +The file defines the licenses of certain third-party component in the repository. The root `Makefile` contains a target `reuse` that checks for compliance. Further documentation: @@ -212,7 +212,7 @@ Further information: ### `LICENSES` -A folder that contains every license of all license files (library and third-party code). +A folder that contains every license of all licenses files (library and third-party code). Further documentation: diff --git a/nlohmann_json/README.md b/nlohmann_json/README.md index 8a48d07c..f97afeb4 100644 --- a/nlohmann_json/README.md +++ b/nlohmann_json/README.md @@ -19,7 +19,6 @@ [![Average time to resolve an issue](https://isitmaintained.com/badge/resolution/nlohmann/json.svg)](https://isitmaintained.com/project/nlohmann/json "Average time to resolve an issue") [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/289/badge)](https://bestpractices.coreinfrastructure.org/projects/289) [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/nlohmann/json/badge)](https://scorecard.dev/viewer/?uri=github.com/nlohmann/json) -[![Backup Status](https://app.cloudback.it/badge/nlohmann/json)](https://cloudback.it) [![GitHub Sponsors](https://img.shields.io/badge/GitHub-Sponsors-ff69b4)](https://github.com/sponsors/nlohmann) [![REUSE status](https://api.reuse.software/badge/github.com/nlohmann/json)](https://api.reuse.software/info/github.com/nlohmann/json) [![Discord](https://img.shields.io/discord/1003743314341793913)](https://discord.gg/6mrGXKvX7y) @@ -31,7 +30,7 @@ - [Examples](#examples) - [Read JSON from a file](#read-json-from-a-file) - [Creating `json` objects from JSON literals](#creating-json-objects-from-json-literals) - - [JSON as a first-class data type](#json-as-a-first-class-data-type) + - [JSON as first-class data type](#json-as-first-class-data-type) - [Serialization / Deserialization](#serialization--deserialization) - [STL-like access](#stl-like-access) - [Conversion from STL containers](#conversion-from-stl-containers) @@ -58,7 +57,7 @@ There are myriads of [JSON](https://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals: -- **Intuitive syntax**. In languages such as Python, JSON feels like a first-class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you'll know what I mean. +- **Intuitive syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you'll know what I mean. - **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings. The library is also included in all popular [package managers](https://json.nlohmann.me/integration/package_managers/). @@ -108,7 +107,7 @@ Thanks everyone! :bug: If you found a **bug**, please check the [**FAQ**](https://json.nlohmann.me/home/faq/) if it is a known issue or the result of a design decision. Please also have a look at the [**issue list**](https://github.com/nlohmann/json/issues) before you [**create a new issue**](https://github.com/nlohmann/json/issues/new/choose). Please provide as much information as possible to help us understand and reproduce your issue. -There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for the documentation browsers [Dash](https://kapeli.com/dash), [Velocity](https://velocity.silverlakesoftware.com), and [Zeal](https://zealdocs.org) that contains the full [documentation](https://json.nlohmann.me) as an offline resource. +There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for the documentation browsers [Dash](https://kapeli.com/dash), [Velocity](https://velocity.silverlakesoftware.com), and [Zeal](https://zealdocs.org) that contains the full [documentation](https://json.nlohmann.me) as offline resource. ## Quick reference @@ -137,7 +136,7 @@ There is also a [**docset**](https://github.com/Kapeli/Dash-User-Contributions/t Here are some examples to give you an idea how to use the class. -Besides the examples below, you may want to: +Beside the examples below, you may want to: → Check the [documentation](https://json.nlohmann.me/)\ → Browse the [standalone example files](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/examples)\ @@ -196,7 +195,7 @@ json ex3 = { }; ``` -### JSON as a first-class data type +### JSON as first-class data type Here are some examples to give you an idea how to use the class. @@ -225,13 +224,13 @@ With this library, you could write: // create an empty structure (null) json j; -// add a number stored as double (note the implicit conversion of j to an object) +// add a number that is stored as double (note the implicit conversion of j to an object) j["pi"] = 3.141; -// add a Boolean stored as bool +// add a Boolean that is stored as bool j["happy"] = true; -// add a string stored as std::string +// add a string that is stored as std::string j["name"] = "Niels"; // add another null object by passing nullptr @@ -240,7 +239,7 @@ j["nothing"] = nullptr; // add an object inside the object j["answer"]["everything"] = 42; -// add an array stored as std::vector (using an initializer list) +// add an array that is stored as std::vector (using an initializer list) j["list"] = { 1, 0, 2 }; // add another object (using an initializer list of pairs) @@ -350,7 +349,7 @@ std::cout << j_string << " == " << serialized_string << std::endl; Note the library only supports UTF-8. When you store strings with different encodings in the library, calling [`dump()`](https://json.nlohmann.me/api/basic_json/dump/) may throw an exception unless `json::error_handler_t::replace` or `json::error_handler_t::ignore` are used as error handlers. -#### To/from streams (e.g., files, string streams) +#### To/from streams (e.g. files, string streams) You can also use streams to serialize and deserialize: @@ -383,7 +382,7 @@ Please note that setting the exception bit for `failbit` is inappropriate for th #### Read from iterator range -You can also parse JSON from an iterator range; that is, from any container accessible by iterators whose `value_type` is an integral type of 1, 2, or 4 bytes, which will be interpreted as UTF-8, UTF-16, and UTF-32 respectively. For instance, a `std::vector`, or a `std::list`: +You can also parse JSON from an iterator range; that is, from any container accessible by iterators whose `value_type` is an integral type of 1, 2 or 4 bytes, which will be interpreted as UTF-8, UTF-16 and UTF-32 respectively. For instance, a `std::vector`, or a `std::list`: ```cpp std::vector v = {'t', 'r', 'u', 'e'}; @@ -487,7 +486,7 @@ To implement your own SAX handler, proceed as follows: 2. Create an object of your SAX interface class, e.g. `my_sax`. 3. Call `bool json::sax_parse(input, &my_sax)`; where the first parameter can be any input like a string or an input stream and the second parameter is a pointer to your SAX interface. -Note the `sax_parse` function only returns a `bool` indicating the result of the last executed SAX event. It does not return a `json` value - it is up to you to decide what to do with the SAX events. Furthermore, no exceptions are thrown in case of a parse error -- it is up to you what to do with the exception object passed to your `parse_error` implementation. Internally, the SAX interface is used for the DOM parser (class `json_sax_dom_parser`) as well as the acceptor (`json_sax_acceptor`), see file [`json_sax.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/detail/input/json_sax.hpp). +Note the `sax_parse` function only returns a `bool` indicating the result of the last executed SAX event. It does not return a `json` value - it is up to you to decide what to do with the SAX events. Furthermore, no exceptions are thrown in case of a parse error - it is up to you what to do with the exception object passed to your `parse_error` implementation. Internally, the SAX interface is used for the DOM parser (class `json_sax_dom_parser`) as well as the acceptor (`json_sax_acceptor`), see file [`json_sax.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/detail/input/json_sax.hpp). ### STL-like access @@ -619,7 +618,7 @@ json j_umset(c_umset); // both entries for "one" are used // maybe ["one", "two", "one", "four"] ``` -Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys can construct an `std::string` and whose values can be used to construct JSON values (see examples above) can be used to create a JSON object. Note that in case of multimaps, only one key is used in the JSON object and the value depends on the internal order of the STL container. +Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys can construct an `std::string` and whose values can be used to construct JSON values (see examples above) can be used to create a JSON object. Note that in case of multimaps only one key is used in the JSON object and the value depends on the internal order of the STL container. ```cpp std::map c_map { {"one", 1}, {"two", 2}, {"three", 3} }; @@ -641,7 +640,7 @@ json j_ummap(c_ummap); // only one entry for key "three" is used ### JSON Pointer and JSON Patch -The library supports **JSON Pointer** ([RFC 6901](https://tools.ietf.org/html/rfc6901)) as an alternative means to address structured values. On top of this, **JSON Patch** ([RFC 6902](https://tools.ietf.org/html/rfc6902)) allows describing differences between two JSON values -- effectively allowing patch and diff operations known from Unix. +The library supports **JSON Pointer** ([RFC 6901](https://tools.ietf.org/html/rfc6901)) as alternative means to address structured values. On top of this, **JSON Patch** ([RFC 6902](https://tools.ietf.org/html/rfc6902)) allows describing differences between two JSON values - effectively allowing patch and diff operations known from Unix. ```cpp // a JSON value @@ -874,7 +873,7 @@ namespace ns { This requires a bit more advanced technique. But first, let's see how this conversion mechanism works: -The library uses **JSON Serializers** to convert types to JSON. +The library uses **JSON Serializers** to convert types to json. The default serializer for `nlohmann::json` is `nlohmann::adl_serializer` (ADL means [Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)). It is implemented like this (simplified): @@ -924,7 +923,7 @@ namespace nlohmann { #### How can I use `get()` for non-default constructible/non-copyable types? -There is a way if your type is [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible). You will need to specialize the `adl_serializer` as well, but with a special `from_json` overload: +There is a way, if your type is [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible). You will need to specialize the `adl_serializer` as well, but with a special `from_json` overload: ```cpp struct move_only_type { @@ -1013,7 +1012,7 @@ struct bad_serializer ### Specializing enum conversion -By default, enum values are serialized to JSON as integers. In some cases, this could result in undesired behavior. If an enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be undefined or a different enum value than was originally intended. +By default, enum values are serialized to JSON as integers. In some cases this could result in undesired behavior. If an enum is modified or re-ordered after data has been serialized to JSON, the later de-serialized JSON data may be undefined or a different enum value than was originally intended. It is possible to more precisely specify how a given enum is mapped to and from JSON as shown below: @@ -1169,7 +1168,7 @@ Please note: The code compiles successfully with [Android NDK](https://developer.android.com/ndk/index.html?hl=ml), Revision 9 - 11 (and possibly later) and [CrystaX's Android NDK](https://www.crystax.net/en/android/ndk) version 10. -- For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod` or `strtof`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MinGW, please refer to [this site](https://tehsausage.com/mingw-to-string) and [this discussion](https://github.com/nlohmann/json/issues/136) for information on how to fix this bug. For Android NDK using `APP_STL := gnustl_static`, please refer to [this discussion](https://github.com/nlohmann/json/issues/219). +- For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod` or `strtof`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MinGW, please refer to [this site](https://tehsausage.com/mingw-to-string) and [this discussion](https://github.com/nlohmann/json/issues/136) for information on how to fix this bug. For Android NDK using `APP_STL := gnustl_static`, please refer to [this discussion](https://github.com/nlohmann/json/issues/219). - Unsupported versions of GCC and Clang are rejected by `#error` directives. This can be switched off by defining `JSON_SKIP_UNSUPPORTED_COMPILER_CHECK`. Note that you can expect no support in this case. @@ -1188,7 +1187,7 @@ using json = nlohmann::json; to the files you want to process JSON and set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang). -You can further use file [`include/nlohmann/json_fwd.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/json_fwd.hpp) for forward-declarations. The installation of `json_fwd.hpp` (as part of cmake's install step) can be achieved by setting `-DJSON_MultipleHeaders=ON`. +You can further use file [`include/nlohmann/json_fwd.hpp`](https://github.com/nlohmann/json/blob/develop/include/nlohmann/json_fwd.hpp) for forward-declarations. The installation of json_fwd.hpp (as part of cmake's install step), can be achieved by setting `-DJSON_MultipleHeaders=ON`. ### CMake @@ -1250,7 +1249,7 @@ FetchContent_MakeAvailable(json) target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json) ``` -**Note**: It is recommended to use the URL approach described above, which is supported as of version 3.10.0. See +**Note**: It is recommended to use the URL approach described above which is supported as of version 3.10.0. See for more information. #### Supporting Both @@ -1372,13 +1371,13 @@ I deeply appreciate the help of the following people. 9. [Florian Weber](https://github.com/Florianjw) fixed a bug in and improved the performance of the comparison operators. 10. [Eric Cornelius](https://github.com/EricMCornelius) pointed out a bug in the handling with NaN and infinity values. He also improved the performance of the string escaping. 11. [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums. -12. [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual Studio. +12. [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual studio. 13. [gregmarr](https://github.com/gregmarr) simplified the implementation of reverse iterators and helped with numerous hints and improvements. In particular, he pushed forward the implementation of user-defined types. 14. [Caio Luppi](https://github.com/caiovlp) fixed a bug in the Unicode handling. 15. [dariomt](https://github.com/dariomt) fixed some typos in the examples. 16. [Daniel Frey](https://github.com/d-frey) cleaned up some pointers and implemented exception-safe memory allocation. 17. [Colin Hirsch](https://github.com/ColinH) took care of a small namespace issue. -18. [Huu Nguyen](https://github.com/whoshuu) corrected a variable name in the documentation. +18. [Huu Nguyen](https://github.com/whoshuu) correct a variable name in the documentation. 19. [Silverweed](https://github.com/silverweed) overloaded `parse()` to accept an rvalue reference. 20. [dariomt](https://github.com/dariomt) fixed a subtlety in MSVC type support and implemented the `get_ref()` function to get a reference to stored values. 21. [ZahlGraf](https://github.com/ZahlGraf) added a workaround that allows compilation using Android NDK. @@ -1413,7 +1412,7 @@ I deeply appreciate the help of the following people. 50. [Jared Grubb](https://github.com/jaredgrubb) silenced a nasty documentation warning. 51. [Yixin Zhang](https://github.com/qwename) fixed an integer overflow check. 52. [Bosswestfalen](https://github.com/Bosswestfalen) merged two iterator classes into a smaller one. -53. [Daniel599](https://github.com/Daniel599) helped to get Travis to execute the tests with Clang's sanitizers. +53. [Daniel599](https://github.com/Daniel599) helped to get Travis execute the tests with Clang's sanitizers. 54. [Jonathan Lee](https://github.com/vjon) fixed an example in the README file. 55. [gnzlbg](https://github.com/gnzlbg) supported the implementation of user-defined types. 56. [Alexej Harm](https://github.com/qis) helped to get the user-defined types working with Visual Studio. @@ -1434,7 +1433,7 @@ I deeply appreciate the help of the following people. 71. [Vincent Thiery](https://github.com/vthiery) maintains a package for the Conan package manager. 72. [Steffen](https://github.com/koemeet) fixed a potential issue with MSVC and `std::min`. 73. [Mike Tzou](https://github.com/Chocobo1) fixed some typos. -74. [amrcode](https://github.com/amrcode) noted misleading documentation about comparison of floats. +74. [amrcode](https://github.com/amrcode) noted a misleading documentation about comparison of floats. 75. [Oleg Endo](https://github.com/olegendo) reduced the memory consumption by replacing `` with ``. 76. [dan-42](https://github.com/dan-42) cleaned up the CMake files to simplify including/reusing of the library. 77. [Nikita Ofitserov](https://github.com/himikof) allowed for moving values from initializer lists. @@ -1461,13 +1460,13 @@ I deeply appreciate the help of the following people. 98. [Vadim Evard](https://github.com/Pipeliner) fixed a Markdown issue in the README. 99. [zerodefect](https://github.com/zerodefect) fixed a compiler warning. 100. [Kert](https://github.com/kaidokert) allowed to template the string type in the serialization and added the possibility to override the exceptional behavior. -101. [mark-99](https://github.com/mark-99) helped fix an ICC error. +101. [mark-99](https://github.com/mark-99) helped fixing an ICC error. 102. [Patrik Huber](https://github.com/patrikhuber) fixed links in the README file. 103. [johnfb](https://github.com/johnfb) found a bug in the implementation of CBOR's indefinite length strings. 104. [Paul Fultz II](https://github.com/pfultz2) added a note on the cget package manager. 105. [Wilson Lin](https://github.com/wla80) made the integration section of the README more concise. 106. [RalfBielig](https://github.com/ralfbielig) detected and fixed a memory leak in the parser callback. -107. [agrianius](https://github.com/agrianius) allowed dumping JSON to an alternative string type. +107. [agrianius](https://github.com/agrianius) allowed to dump JSON to an alternative string type. 108. [Kevin Tonon](https://github.com/ktonon) overworked the C++11 compiler checks in CMake. 109. [Axel Huebl](https://github.com/ax3l) simplified a CMake check and added support for the [Spack package manager](https://spack.io). 110. [Carlos O'Ryan](https://github.com/coryan) fixed a typo. @@ -1516,12 +1515,12 @@ I deeply appreciate the help of the following people. 153. [Ivor Wanders](https://github.com/iwanders) helped to reduce the CMake requirement to version 3.1. 154. [njlr](https://github.com/njlr) updated the Buckaroo instructions. 155. [Lion](https://github.com/lieff) fixed a compilation issue with GCC 7 on CentOS. -156. [Isaac Nickaein](https://github.com/nickaein) improved the integer serialization performance and implemented the `contains()` function. +156. [Isaac Nickaein](https://github.com/nickaein) improved the integer serialization performance and implemented the `contains()` function. 157. [past-due](https://github.com/past-due) suppressed an unfixable warning. 158. [Elvis Oric](https://github.com/elvisoric) improved Meson support. 159. [Matěj Plch](https://github.com/Afforix) fixed an example in the README. 160. [Mark Beckwith](https://github.com/wythe) fixed a typo. -161. [scinart](https://github.com/scinart) fixed a bug in the serializer. +161. [scinart](https://github.com/scinart) fixed bug in the serializer. 162. [Patrick Boettcher](https://github.com/pboettch) implemented `push_back()` and `pop_back()` for JSON Pointers. 163. [Bruno Oliveira](https://github.com/nicoddemus) added support for Conda. 164. [Michele Caini](https://github.com/skypjack) fixed links in the README. @@ -1563,7 +1562,7 @@ I deeply appreciate the help of the following people. 200. [Alexander “weej” Jones](https://github.com/alex-weej) fixed an example in the README. 201. [Antoine Cœur](https://github.com/Coeur) fixed some typos in the documentation. 202. [jothepro](https://github.com/jothepro) updated links to the Hunter package. -203. [Dave Lee](https://github.com/kastiglione) fixed a link in the README. +203. [Dave Lee](https://github.com/kastiglione) fixed link in the README. 204. [Joël Lamotte](https://github.com/Klaim) added instruction for using Build2's package manager. 205. [Paul Jurczak](https://github.com/pauljurczak) fixed an example in the README. 206. [Sonu Lohani](https://github.com/sonulohani) fixed a warning. @@ -1606,7 +1605,7 @@ I deeply appreciate the help of the following people. 243. [raduteo](https://github.com/raduteo) fixed a warning. 244. [David Pfahler](https://github.com/theShmoo) added the possibility to compile the library without I/O support. 245. [Morten Fyhn Amundsen](https://github.com/mortenfyhn) fixed a typo. -246. [jpl-mac](https://github.com/jpl-mac) allowed treating the library as a system header in CMake. +246. [jpl-mac](https://github.com/jpl-mac) allowed to treat the library as a system header in CMake. 247. [Jason Dsouza](https://github.com/jasmcaus) fixed the indentation of the CMake file. 248. [offa](https://github.com/offa) added a link to Conan Center to the documentation. 249. [TotalCaesar659](https://github.com/TotalCaesar659) updated the links in the documentation to use HTTPS. @@ -1648,7 +1647,7 @@ I deeply appreciate the help of the following people. 285. [Wolf Vollprecht](https://github.com/wolfv) added the `patch_inplace` function. 286. [Jake Zimmerman](https://github.com/jez) highlighted common usage patterns in the README file. 287. [NN](https://github.com/NN---) added the Visual Studio output directory to `.gitignore`. -288. [Romain Reignier](https://github.com/romainreignier) improved the performance of the vector output adapter. +288. [Romain Reignier](https://github.com/romainreignier) improved the performance the vector output adapter. 289. [Mike](https://github.com/Mike-Leo-Smith) fixed the `std::iterator_traits`. 290. [Richard Hozák](https://github.com/zxey) added macro `JSON_NO_ENUM` to disable default enum conversions. 291. [vakokako](https://github.com/vakokako) fixed tests when compiling with C++20. @@ -1695,9 +1694,9 @@ I deeply appreciate the help of the following people. 332. [taro](https://github.com/tarolling) fixed a typo in the `CODEOWNERS` file. 333. [Ikko Eltociear Ashimine](https://github.com/eltociear) fixed a typo. 334. [Felix Yan](https://github.com/felixonmars) fixed a typo in the README. -335. [HO-COOH](https://github.com/HO-COOH) fixed a parenthesis in the documentation. +335. [HO-COOH](https://github.com/HO-COOH) fixed a parentheses in the documentation. 336. [Ivor Wanders](https://github.com/iwanders) fixed the examples to catch exception by `const&`. -337. [miny1233](https://github.com/miny1233) fixed a parenthesis in the documentation. +337. [miny1233](https://github.com/miny1233) fixed a parentheses in the documentation. 338. [tomalakgeretkal](https://github.com/tomalakgeretkal) fixed a compilation error. 339. [alferov](https://github.com/ALF-ONE) fixed a compilation error. 340. [Craig Scott](https://github.com/craigscott-crascit) fixed a deprecation warning in CMake. @@ -1780,7 +1779,7 @@ The library itself consists of a single header file licensed under the MIT licen The library supports **Unicode input** as follows: -- Only **UTF-8** encoded input is supported, which is the default encoding for JSON according to [RFC 8259](https://tools.ietf.org/html/rfc8259.html#section-8.1). +- Only **UTF-8** encoded input is supported which is the default encoding for JSON according to [RFC 8259](https://tools.ietf.org/html/rfc8259.html#section-8.1). - `std::u16string` and `std::u32string` can be parsed, assuming UTF-16 and UTF-32 encoding, respectively. These encodings are not supported when reading from files or other input containers. - Other encodings such as Latin-1 or ISO 8859-1 are **not** supported and will yield parse or serialization errors. - [Unicode noncharacters](https://www.unicode.org/faq/private_use.html#nonchar1) will not be replaced by the library. @@ -1802,17 +1801,7 @@ This library does not support comments by default. It does so for three reasons: 3. It is dangerous for interoperability if some libraries would add comment support while others don't. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this. -However, you can set set parameter `ignore_comments` to true in the `parse` function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace. - -### Trailing commas - -The JSON specification does not allow trailing commas in arrays and objects, and hence this library is treating them as parsing errors by default. - -Like comments, you can set parameter `ignore_trailing_commas` to true in the `parse` function to ignore trailing commas in arrays and objects. Note that a single comma as the only content of the array or object (`[,]` or `{,}`) is not allowed, and multiple trailing commas (`[1,,]`) are not allowed either. - -This library does not add trailing commas when serializing JSON data. - -For more information, see [JSON With Commas and Comments (JWCC)](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html). +However, you can pass set parameter `ignore_comments` to true in the `parse` function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace. ### Order of object keys diff --git a/nlohmann_json/cmake/ci.cmake b/nlohmann_json/cmake/ci.cmake index 316d6efe..1247e918 100644 --- a/nlohmann_json/cmake/ci.cmake +++ b/nlohmann_json/cmake/ci.cmake @@ -659,17 +659,6 @@ add_custom_target(ci_cuda_example COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_cuda_example ) -############################################################################### -# C++ 20 modules -############################################################################### - -add_custom_target(ci_module_cpp20 - COMMAND ${CMAKE_COMMAND} - -DCMAKE_BUILD_TYPE=Debug -GNinja - -S${PROJECT_SOURCE_DIR}/tests/module_cpp20 -B${PROJECT_BINARY_DIR}/ci_module_cpp20 - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/ci_module_cpp20 -) - ############################################################################### # Intel C++ Compiler ############################################################################### diff --git a/nlohmann_json/cmake/detect_libcpp_version.cpp b/nlohmann_json/cmake/detect_libcpp_version.cpp deleted file mode 100644 index a39322fc..00000000 --- a/nlohmann_json/cmake/detect_libcpp_version.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Detect used C++ Standard Library - * - * This file is compiled and run via try_run in download_test_data.cmake. - */ - -#include - -// see https://en.cppreference.com/w/cpp/header/ciso646 -#if __cplusplus >= 202002L - #include -#else - #include -#endif - -int main() -{ -#if defined(_LIBCPP_VERSION) - std::printf("LLVM C++ Standard Library (libc++), _LIBCPP_VERSION=%d", _LIBCPP_VERSION); -#elif defined(__GLIBCXX__) - std::printf("GNU C++ Standard Library (libstdc++), __GLIBCXX__=%d", __GLIBCXX__); -#elif defined(_MSVC_STL_VERSION) - std::printf("Microsoft C++ Standard Library (MSVC STL), _MSVC_STL_VERSION=%d", _MSVC_STL_VERSION); -#elif defined(_LIBCUDACXX_VERSION) - std::printf("NVIDIA C++ Standard Library (libcudacxx), _LIBCUDACXX_VERSION=%d", _LIBCUDACXX_VERSION); -#elif defined(EASTL_VERSION) - std::printf("Electronic Arts Standard Template Library (EASTL), EASTL_VERSION=%d", EASTL_VERSION); -#else - std::printf("unknown"); -#endif -} diff --git a/nlohmann_json/cmake/download_test_data.cmake b/nlohmann_json/cmake/download_test_data.cmake index 14376f4c..1bb998da 100644 --- a/nlohmann_json/cmake/download_test_data.cmake +++ b/nlohmann_json/cmake/download_test_data.cmake @@ -54,18 +54,3 @@ else() endif() string(REGEX REPLACE "[ ]*\n" "; " CXX_VERSION_RESULT "${CXX_VERSION_RESULT}") message(STATUS "Compiler: ${CXX_VERSION_RESULT}") - -# determine used C++ standard library (for debug and support purposes) -if(NOT DEFINED LIBCPP_VERSION_OUTPUT_CACHED) - try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR - "${CMAKE_BINARY_DIR}" SOURCES "${CMAKE_SOURCE_DIR}/cmake/detect_libcpp_version.cpp" - RUN_OUTPUT_VARIABLE LIBCPP_VERSION_OUTPUT COMPILE_OUTPUT_VARIABLE LIBCPP_VERSION_COMPILE_OUTPUT - ) - if(NOT LIBCPP_VERSION_OUTPUT) - set(LIBCPP_VERSION_OUTPUT "Unknown") - message(AUTHOR_WARNING "Failed to compile cmake/detect_libcpp_version to detect the used C++ standard library. This does not affect the library or the test cases. Please still create an issue at https://github.com/nlohmann/json to investigate this.\n${LIBCPP_VERSION_COMPILE_OUTPUT}") - endif() - set(LIBCPP_VERSION_OUTPUT_CACHED "${LIBCPP_VERSION_OUTPUT}" CACHE STRING "Detected C++ standard library version") -endif() - -message(STATUS "C++ standard library: ${LIBCPP_VERSION_OUTPUT_CACHED}") diff --git a/nlohmann_json/cmake/gcc_flags.cmake b/nlohmann_json/cmake/gcc_flags.cmake index 34c168ce..848630f3 100644 --- a/nlohmann_json/cmake/gcc_flags.cmake +++ b/nlohmann_json/cmake/gcc_flags.cmake @@ -1,13 +1,13 @@ -# Warning flags determined for GCC 15.1.0 with https://github.com/nlohmann/gcc_flags: +# Warning flags determined for GCC 14.2.0 with https://github.com/nlohmann/gcc_flags: # Ignored GCC warnings: -# -Wno-abi-tag We do not care about ABI tags. -# -Wno-aggregate-return The library uses aggregate returns. -# -Wno-long-long The library uses the long long type to interface with system functions. -# -Wno-namespaces The library uses namespaces. -# -Wno-nrvo Doctest triggers this warning. -# -Wno-padded We do not care about padding warnings. -# -Wno-system-headers We do not care about warnings in system headers. -# -Wno-templates The library uses templates. +# -Wno-abi-tag We do not care about ABI tags. +# -Wno-aggregate-return The library uses aggregate returns. +# -Wno-long-long The library uses the long long type to interface with system functions. +# -Wno-namespaces The library uses namespaces. +# -Wno-nrvo Doctest triggers this warning. +# -Wno-padded We do not care about padding warnings. +# -Wno-system-headers We do not care about warnings in system headers. +# -Wno-templates The library uses templates. set(GCC_CXXFLAGS -pedantic @@ -65,7 +65,6 @@ set(GCC_CXXFLAGS -Wanalyzer-tainted-offset -Wanalyzer-tainted-size -Wanalyzer-too-complex - -Wanalyzer-undefined-behavior-ptrdiff -Wanalyzer-undefined-behavior-strtok -Wanalyzer-unsafe-call-within-signal-handler -Wanalyzer-use-after-free @@ -124,7 +123,6 @@ set(GCC_CXXFLAGS -Wcoverage-invalid-line-number -Wcoverage-mismatch -Wcoverage-too-many-conditions - -Wcoverage-too-many-paths -Wcpp -Wctad-maybe-unsupported -Wctor-dtor-privacy @@ -132,7 +130,6 @@ set(GCC_CXXFLAGS -Wdangling-pointer=2 -Wdangling-reference -Wdate-time - -Wdefaulted-function-deleted -Wdelete-incomplete -Wdelete-non-virtual-dtor -Wdeprecated @@ -141,8 +138,6 @@ set(GCC_CXXFLAGS -Wdeprecated-declarations -Wdeprecated-enum-enum-conversion -Wdeprecated-enum-float-conversion - -Wdeprecated-literal-operator - -Wdeprecated-variadic-comma-omission -Wdisabled-optimization -Wdiv-by-zero -Wdouble-promotion @@ -162,21 +157,20 @@ set(GCC_CXXFLAGS -Wfloat-conversion -Wfloat-equal -Wformat -Wformat-contains-nul - -Wformat -Wformat-diag -Wformat -Wformat-extra-args -Wformat -Wformat-nonliteral - -Wformat -Wformat-overflow=2 -Wformat -Wformat-security - -Wformat -Wformat-signedness - -Wformat -Wformat-truncation=2 -Wformat -Wformat-y2k -Wformat -Wformat-zero-length + -Wformat-diag + -Wformat-overflow=2 + -Wformat-signedness + -Wformat-truncation=2 -Wformat=2 -Wframe-address -Wfree-nonheap-object -Wglobal-module -Whardened - -Wheader-guard -Whsa -Wif-not-aligned -Wignored-attributes @@ -203,7 +197,6 @@ set(GCC_CXXFLAGS -Wno-long-long -Wlto-type-mismatch -Wmain - -Wmaybe-musttail-local-addr -Wmaybe-uninitialized -Wmemset-elt-size -Wmemset-transposed-args @@ -222,7 +215,6 @@ set(GCC_CXXFLAGS -Wmultichar -Wmultiple-inheritance -Wmultistatement-macros - -Wmusttail-local-addr -Wno-namespaces -Wnarrowing -Wnoexcept @@ -253,7 +245,6 @@ set(GCC_CXXFLAGS -Wpmf-conversions -Wpointer-arith -Wpointer-compare - -Wpragma-once-outside-header -Wpragmas -Wprio-ctor-dtor -Wpsabi @@ -285,12 +276,10 @@ set(GCC_CXXFLAGS -Wsizeof-pointer-div -Wsizeof-pointer-memaccess -Wstack-protector - -Wstrict-aliasing -Wstrict-aliasing=3 -Wstrict-null-sentinel -Wstrict-overflow -Wstring-compare - -Wstringop-overflow -Wstringop-overflow=4 -Wstringop-overread -Wstringop-truncation @@ -315,12 +304,8 @@ set(GCC_CXXFLAGS -Wsynth -Wno-system-headers -Wtautological-compare - -Wtemplate-body - -Wtemplate-id-cdtor - -Wtemplate-names-tu-local -Wno-templates -Wterminate - -Wtrailing-whitespace -Wtrampolines -Wtrigraphs -Wtrivial-auto-var-init diff --git a/nlohmann_json/cmake/requirements/requirements-cpplint.txt b/nlohmann_json/cmake/requirements/requirements-cpplint.txt index 6aabac21..abb438cc 100644 --- a/nlohmann_json/cmake/requirements/requirements-cpplint.txt +++ b/nlohmann_json/cmake/requirements/requirements-cpplint.txt @@ -1 +1 @@ -cpplint==2.0.2 +cpplint==2.0.1 diff --git a/nlohmann_json/docs/mkdocs/docs/api/adl_serializer/index.md b/nlohmann_json/docs/mkdocs/docs/api/adl_serializer/index.md index e83b66de..95f35cdd 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/adl_serializer/index.md +++ b/nlohmann_json/docs/mkdocs/docs/api/adl_serializer/index.md @@ -8,7 +8,7 @@ struct adl_serializer; Serializer that uses ADL ([Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)) to choose `to_json`/`from_json` functions from the types' namespaces. -It is implemented similarly to +It is implemented similar to ```cpp template diff --git a/nlohmann_json/docs/mkdocs/docs/api/basic_json/accept.md b/nlohmann_json/docs/mkdocs/docs/api/basic_json/accept.md index 5f9bac05..15206984 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/basic_json/accept.md +++ b/nlohmann_json/docs/mkdocs/docs/api/basic_json/accept.md @@ -4,14 +4,12 @@ // (1) template static bool accept(InputType&& i, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false); + const bool ignore_comments = false); // (2) template static bool accept(IteratorType first, IteratorType last, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false); + const bool ignore_comments = false); ``` Checks whether the input is valid JSON. @@ -52,10 +50,6 @@ Unlike the [`parse()`](parse.md) function, this function neither throws an excep : whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error (`#!cpp false`); (optional, `#!cpp false` by default) -`ignore_trailing_commas` (in) -: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error - (`#!cpp false`); (optional, `#!cpp false` by default) - `first` (in) : iterator to the start of the character range @@ -108,7 +102,6 @@ A UTF-8 byte order mark is silently ignored. - Added in version 3.0.0. - Ignoring comments via `ignore_comments` added in version 3.9.0. - Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0. -- Added `ignore_trailing_commas` in version 3.12.1. !!! warning "Deprecation" diff --git a/nlohmann_json/docs/mkdocs/docs/api/basic_json/basic_json.md b/nlohmann_json/docs/mkdocs/docs/api/basic_json/basic_json.md index 83c50007..71def92a 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/basic_json/basic_json.md +++ b/nlohmann_json/docs/mkdocs/docs/api/basic_json/basic_json.md @@ -74,7 +74,7 @@ basic_json(basic_json&& other) noexcept; - **boolean**: `boolean_t` / `bool` can be used. - **binary**: `binary_t` / `std::vector` may be used; unfortunately because string literals cannot be distinguished from binary character arrays by the C++ type system, all types compatible with `const char*` will be - directed to the string constructor instead. This is both for backwards compatibility and due to the fact that a + directed to the string constructor instead. This is both for backwards compatibility, and due to the fact that a binary type is not a standard JSON type. See the examples below. diff --git a/nlohmann_json/docs/mkdocs/docs/api/basic_json/empty.md b/nlohmann_json/docs/mkdocs/docs/api/basic_json/empty.md index 8d566738..26bf6e9a 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/basic_json/empty.md +++ b/nlohmann_json/docs/mkdocs/docs/api/basic_json/empty.md @@ -4,7 +4,7 @@ bool empty() const noexcept; ``` -Checks if a JSON value has no elements (i.e., whether its [`size()`](size.md) is `0`). +Checks if a JSON value has no elements (i.e. whether its [`size()`](size.md) is `0`). ## Return value diff --git a/nlohmann_json/docs/mkdocs/docs/api/basic_json/insert.md b/nlohmann_json/docs/mkdocs/docs/api/basic_json/insert.md index 160b0d43..2f809f01 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/basic_json/insert.md +++ b/nlohmann_json/docs/mkdocs/docs/api/basic_json/insert.md @@ -29,11 +29,11 @@ void insert(const_iterator first, const_iterator last); For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators (including the [`end()`](end.md) iterator) and all references to the elements are invalidated. Otherwise, only the [`end()`](end.md) iterator is invalidated. Also, any iterator or reference after the insertion point will point to the -same index, which is now a different value. +same index which is now a different value. For [`ordered_json`](../ordered_json.md), also adding an element to an **object** can yield a reallocation which again invalidates all iterators and all references. Also, any iterator or reference after the insertion point will point to -the same index, which is now a different value. +the same index which is now a different value. ## Parameters diff --git a/nlohmann_json/docs/mkdocs/docs/api/basic_json/json_base_class_t.md b/nlohmann_json/docs/mkdocs/docs/api/basic_json/json_base_class_t.md index dfe5f1cb..75752049 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/basic_json/json_base_class_t.md +++ b/nlohmann_json/docs/mkdocs/docs/api/basic_json/json_base_class_t.md @@ -16,7 +16,7 @@ Examples of such functionality might be metadata, additional member functions (e #### Default type -The default value for `CustomBaseClass` is `void`. In this case, an +The default value for `CustomBaseClass` is `void`. In this case an [empty base class](https://en.cppreference.com/w/cpp/language/ebo) is used and no additional functionality is injected. #### Limitations diff --git a/nlohmann_json/docs/mkdocs/docs/api/basic_json/parse.md b/nlohmann_json/docs/mkdocs/docs/api/basic_json/parse.md index 7baa16b8..140a08f3 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/basic_json/parse.md +++ b/nlohmann_json/docs/mkdocs/docs/api/basic_json/parse.md @@ -6,16 +6,14 @@ template static basic_json parse(InputType&& i, const parser_callback_t cb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false); + const bool ignore_comments = false); // (2) template static basic_json parse(IteratorType first, IteratorType last, const parser_callback_t cb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false); + const bool ignore_comments = false); ``` 1. Deserialize from a compatible input. @@ -58,10 +56,6 @@ static basic_json parse(IteratorType first, IteratorType last, : whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error (`#!cpp false`); (optional, `#!cpp false` by default) -`ignore_trailing_commas` (in) -: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error - (`#!cpp false`); (optional, `#!cpp false` by default) - `first` (in) : iterator to the start of a character range @@ -195,34 +189,6 @@ A UTF-8 byte order mark is silently ignored. --8<-- "examples/parse__allow_exceptions.output" ``` -??? example "Effect of `ignore_comments` parameter" - - The example below demonstrates the effect of the `ignore_comments` parameter in the `parse()` function. - - ```cpp - --8<-- "examples/comments.cpp" - ``` - - Output: - - ``` - --8<-- "examples/comments.output" - ``` - -??? example "Effect of `ignore_trailing_commas` parameter" - - The example below demonstrates the effect of the `ignore_trailing_commas` parameter in the `parse()` function. - - ```cpp - --8<-- "examples/trailing_commas.cpp" - ``` - - Output: - - ``` - --8<-- "examples/trailing_commas.output" - ``` - ## See also - [accept](accept.md) - check if the input is valid JSON @@ -234,7 +200,6 @@ A UTF-8 byte order mark is silently ignored. - Overload for contiguous containers (1) added in version 2.0.3. - Ignoring comments via `ignore_comments` added in version 3.9.0. - Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0. -- Added `ignore_trailing_commas` in version 3.12.1. !!! warning "Deprecation" diff --git a/nlohmann_json/docs/mkdocs/docs/api/basic_json/sax_parse.md b/nlohmann_json/docs/mkdocs/docs/api/basic_json/sax_parse.md index 26b2f236..43793d09 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/basic_json/sax_parse.md +++ b/nlohmann_json/docs/mkdocs/docs/api/basic_json/sax_parse.md @@ -7,8 +7,7 @@ static bool sax_parse(InputType&& i, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false); + const bool ignore_comments = false); // (2) template @@ -16,8 +15,7 @@ static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false); + const bool ignore_comments = false); ``` Read from input and generate SAX events @@ -67,10 +65,6 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index : whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error (`#!cpp false`); (optional, `#!cpp false` by default) -`ignore_trailing_commas` (in) -: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error - (`#!cpp false`); (optional, `#!cpp false` by default) - `first` (in) : iterator to the start of a character range @@ -113,7 +107,6 @@ A UTF-8 byte order mark is silently ignored. - Added in version 3.2.0. - Ignoring comments via `ignore_comments` added in version 3.9.0. -- Added `ignore_trailing_commas` in version 3.12.1. !!! warning "Deprecation" diff --git a/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_derived_type.md b/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_derived_type.md index d33bc1ee..d9c9e042 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_derived_type.md +++ b/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_derived_type.md @@ -79,7 +79,7 @@ template void from_json(const BasicJsonType&, type&); ``` -Macros 3 and 6 add one function to the namespace, which takes care of the serialization only: +Macros 3 and 6 add one function to the namespace which takes care of the serialization only: ```cpp template diff --git a/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_type_intrusive.md b/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_type_intrusive.md index b95d2679..32fb68ee 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_type_intrusive.md +++ b/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_type_intrusive.md @@ -46,7 +46,7 @@ template friend void from_json(const BasicJsonType&, type&); // except (3) ``` -See the examples below for the concrete generated code. +See examples below for the concrete generated code. ## Notes diff --git a/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_type_non_intrusive.md b/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_type_non_intrusive.md index c3e2721c..2bbf0a69 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_type_non_intrusive.md +++ b/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_define_type_non_intrusive.md @@ -46,7 +46,7 @@ template void from_json(const BasicJsonType&, type&); // except (3) ``` -See the examples below for the concrete generated code. +See examples below for the concrete generated code. ## Notes diff --git a/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_json_serialize_enum.md b/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_json_serialize_enum.md index adaceae8..c54f9195 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_json_serialize_enum.md +++ b/nlohmann_json/docs/mkdocs/docs/api/macros/nlohmann_json_serialize_enum.md @@ -4,8 +4,8 @@ #define NLOHMANN_JSON_SERIALIZE_ENUM(type, conversion...) ``` -By default, enum values are serialized to JSON as integers. In some cases, this could result in undesired behavior. If -an enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be +By default, enum values are serialized to JSON as integers. In some cases this could result in undesired behavior. If an +enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be undefined or a different enum value than was originally intended. The `NLOHMANN_JSON_SERIALIZE_ENUM` allows to define a user-defined serialization for every enumerator. diff --git a/nlohmann_json/docs/mkdocs/docs/api/ordered_json.md b/nlohmann_json/docs/mkdocs/docs/api/ordered_json.md index b28fe36f..f4062d13 100644 --- a/nlohmann_json/docs/mkdocs/docs/api/ordered_json.md +++ b/nlohmann_json/docs/mkdocs/docs/api/ordered_json.md @@ -11,7 +11,7 @@ This type preserves the insertion order of object keys. The type is based on [`ordered_map`](ordered_map.md) which in turn uses a `std::vector` to store object elements. Therefore, adding object elements can yield a reallocation in which case all iterators (including the [`end()`](basic_json/end.md) iterator) and all references to the elements are invalidated. Also, any iterator or -reference after the insertion point will point to the same index, which is now a different value. +reference after the insertion point will point to the same index which is now a different value. ## Examples diff --git a/nlohmann_json/docs/mkdocs/docs/community/quality_assurance.md b/nlohmann_json/docs/mkdocs/docs/community/quality_assurance.md index 5b09b12f..134926ca 100644 --- a/nlohmann_json/docs/mkdocs/docs/community/quality_assurance.md +++ b/nlohmann_json/docs/mkdocs/docs/community/quality_assurance.md @@ -28,7 +28,6 @@ violations will result in a failed build. | AppleClang 16.0.0.16000026; Xcode 16 | arm64 | macOS 15.2 (Sequoia) | GitHub | | AppleClang 16.0.0.16000026; Xcode 16.1 | arm64 | macOS 15.2 (Sequoia) | GitHub | | AppleClang 16.0.0.16000026; Xcode 16.2 | arm64 | macOS 15.2 (Sequoia) | GitHub | - | AppleClang 17.0.0.17000013; Xcode 16.3 | arm64 | macOS 15.5 (Sequoia) | GitHub | | Clang 3.5.2 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | Clang 3.6.2 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | Clang 3.7.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | @@ -58,7 +57,6 @@ violations will result in a failed build. | Clang 19.1.7 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | Clang 20.1.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | Clang 21.0.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | - | Emscripten 4.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 4.8.5 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 4.9.3 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 5.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | @@ -77,8 +75,6 @@ violations will result in a failed build. | GNU 13.3.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 14.2.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 14.2.0 | arm64 | Linux 6.1.100 | Cirrus CI | - | GNU 15.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | - | icpc (ICC) 2021.5.0 20211109 | x86_64 | Ubuntu 20.04.3 LTS | GitHub | | MSVC 19.0.24241.7 | x86 | Windows 8.1 | AppVeyor | | MSVC 19.16.27035.0 | x86 | Windows-10 (Build 14393) | AppVeyor | | MSVC 19.29.30157.0 | x86 | Windows 10 (Build 17763) | GitHub | diff --git a/nlohmann_json/docs/mkdocs/docs/examples/README.cpp b/nlohmann_json/docs/mkdocs/docs/examples/README.cpp index 2d641e58..c8594598 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/README.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/README.cpp @@ -1,39 +1,26 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create a JSON object - json j = - { - {"pi", 3.141}, - {"happy", true}, - {"name", "Niels"}, - {"nothing", nullptr}, - { - "answer", { - {"everything", 42} - } - }, - {"list", {1, 0, 2}}, - { - "object", { - {"currency", "USD"}, - {"value", 42.99} - } - } - }; +int main() { + // create a JSON object + json j = {{"pi", 3.141}, + {"happy", true}, + {"name", "Niels"}, + {"nothing", nullptr}, + {"answer", {{"everything", 42}}}, + {"list", {1, 0, 2}}, + {"object", {{"currency", "USD"}, {"value", 42.99}}}}; - // add new values - j["new"]["key"]["value"] = {"another", "list"}; + // add new values + j["new"]["key"]["value"] = {"another", "list"}; - // count elements - auto s = j.size(); - j["size"] = s; + // count elements + auto s = j.size(); + j["size"] = s; - // pretty print with indent of 4 spaces - std::cout << std::setw(4) << j << '\n'; + // pretty print with indent of 4 spaces + std::cout << std::setw(4) << j << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/accept__string.cpp b/nlohmann_json/docs/mkdocs/docs/examples/accept__string.cpp index 8eb3d9b7..0deb1fb7 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/accept__string.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/accept__string.cpp @@ -1,26 +1,24 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // a valid JSON text - auto valid_text = R"( +int main() { + // a valid JSON text + auto valid_text = R"( { "numbers": [1, 2, 3] } )"; - // an invalid JSON text - auto invalid_text = R"( + // an invalid JSON text + auto invalid_text = R"( { "strings": ["extra", "comma", ] } )"; - std::cout << std::boolalpha - << json::accept(valid_text) << ' ' - << json::accept(invalid_text) << '\n'; + std::cout << std::boolalpha << json::accept(valid_text) << ' ' + << json::accept(invalid_text) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/array.cpp b/nlohmann_json/docs/mkdocs/docs/examples/array.cpp index 139b5ef1..df445026 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/array.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/array.cpp @@ -3,17 +3,16 @@ using json = nlohmann::json; -int main() -{ - // create JSON arrays - json j_no_init_list = json::array(); - json j_empty_init_list = json::array({}); - json j_nonempty_init_list = json::array({1, 2, 3, 4}); - json j_list_of_pairs = json::array({ {"one", 1}, {"two", 2} }); +int main() { + // create JSON arrays + json j_no_init_list = json::array(); + json j_empty_init_list = json::array({}); + json j_nonempty_init_list = json::array({1, 2, 3, 4}); + json j_list_of_pairs = json::array({{"one", 1}, {"two", 2}}); - // serialize the JSON arrays - std::cout << j_no_init_list << '\n'; - std::cout << j_empty_init_list << '\n'; - std::cout << j_nonempty_init_list << '\n'; - std::cout << j_list_of_pairs << '\n'; + // serialize the JSON arrays + std::cout << j_no_init_list << '\n'; + std::cout << j_empty_init_list << '\n'; + std::cout << j_nonempty_init_list << '\n'; + std::cout << j_list_of_pairs << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/array_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/array_t.cpp index 0964857b..2e04c6e3 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/array_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/array_t.cpp @@ -1,10 +1,11 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - std::cout << std::boolalpha << std::is_same, json::array_t>::value << std::endl; +int main() { + std::cout << std::boolalpha + << std::is_same, json::array_t>::value + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/at__json_pointer.cpp b/nlohmann_json/docs/mkdocs/docs/examples/at__json_pointer.cpp index 15e91433..f821441e 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/at__json_pointer.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/at__json_pointer.cpp @@ -4,100 +4,78 @@ using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create a JSON value - json j = - { - {"number", 1}, {"string", "foo"}, {"array", {1, 2}} - }; +int main() { + // create a JSON value + json j = {{"number", 1}, {"string", "foo"}, {"array", {1, 2}}}; - // read-only access + // read-only access - // output element with JSON pointer "/number" - std::cout << j.at("/number"_json_pointer) << '\n'; - // output element with JSON pointer "/string" - std::cout << j.at("/string"_json_pointer) << '\n'; - // output element with JSON pointer "/array" - std::cout << j.at("/array"_json_pointer) << '\n'; - // output element with JSON pointer "/array/1" - std::cout << j.at("/array/1"_json_pointer) << '\n'; + // output element with JSON pointer "/number" + std::cout << j.at("/number"_json_pointer) << '\n'; + // output element with JSON pointer "/string" + std::cout << j.at("/string"_json_pointer) << '\n'; + // output element with JSON pointer "/array" + std::cout << j.at("/array"_json_pointer) << '\n'; + // output element with JSON pointer "/array/1" + std::cout << j.at("/array/1"_json_pointer) << '\n'; - // writing access + // writing access - // change the string - j.at("/string"_json_pointer) = "bar"; - // output the changed string - std::cout << j["string"] << '\n'; + // change the string + j.at("/string"_json_pointer) = "bar"; + // output the changed string + std::cout << j["string"] << '\n'; - // change an array element - j.at("/array/1"_json_pointer) = 21; - // output the changed array - std::cout << j["array"] << '\n'; + // change an array element + j.at("/array/1"_json_pointer) = 21; + // output the changed array + std::cout << j["array"] << '\n'; - // out_of_range.106 - try - { - // try to use an array index with leading '0' - json::reference ref = j.at("/array/01"_json_pointer); - } - catch (const json::parse_error& e) - { - std::cout << e.what() << '\n'; - } + // out_of_range.106 + try { + // try to use an array index with leading '0' + json::reference ref = j.at("/array/01"_json_pointer); + } catch (const json::parse_error &e) { + std::cout << e.what() << '\n'; + } - // out_of_range.109 - try - { - // try to use an array index that is not a number - json::reference ref = j.at("/array/one"_json_pointer); - } - catch (const json::parse_error& e) - { - std::cout << e.what() << '\n'; - } + // out_of_range.109 + try { + // try to use an array index that is not a number + json::reference ref = j.at("/array/one"_json_pointer); + } catch (const json::parse_error &e) { + std::cout << e.what() << '\n'; + } - // out_of_range.401 - try - { - // try to use an invalid array index - json::reference ref = j.at("/array/4"_json_pointer); - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } + // out_of_range.401 + try { + // try to use an invalid array index + json::reference ref = j.at("/array/4"_json_pointer); + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } - // out_of_range.402 - try - { - // try to use the array index '-' - json::reference ref = j.at("/array/-"_json_pointer); - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } + // out_of_range.402 + try { + // try to use the array index '-' + json::reference ref = j.at("/array/-"_json_pointer); + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } - // out_of_range.403 - try - { - // try to use a JSON pointer to a nonexistent object key - json::const_reference ref = j.at("/foo"_json_pointer); - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } + // out_of_range.403 + try { + // try to use a JSON pointer to a nonexistent object key + json::const_reference ref = j.at("/foo"_json_pointer); + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } - // out_of_range.404 - try - { - // try to use a JSON pointer that cannot be resolved - json::reference ref = j.at("/number/foo"_json_pointer); - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } + // out_of_range.404 + try { + // try to use a JSON pointer that cannot be resolved + json::reference ref = j.at("/number/foo"_json_pointer); + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/at__json_pointer_const.cpp b/nlohmann_json/docs/mkdocs/docs/examples/at__json_pointer_const.cpp index ab026e07..4d0edcbf 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/at__json_pointer_const.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/at__json_pointer_const.cpp @@ -4,77 +4,58 @@ using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create a JSON value - const json j = - { - {"number", 1}, {"string", "foo"}, {"array", {1, 2}} - }; - - // read-only access - - // output element with JSON pointer "/number" - std::cout << j.at("/number"_json_pointer) << '\n'; - // output element with JSON pointer "/string" - std::cout << j.at("/string"_json_pointer) << '\n'; - // output element with JSON pointer "/array" - std::cout << j.at("/array"_json_pointer) << '\n'; - // output element with JSON pointer "/array/1" - std::cout << j.at("/array/1"_json_pointer) << '\n'; - - // out_of_range.109 - try - { - // try to use an array index that is not a number - json::const_reference ref = j.at("/array/one"_json_pointer); - } - catch (const json::parse_error& e) - { - std::cout << e.what() << '\n'; - } - - // out_of_range.401 - try - { - // try to use an invalid array index - json::const_reference ref = j.at("/array/4"_json_pointer); - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } - - // out_of_range.402 - try - { - // try to use the array index '-' - json::const_reference ref = j.at("/array/-"_json_pointer); - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } - - // out_of_range.403 - try - { - // try to use a JSON pointer to a nonexistent object key - json::const_reference ref = j.at("/foo"_json_pointer); - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } - - // out_of_range.404 - try - { - // try to use a JSON pointer that cannot be resolved - json::const_reference ref = j.at("/number/foo"_json_pointer); - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } +int main() { + // create a JSON value + const json j = {{"number", 1}, {"string", "foo"}, {"array", {1, 2}}}; + + // read-only access + + // output element with JSON pointer "/number" + std::cout << j.at("/number"_json_pointer) << '\n'; + // output element with JSON pointer "/string" + std::cout << j.at("/string"_json_pointer) << '\n'; + // output element with JSON pointer "/array" + std::cout << j.at("/array"_json_pointer) << '\n'; + // output element with JSON pointer "/array/1" + std::cout << j.at("/array/1"_json_pointer) << '\n'; + + // out_of_range.109 + try { + // try to use an array index that is not a number + json::const_reference ref = j.at("/array/one"_json_pointer); + } catch (const json::parse_error &e) { + std::cout << e.what() << '\n'; + } + + // out_of_range.401 + try { + // try to use an invalid array index + json::const_reference ref = j.at("/array/4"_json_pointer); + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } + + // out_of_range.402 + try { + // try to use the array index '-' + json::const_reference ref = j.at("/array/-"_json_pointer); + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } + + // out_of_range.403 + try { + // try to use a JSON pointer to a nonexistent object key + json::const_reference ref = j.at("/foo"_json_pointer); + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } + + // out_of_range.404 + try { + // try to use a JSON pointer that cannot be resolved + json::const_reference ref = j.at("/number/foo"_json_pointer); + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/at__keytype.c++17.cpp b/nlohmann_json/docs/mkdocs/docs/examples/at__keytype.c++17.cpp index 032506ac..1818e8c8 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/at__keytype.c++17.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/at__keytype.c++17.cpp @@ -1,49 +1,39 @@ #include -#include #include +#include using namespace std::string_view_literals; using json = nlohmann::json; -int main() -{ - // create JSON object - json object = - { - {"the good", "il buono"}, - {"the bad", "il cattivo"}, - {"the ugly", "il brutto"} - }; +int main() { + // create JSON object + json object = {{"the good", "il buono"}, + {"the bad", "il cattivo"}, + {"the ugly", "il brutto"}}; - // output element with key "the ugly" using string_view - std::cout << object.at("the ugly"sv) << '\n'; + // output element with key "the ugly" using string_view + std::cout << object.at("the ugly"sv) << '\n'; - // change element with key "the bad" using string_view - object.at("the bad"sv) = "il cattivo"; + // change element with key "the bad" using string_view + object.at("the bad"sv) = "il cattivo"; - // output changed array - std::cout << object << '\n'; + // output changed array + std::cout << object << '\n'; - // exception type_error.304 - try - { - // use at() with string_view on a non-object type - json str = "I am a string"; - str.at("the good"sv) = "Another string"; - } - catch (const json::type_error& e) - { - std::cout << e.what() << '\n'; - } + // exception type_error.304 + try { + // use at() with string_view on a non-object type + json str = "I am a string"; + str.at("the good"sv) = "Another string"; + } catch (const json::type_error &e) { + std::cout << e.what() << '\n'; + } - // exception out_of_range.401 - try - { - // try to write at a nonexisting key using string_view - object.at("the fast"sv) = "il rapido"; - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } + // exception out_of_range.401 + try { + // try to write at a nonexisting key using string_view + object.at("the fast"sv) = "il rapido"; + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/at__keytype_const.c++17.cpp b/nlohmann_json/docs/mkdocs/docs/examples/at__keytype_const.c++17.cpp index 712d456e..1834fca3 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/at__keytype_const.c++17.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/at__keytype_const.c++17.cpp @@ -1,43 +1,33 @@ #include -#include #include +#include using namespace std::string_view_literals; using json = nlohmann::json; -int main() -{ - // create JSON object - const json object = - { - {"the good", "il buono"}, - {"the bad", "il cattivo"}, - {"the ugly", "il brutto"} - }; +int main() { + // create JSON object + const json object = {{"the good", "il buono"}, + {"the bad", "il cattivo"}, + {"the ugly", "il brutto"}}; - // output element with key "the ugly" using string_view - std::cout << object.at("the ugly"sv) << '\n'; + // output element with key "the ugly" using string_view + std::cout << object.at("the ugly"sv) << '\n'; - // exception type_error.304 - try - { - // use at() with string_view on a non-object type - const json str = "I am a string"; - std::cout << str.at("the good"sv) << '\n'; - } - catch (const json::type_error& e) - { - std::cout << e.what() << '\n'; - } + // exception type_error.304 + try { + // use at() with string_view on a non-object type + const json str = "I am a string"; + std::cout << str.at("the good"sv) << '\n'; + } catch (const json::type_error &e) { + std::cout << e.what() << '\n'; + } - // exception out_of_range.401 - try - { - // try to read from a nonexisting key using string_view - std::cout << object.at("the fast"sv) << '\n'; - } - catch (const json::out_of_range& e) - { - std::cout << "out of range" << '\n'; - } + // exception out_of_range.401 + try { + // try to read from a nonexisting key using string_view + std::cout << object.at("the fast"sv) << '\n'; + } catch (const json::out_of_range &e) { + std::cout << "out of range" << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/at__object_t_key_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/at__object_t_key_type.cpp index e1f33cec..21a0ee2a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/at__object_t_key_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/at__object_t_key_type.cpp @@ -3,45 +3,35 @@ using json = nlohmann::json; -int main() -{ - // create JSON object - json object = - { - {"the good", "il buono"}, - {"the bad", "il cattivo"}, - {"the ugly", "il brutto"} - }; +int main() { + // create JSON object + json object = {{"the good", "il buono"}, + {"the bad", "il cattivo"}, + {"the ugly", "il brutto"}}; - // output element with key "the ugly" - std::cout << object.at("the ugly") << '\n'; + // output element with key "the ugly" + std::cout << object.at("the ugly") << '\n'; - // change element with key "the bad" - object.at("the bad") = "il cattivo"; + // change element with key "the bad" + object.at("the bad") = "il cattivo"; - // output changed array - std::cout << object << '\n'; + // output changed array + std::cout << object << '\n'; - // exception type_error.304 - try - { - // use at() on a non-object type - json str = "I am a string"; - str.at("the good") = "Another string"; - } - catch (const json::type_error& e) - { - std::cout << e.what() << '\n'; - } + // exception type_error.304 + try { + // use at() on a non-object type + json str = "I am a string"; + str.at("the good") = "Another string"; + } catch (const json::type_error &e) { + std::cout << e.what() << '\n'; + } - // exception out_of_range.401 - try - { - // try to write at a nonexisting key - object.at("the fast") = "il rapido"; - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } + // exception out_of_range.401 + try { + // try to write at a nonexisting key + object.at("the fast") = "il rapido"; + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/at__object_t_key_type_const.cpp b/nlohmann_json/docs/mkdocs/docs/examples/at__object_t_key_type_const.cpp index b37bbd48..164ef8ee 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/at__object_t_key_type_const.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/at__object_t_key_type_const.cpp @@ -3,39 +3,29 @@ using json = nlohmann::json; -int main() -{ - // create JSON object - const json object = - { - {"the good", "il buono"}, - {"the bad", "il cattivo"}, - {"the ugly", "il brutto"} - }; +int main() { + // create JSON object + const json object = {{"the good", "il buono"}, + {"the bad", "il cattivo"}, + {"the ugly", "il brutto"}}; - // output element with key "the ugly" - std::cout << object.at("the ugly") << '\n'; + // output element with key "the ugly" + std::cout << object.at("the ugly") << '\n'; - // exception type_error.304 - try - { - // use at() on a non-object type - const json str = "I am a string"; - std::cout << str.at("the good") << '\n'; - } - catch (const json::type_error& e) - { - std::cout << e.what() << '\n'; - } + // exception type_error.304 + try { + // use at() on a non-object type + const json str = "I am a string"; + std::cout << str.at("the good") << '\n'; + } catch (const json::type_error &e) { + std::cout << e.what() << '\n'; + } - // exception out_of_range.401 - try - { - // try to read from a nonexisting key - std::cout << object.at("the fast") << '\n'; - } - catch (const json::out_of_range) - { - std::cout << "out of range" << '\n'; - } + // exception out_of_range.401 + try { + // try to read from a nonexisting key + std::cout << object.at("the fast") << '\n'; + } catch (const json::out_of_range) { + std::cout << "out of range" << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/at__size_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/at__size_type.cpp index 6527c6b1..2c28b62f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/at__size_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/at__size_type.cpp @@ -3,40 +3,33 @@ using json = nlohmann::json; -int main() -{ - // create JSON array - json array = {"first", "2nd", "third", "fourth"}; +int main() { + // create JSON array + json array = {"first", "2nd", "third", "fourth"}; - // output element at index 2 (third element) - std::cout << array.at(2) << '\n'; + // output element at index 2 (third element) + std::cout << array.at(2) << '\n'; - // change element at index 1 (second element) to "second" - array.at(1) = "second"; + // change element at index 1 (second element) to "second" + array.at(1) = "second"; - // output changed array - std::cout << array << '\n'; + // output changed array + std::cout << array << '\n'; - // exception type_error.304 - try - { - // use at() on a non-array type - json str = "I am a string"; - str.at(0) = "Another string"; - } - catch (const json::type_error& e) - { - std::cout << e.what() << '\n'; - } + // exception type_error.304 + try { + // use at() on a non-array type + json str = "I am a string"; + str.at(0) = "Another string"; + } catch (const json::type_error &e) { + std::cout << e.what() << '\n'; + } - // exception out_of_range.401 - try - { - // try to write beyond the array limit - array.at(5) = "sixth"; - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } + // exception out_of_range.401 + try { + // try to write beyond the array limit + array.at(5) = "sixth"; + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/at__size_type_const.cpp b/nlohmann_json/docs/mkdocs/docs/examples/at__size_type_const.cpp index 2080387a..62dc7aa1 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/at__size_type_const.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/at__size_type_const.cpp @@ -3,34 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON array - const json array = {"first", "2nd", "third", "fourth"}; +int main() { + // create JSON array + const json array = {"first", "2nd", "third", "fourth"}; - // output element at index 2 (third element) - std::cout << array.at(2) << '\n'; + // output element at index 2 (third element) + std::cout << array.at(2) << '\n'; - // exception type_error.304 - try - { - // use at() on a non-array type - const json str = "I am a string"; - std::cout << str.at(0) << '\n'; - } - catch (const json::type_error& e) - { - std::cout << e.what() << '\n'; - } + // exception type_error.304 + try { + // use at() on a non-array type + const json str = "I am a string"; + std::cout << str.at(0) << '\n'; + } catch (const json::type_error &e) { + std::cout << e.what() << '\n'; + } - // exception out_of_range.401 - try - { - // try to read beyond the array limit - std::cout << array.at(5) << '\n'; - } - catch (const json::out_of_range& e) - { - std::cout << e.what() << '\n'; - } + // exception out_of_range.401 + try { + // try to read beyond the array limit + std::cout << array.at(5) << '\n'; + } catch (const json::out_of_range &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/back.cpp b/nlohmann_json/docs/mkdocs/docs/examples/back.cpp index 45342db1..02286ae0 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/back.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/back.cpp @@ -3,36 +3,32 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_object_empty(json::value_t::object); - json j_array = {1, 2, 4, 8, 16}; - json j_array_empty(json::value_t::array); - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_object_empty(json::value_t::object); + json j_array = {1, 2, 4, 8, 16}; + json j_array_empty(json::value_t::array); + json j_string = "Hello, world"; - // call back() - std::cout << j_boolean.back() << '\n'; - std::cout << j_number_integer.back() << '\n'; - std::cout << j_number_float.back() << '\n'; - std::cout << j_object.back() << '\n'; - //std::cout << j_object_empty.back() << '\n'; // undefined behavior - std::cout << j_array.back() << '\n'; - //std::cout << j_array_empty.back() << '\n'; // undefined behavior - std::cout << j_string.back() << '\n'; + // call back() + std::cout << j_boolean.back() << '\n'; + std::cout << j_number_integer.back() << '\n'; + std::cout << j_number_float.back() << '\n'; + std::cout << j_object.back() << '\n'; + // std::cout << j_object_empty.back() << '\n'; // undefined behavior + std::cout << j_array.back() << '\n'; + // std::cout << j_array_empty.back() << '\n'; // undefined behavior + std::cout << j_string.back() << '\n'; - // back() called on a null value - try - { - json j_null; - j_null.back(); - } - catch (const json::invalid_iterator& e) - { - std::cout << e.what() << '\n'; - } + // back() called on a null value + try { + json j_null; + j_null.back(); + } catch (const json::invalid_iterator &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__CompatibleType.cpp b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__CompatibleType.cpp index f0d0cc1e..13b4b75d 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__CompatibleType.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__CompatibleType.cpp @@ -1,214 +1,205 @@ -#include #include -#include #include +#include +#include +#include #include #include #include #include -#include using json = nlohmann::json; -int main() -{ - // ============ - // object types - // ============ - - // create an object from an object_t value - json::object_t object_value = { {"one", 1}, {"two", 2} }; - json j_object_t(object_value); - - // create an object from std::map - std::map c_map - { - {"one", 1}, {"two", 2}, {"three", 3} - }; - json j_map(c_map); - - // create an object from std::unordered_map - std::unordered_map c_umap - { - {"one", 1.2}, {"two", 2.3}, {"three", 3.4} - }; - json j_umap(c_umap); - - // create an object from std::multimap - std::multimap c_mmap - { - {"one", true}, {"two", true}, {"three", false}, {"three", true} - }; - json j_mmap(c_mmap); // only one entry for key "three" is used - - // create an object from std::unordered_multimap - std::unordered_multimap c_ummap - { - {"one", true}, {"two", true}, {"three", false}, {"three", true} - }; - json j_ummap(c_ummap); // only one entry for key "three" is used - - // serialize the JSON objects - std::cout << j_object_t << '\n'; - std::cout << j_map << '\n'; - std::cout << j_umap << '\n'; - std::cout << j_mmap << '\n'; - std::cout << j_ummap << "\n\n"; - - // =========== - // array types - // =========== - - // create an array from an array_t value - json::array_t array_value = {"one", "two", 3, 4.5, false}; - json j_array_t(array_value); - - // create an array from std::vector - std::vector c_vector {1, 2, 3, 4}; - json j_vec(c_vector); - - // create an array from std::valarray - std::valarray c_valarray {10, 9, 8, 7}; - json j_valarray(c_valarray); - - // create an array from std::deque - std::deque c_deque {1.2, 2.3, 3.4, 5.6}; - json j_deque(c_deque); - - // create an array from std::list - std::list c_list {true, true, false, true}; - json j_list(c_list); - - // create an array from std::forward_list - std::forward_list c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543}; - json j_flist(c_flist); - - // create an array from std::array - std::array c_array {{1, 2, 3, 4}}; - json j_array(c_array); - - // create an array from std::set - std::set c_set {"one", "two", "three", "four", "one"}; - json j_set(c_set); // only one entry for "one" is used - - // create an array from std::unordered_set - std::unordered_set c_uset {"one", "two", "three", "four", "one"}; - json j_uset(c_uset); // only one entry for "one" is used - - // create an array from std::multiset - std::multiset c_mset {"one", "two", "one", "four"}; - json j_mset(c_mset); // both entries for "one" are used - - // create an array from std::unordered_multiset - std::unordered_multiset c_umset {"one", "two", "one", "four"}; - json j_umset(c_umset); // both entries for "one" are used - - // serialize the JSON arrays - std::cout << j_array_t << '\n'; - std::cout << j_vec << '\n'; - std::cout << j_valarray << '\n'; - std::cout << j_deque << '\n'; - std::cout << j_list << '\n'; - std::cout << j_flist << '\n'; - std::cout << j_array << '\n'; - std::cout << j_set << '\n'; - std::cout << j_uset << '\n'; - std::cout << j_mset << '\n'; - std::cout << j_umset << "\n\n"; - - // ============ - // string types - // ============ - - // create string from a string_t value - json::string_t string_value = "The quick brown fox jumps over the lazy dog."; - json j_string_t(string_value); - - // create a JSON string directly from a string literal - json j_string_literal("The quick brown fox jumps over the lazy dog."); - - // create string from std::string - std::string s_stdstring = "The quick brown fox jumps over the lazy dog."; - json j_stdstring(s_stdstring); - - // serialize the JSON strings - std::cout << j_string_t << '\n'; - std::cout << j_string_literal << '\n'; - std::cout << j_stdstring << "\n\n"; - - // ============ - // number types - // ============ - - // create a JSON number from number_integer_t - json::number_integer_t value_integer_t = -42; - json j_integer_t(value_integer_t); - - // create a JSON number from number_unsigned_t - json::number_integer_t value_unsigned_t = 17; - json j_unsigned_t(value_unsigned_t); - - // create a JSON number from an anonymous enum - enum { enum_value = 17 }; - json j_enum(enum_value); - - // create values of different integer types - short n_short = 42; - int n_int = -23; - long n_long = 1024; - int_least32_t n_int_least32_t = -17; - uint8_t n_uint8_t = 8; - - // create (integer) JSON numbers - json j_short(n_short); - json j_int(n_int); - json j_long(n_long); - json j_int_least32_t(n_int_least32_t); - json j_uint8_t(n_uint8_t); - - // create values of different floating-point types - json::number_float_t v_ok = 3.141592653589793; - json::number_float_t v_nan = NAN; - json::number_float_t v_infinity = INFINITY; - - // create values of different floating-point types - float n_float = 42.23; - float n_float_nan = 1.0f / 0.0f; - double n_double = 23.42; - - // create (floating point) JSON numbers - json j_ok(v_ok); - json j_nan(v_nan); - json j_infinity(v_infinity); - json j_float(n_float); - json j_float_nan(n_float_nan); - json j_double(n_double); - - // serialize the JSON numbers - std::cout << j_integer_t << '\n'; - std::cout << j_unsigned_t << '\n'; - std::cout << j_enum << '\n'; - std::cout << j_short << '\n'; - std::cout << j_int << '\n'; - std::cout << j_long << '\n'; - std::cout << j_int_least32_t << '\n'; - std::cout << j_uint8_t << '\n'; - std::cout << j_ok << '\n'; - std::cout << j_nan << '\n'; - std::cout << j_infinity << '\n'; - std::cout << j_float << '\n'; - std::cout << j_float_nan << '\n'; - std::cout << j_double << "\n\n"; - - // ============= - // boolean types - // ============= - - // create boolean values - json j_truth = true; - json j_falsity = false; - - // serialize the JSON booleans - std::cout << j_truth << '\n'; - std::cout << j_falsity << '\n'; +int main() { + // ============ + // object types + // ============ + + // create an object from an object_t value + json::object_t object_value = {{"one", 1}, {"two", 2}}; + json j_object_t(object_value); + + // create an object from std::map + std::map c_map{{"one", 1}, {"two", 2}, {"three", 3}}; + json j_map(c_map); + + // create an object from std::unordered_map + std::unordered_map c_umap{ + {"one", 1.2}, {"two", 2.3}, {"three", 3.4}}; + json j_umap(c_umap); + + // create an object from std::multimap + std::multimap c_mmap{ + {"one", true}, {"two", true}, {"three", false}, {"three", true}}; + json j_mmap(c_mmap); // only one entry for key "three" is used + + // create an object from std::unordered_multimap + std::unordered_multimap c_ummap{ + {"one", true}, {"two", true}, {"three", false}, {"three", true}}; + json j_ummap(c_ummap); // only one entry for key "three" is used + + // serialize the JSON objects + std::cout << j_object_t << '\n'; + std::cout << j_map << '\n'; + std::cout << j_umap << '\n'; + std::cout << j_mmap << '\n'; + std::cout << j_ummap << "\n\n"; + + // =========== + // array types + // =========== + + // create an array from an array_t value + json::array_t array_value = {"one", "two", 3, 4.5, false}; + json j_array_t(array_value); + + // create an array from std::vector + std::vector c_vector{1, 2, 3, 4}; + json j_vec(c_vector); + + // create an array from std::valarray + std::valarray c_valarray{10, 9, 8, 7}; + json j_valarray(c_valarray); + + // create an array from std::deque + std::deque c_deque{1.2, 2.3, 3.4, 5.6}; + json j_deque(c_deque); + + // create an array from std::list + std::list c_list{true, true, false, true}; + json j_list(c_list); + + // create an array from std::forward_list + std::forward_list c_flist{12345678909876, 23456789098765, + 34567890987654, 45678909876543}; + json j_flist(c_flist); + + // create an array from std::array + std::array c_array{{1, 2, 3, 4}}; + json j_array(c_array); + + // create an array from std::set + std::set c_set{"one", "two", "three", "four", "one"}; + json j_set(c_set); // only one entry for "one" is used + + // create an array from std::unordered_set + std::unordered_set c_uset{"one", "two", "three", "four", "one"}; + json j_uset(c_uset); // only one entry for "one" is used + + // create an array from std::multiset + std::multiset c_mset{"one", "two", "one", "four"}; + json j_mset(c_mset); // both entries for "one" are used + + // create an array from std::unordered_multiset + std::unordered_multiset c_umset{"one", "two", "one", "four"}; + json j_umset(c_umset); // both entries for "one" are used + + // serialize the JSON arrays + std::cout << j_array_t << '\n'; + std::cout << j_vec << '\n'; + std::cout << j_valarray << '\n'; + std::cout << j_deque << '\n'; + std::cout << j_list << '\n'; + std::cout << j_flist << '\n'; + std::cout << j_array << '\n'; + std::cout << j_set << '\n'; + std::cout << j_uset << '\n'; + std::cout << j_mset << '\n'; + std::cout << j_umset << "\n\n"; + + // ============ + // string types + // ============ + + // create string from a string_t value + json::string_t string_value = "The quick brown fox jumps over the lazy dog."; + json j_string_t(string_value); + + // create a JSON string directly from a string literal + json j_string_literal("The quick brown fox jumps over the lazy dog."); + + // create string from std::string + std::string s_stdstring = "The quick brown fox jumps over the lazy dog."; + json j_stdstring(s_stdstring); + + // serialize the JSON strings + std::cout << j_string_t << '\n'; + std::cout << j_string_literal << '\n'; + std::cout << j_stdstring << "\n\n"; + + // ============ + // number types + // ============ + + // create a JSON number from number_integer_t + json::number_integer_t value_integer_t = -42; + json j_integer_t(value_integer_t); + + // create a JSON number from number_unsigned_t + json::number_integer_t value_unsigned_t = 17; + json j_unsigned_t(value_unsigned_t); + + // create a JSON number from an anonymous enum + enum { enum_value = 17 }; + json j_enum(enum_value); + + // create values of different integer types + short n_short = 42; + int n_int = -23; + long n_long = 1024; + int_least32_t n_int_least32_t = -17; + uint8_t n_uint8_t = 8; + + // create (integer) JSON numbers + json j_short(n_short); + json j_int(n_int); + json j_long(n_long); + json j_int_least32_t(n_int_least32_t); + json j_uint8_t(n_uint8_t); + + // create values of different floating-point types + json::number_float_t v_ok = 3.141592653589793; + json::number_float_t v_nan = NAN; + json::number_float_t v_infinity = INFINITY; + + // create values of different floating-point types + float n_float = 42.23; + float n_float_nan = 1.0f / 0.0f; + double n_double = 23.42; + + // create (floating point) JSON numbers + json j_ok(v_ok); + json j_nan(v_nan); + json j_infinity(v_infinity); + json j_float(n_float); + json j_float_nan(n_float_nan); + json j_double(n_double); + + // serialize the JSON numbers + std::cout << j_integer_t << '\n'; + std::cout << j_unsigned_t << '\n'; + std::cout << j_enum << '\n'; + std::cout << j_short << '\n'; + std::cout << j_int << '\n'; + std::cout << j_long << '\n'; + std::cout << j_int_least32_t << '\n'; + std::cout << j_uint8_t << '\n'; + std::cout << j_ok << '\n'; + std::cout << j_nan << '\n'; + std::cout << j_infinity << '\n'; + std::cout << j_float << '\n'; + std::cout << j_float_nan << '\n'; + std::cout << j_double << "\n\n"; + + // ============= + // boolean types + // ============= + + // create boolean values + json j_truth = true; + json j_falsity = false; + + // serialize the JSON booleans + std::cout << j_truth << '\n'; + std::cout << j_falsity << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__InputIt_InputIt.cpp b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__InputIt_InputIt.cpp index dec693c8..d2f4e3df 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__InputIt_InputIt.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__InputIt_InputIt.cpp @@ -3,30 +3,26 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_array = {"alpha", "bravo", "charly", "delta", "easy"}; - json j_number = 42; - json j_object = {{"one", "eins"}, {"two", "zwei"}}; +int main() { + // create JSON values + json j_array = {"alpha", "bravo", "charly", "delta", "easy"}; + json j_number = 42; + json j_object = {{"one", "eins"}, {"two", "zwei"}}; - // create copies using iterators - json j_array_range(j_array.begin() + 1, j_array.end() - 2); - json j_number_range(j_number.begin(), j_number.end()); - json j_object_range(j_object.begin(), j_object.find("two")); + // create copies using iterators + json j_array_range(j_array.begin() + 1, j_array.end() - 2); + json j_number_range(j_number.begin(), j_number.end()); + json j_object_range(j_object.begin(), j_object.find("two")); - // serialize the values - std::cout << j_array_range << '\n'; - std::cout << j_number_range << '\n'; - std::cout << j_object_range << '\n'; + // serialize the values + std::cout << j_array_range << '\n'; + std::cout << j_number_range << '\n'; + std::cout << j_object_range << '\n'; - // example for an exception - try - { - json j_invalid(j_number.begin() + 1, j_number.end()); - } - catch (const json::invalid_iterator& e) - { - std::cout << e.what() << '\n'; - } + // example for an exception + try { + json j_invalid(j_number.begin() + 1, j_number.end()); + } catch (const json::invalid_iterator &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__basic_json.cpp b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__basic_json.cpp index 17136f43..7f41f0b2 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__basic_json.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__basic_json.cpp @@ -3,15 +3,14 @@ using json = nlohmann::json; -int main() -{ - // create a JSON array - json j1 = {"one", "two", 3, 4.5, false}; +int main() { + // create a JSON array + json j1 = {"one", "two", 3, 4.5, false}; - // create a copy - json j2(j1); + // create a copy + json j2(j1); - // serialize the JSON array - std::cout << j1 << " = " << j2 << '\n'; - std::cout << std::boolalpha << (j1 == j2) << '\n'; + // serialize the JSON array + std::cout << j1 << " = " << j2 << '\n'; + std::cout << std::boolalpha << (j1 == j2) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__copyassignment.cpp b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__copyassignment.cpp index 2d865740..58cfd6fe 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__copyassignment.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__copyassignment.cpp @@ -3,16 +3,15 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json a = 23; - json b = 42; +int main() { + // create JSON values + json a = 23; + json b = 42; - // copy-assign a to b - b = a; + // copy-assign a to b + b = a; - // serialize the JSON arrays - std::cout << a << '\n'; - std::cout << b << '\n'; + // serialize the JSON arrays + std::cout << a << '\n'; + std::cout << b << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__list_init_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__list_init_t.cpp index 78611e1a..162d70ca 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__list_init_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__list_init_t.cpp @@ -3,19 +3,18 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_empty_init_list = json({}); - json j_object = { {"one", 1}, {"two", 2} }; - json j_array = {1, 2, 3, 4}; - json j_nested_object = { {"one", {1}}, {"two", {1, 2}} }; - json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} }; +int main() { + // create JSON values + json j_empty_init_list = json({}); + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 3, 4}; + json j_nested_object = {{"one", {1}}, {"two", {1, 2}}}; + json j_nested_array = {{{1}, "one"}, {{1, 2}, "two"}}; - // serialize the JSON value - std::cout << j_empty_init_list << '\n'; - std::cout << j_object << '\n'; - std::cout << j_array << '\n'; - std::cout << j_nested_object << '\n'; - std::cout << j_nested_array << '\n'; + // serialize the JSON value + std::cout << j_empty_init_list << '\n'; + std::cout << j_object << '\n'; + std::cout << j_array << '\n'; + std::cout << j_nested_object << '\n'; + std::cout << j_nested_array << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__moveconstructor.cpp b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__moveconstructor.cpp index 48b68f61..e42f2753 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__moveconstructor.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__moveconstructor.cpp @@ -3,15 +3,14 @@ using json = nlohmann::json; -int main() -{ - // create a JSON value - json a = 23; +int main() { + // create a JSON value + json a = 23; - // move contents of a to b - json b(std::move(a)); + // move contents of a to b + json b(std::move(a)); - // serialize the JSON arrays - std::cout << a << '\n'; - std::cout << b << '\n'; + // serialize the JSON arrays + std::cout << a << '\n'; + std::cout << b << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__nullptr_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__nullptr_t.cpp index 7a436665..d9bceb70 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__nullptr_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__nullptr_t.cpp @@ -3,14 +3,13 @@ using json = nlohmann::json; -int main() -{ - // implicitly create a JSON null value - json j1; +int main() { + // implicitly create a JSON null value + json j1; - // explicitly create a JSON null value - json j2(nullptr); + // explicitly create a JSON null value + json j2(nullptr); - // serialize the JSON null value - std::cout << j1 << '\n' << j2 << '\n'; + // serialize the JSON null value + std::cout << j1 << '\n' << j2 << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__size_type_basic_json.cpp b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__size_type_basic_json.cpp index 9ec76772..d408b45c 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__size_type_basic_json.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__size_type_basic_json.cpp @@ -3,16 +3,15 @@ using json = nlohmann::json; -int main() -{ - // create an array by creating copies of a JSON value - json value = "Hello"; - json array_0 = json(0, value); - json array_1 = json(1, value); - json array_5 = json(5, value); +int main() { + // create an array by creating copies of a JSON value + json value = "Hello"; + json array_0 = json(0, value); + json array_1 = json(1, value); + json array_5 = json(5, value); - // serialize the JSON arrays - std::cout << array_0 << '\n'; - std::cout << array_1 << '\n'; - std::cout << array_5 << '\n'; + // serialize the JSON arrays + std::cout << array_0 << '\n'; + std::cout << array_1 << '\n'; + std::cout << array_5 << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__value_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__value_t.cpp index c306731a..7927eee9 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/basic_json__value_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/basic_json__value_t.cpp @@ -3,23 +3,22 @@ using json = nlohmann::json; -int main() -{ - // create the different JSON values with default values - json j_null(json::value_t::null); - json j_boolean(json::value_t::boolean); - json j_number_integer(json::value_t::number_integer); - json j_number_float(json::value_t::number_float); - json j_object(json::value_t::object); - json j_array(json::value_t::array); - json j_string(json::value_t::string); +int main() { + // create the different JSON values with default values + json j_null(json::value_t::null); + json j_boolean(json::value_t::boolean); + json j_number_integer(json::value_t::number_integer); + json j_number_float(json::value_t::number_float); + json j_object(json::value_t::object); + json j_array(json::value_t::array); + json j_string(json::value_t::string); - // serialize the JSON values - std::cout << j_null << '\n'; - std::cout << j_boolean << '\n'; - std::cout << j_number_integer << '\n'; - std::cout << j_number_float << '\n'; - std::cout << j_object << '\n'; - std::cout << j_array << '\n'; - std::cout << j_string << '\n'; + // serialize the JSON values + std::cout << j_null << '\n'; + std::cout << j_boolean << '\n'; + std::cout << j_number_integer << '\n'; + std::cout << j_number_float << '\n'; + std::cout << j_object << '\n'; + std::cout << j_array << '\n'; + std::cout << j_string << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/begin.cpp b/nlohmann_json/docs/mkdocs/docs/examples/begin.cpp index 654835b0..034b230a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/begin.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/begin.cpp @@ -3,14 +3,13 @@ using json = nlohmann::json; -int main() -{ - // create an array value - json array = {1, 2, 3, 4, 5}; +int main() { + // create an array value + json array = {1, 2, 3, 4, 5}; - // get an iterator to the first element - json::iterator it = array.begin(); + // get an iterator to the first element + json::iterator it = array.begin(); - // serialize the element that the iterator points to - std::cout << *it << '\n'; + // serialize the element that the iterator points to + std::cout << *it << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/binary.cpp b/nlohmann_json/docs/mkdocs/docs/examples/binary.cpp index 617ce609..acfc2019 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/binary.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/binary.cpp @@ -3,14 +3,14 @@ using json = nlohmann::json; -int main() -{ - // create a binary vector - std::vector vec = {0xCA, 0xFE, 0xBA, 0xBE}; +int main() { + // create a binary vector + std::vector vec = {0xCA, 0xFE, 0xBA, 0xBE}; - // create a binary JSON value with subtype 42 - json j = json::binary(vec, 42); + // create a binary JSON value with subtype 42 + json j = json::binary(vec, 42); - // output type and subtype - std::cout << "type: " << j.type_name() << ", subtype: " << j.get_binary().subtype() << std::endl; + // output type and subtype + std::cout << "type: " << j.type_name() + << ", subtype: " << j.get_binary().subtype() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/binary_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/binary_t.cpp index bfaee5ca..08f09801 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/binary_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/binary_t.cpp @@ -1,10 +1,14 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - std::cout << std::boolalpha << std::is_same>, json::binary_t>::value << std::endl; +int main() { + std::cout + << std::boolalpha + << std::is_same< + nlohmann::byte_container_with_subtype>, + json::binary_t>::value + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/boolean_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/boolean_t.cpp index 75b8c99f..582f8911 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/boolean_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/boolean_t.cpp @@ -1,10 +1,10 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - std::cout << std::boolalpha << std::is_same::value << std::endl; +int main() { + std::cout << std::boolalpha << std::is_same::value + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__byte_container_with_subtype.cpp b/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__byte_container_with_subtype.cpp index 1c10be5c..10050798 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__byte_container_with_subtype.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__byte_container_with_subtype.cpp @@ -2,22 +2,22 @@ #include // define a byte container based on std::vector -using byte_container_with_subtype = nlohmann::byte_container_with_subtype>; +using byte_container_with_subtype = + nlohmann::byte_container_with_subtype>; using json = nlohmann::json; -int main() -{ - // (1) create empty container - auto c1 = byte_container_with_subtype(); +int main() { + // (1) create empty container + auto c1 = byte_container_with_subtype(); - std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; + std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; - // (2) create container - auto c2 = byte_container_with_subtype(bytes); + // (2) create container + auto c2 = byte_container_with_subtype(bytes); - // (3) create container with subtype - auto c3 = byte_container_with_subtype(bytes, 42); + // (3) create container with subtype + auto c3 = byte_container_with_subtype(bytes, 42); - std::cout << json(c1) << "\n" << json(c2) << "\n" << json(c3) << std::endl; + std::cout << json(c1) << "\n" << json(c2) << "\n" << json(c3) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__clear_subtype.cpp b/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__clear_subtype.cpp index f9ce6842..eb993d52 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__clear_subtype.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__clear_subtype.cpp @@ -2,20 +2,20 @@ #include // define a byte container based on std::vector -using byte_container_with_subtype = nlohmann::byte_container_with_subtype>; +using byte_container_with_subtype = + nlohmann::byte_container_with_subtype>; using json = nlohmann::json; -int main() -{ - std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; +int main() { + std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; - // create container with subtype - auto c1 = byte_container_with_subtype(bytes, 42); + // create container with subtype + auto c1 = byte_container_with_subtype(bytes, 42); - std::cout << "before calling clear_subtype(): " << json(c1) << '\n'; + std::cout << "before calling clear_subtype(): " << json(c1) << '\n'; - c1.clear_subtype(); + c1.clear_subtype(); - std::cout << "after calling clear_subtype(): " << json(c1) << '\n'; + std::cout << "after calling clear_subtype(): " << json(c1) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__has_subtype.cpp b/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__has_subtype.cpp index 61c21eaa..a6da3024 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__has_subtype.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__has_subtype.cpp @@ -2,18 +2,18 @@ #include // define a byte container based on std::vector -using byte_container_with_subtype = nlohmann::byte_container_with_subtype>; +using byte_container_with_subtype = + nlohmann::byte_container_with_subtype>; -int main() -{ - std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; +int main() { + std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; - // create container - auto c1 = byte_container_with_subtype(bytes); + // create container + auto c1 = byte_container_with_subtype(bytes); - // create container with subtype - auto c2 = byte_container_with_subtype(bytes, 42); + // create container with subtype + auto c2 = byte_container_with_subtype(bytes, 42); - std::cout << std::boolalpha << "c1.has_subtype() = " << c1.has_subtype() - << "\nc2.has_subtype() = " << c2.has_subtype() << std::endl; + std::cout << std::boolalpha << "c1.has_subtype() = " << c1.has_subtype() + << "\nc2.has_subtype() = " << c2.has_subtype() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__set_subtype.cpp b/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__set_subtype.cpp index b2694c54..36e4d8b6 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__set_subtype.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__set_subtype.cpp @@ -2,21 +2,21 @@ #include // define a byte container based on std::vector -using byte_container_with_subtype = nlohmann::byte_container_with_subtype>; +using byte_container_with_subtype = + nlohmann::byte_container_with_subtype>; using json = nlohmann::json; -int main() -{ - std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; +int main() { + std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; - // create container without subtype - auto c = byte_container_with_subtype(bytes); + // create container without subtype + auto c = byte_container_with_subtype(bytes); - std::cout << "before calling set_subtype(42): " << json(c) << '\n'; + std::cout << "before calling set_subtype(42): " << json(c) << '\n'; - // set the subtype - c.set_subtype(42); + // set the subtype + c.set_subtype(42); - std::cout << "after calling set_subtype(42): " << json(c) << '\n'; + std::cout << "after calling set_subtype(42): " << json(c) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__subtype.cpp b/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__subtype.cpp index cd230ade..96ab684a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__subtype.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/byte_container_with_subtype__subtype.cpp @@ -2,21 +2,22 @@ #include // define a byte container based on std::vector -using byte_container_with_subtype = nlohmann::byte_container_with_subtype>; +using byte_container_with_subtype = + nlohmann::byte_container_with_subtype>; -int main() -{ - std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; +int main() { + std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; - // create container - auto c1 = byte_container_with_subtype(bytes); + // create container + auto c1 = byte_container_with_subtype(bytes); - // create container with subtype - auto c2 = byte_container_with_subtype(bytes, 42); + // create container with subtype + auto c2 = byte_container_with_subtype(bytes, 42); - std::cout << "c1.subtype() = " << c1.subtype() - << "\nc2.subtype() = " << c2.subtype() << std::endl; + std::cout << "c1.subtype() = " << c1.subtype() + << "\nc2.subtype() = " << c2.subtype() << std::endl; - // in case no subtype is set, return special value - assert(c1.subtype() == static_cast(-1)); + // in case no subtype is set, return special value + assert(c1.subtype() == + static_cast(-1)); } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/cbegin.cpp b/nlohmann_json/docs/mkdocs/docs/examples/cbegin.cpp index bed2b372..eaefd191 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/cbegin.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/cbegin.cpp @@ -3,14 +3,13 @@ using json = nlohmann::json; -int main() -{ - // create an array value - const json array = {1, 2, 3, 4, 5}; +int main() { + // create an array value + const json array = {1, 2, 3, 4, 5}; - // get an iterator to the first element - json::const_iterator it = array.cbegin(); + // get an iterator to the first element + json::const_iterator it = array.cbegin(); - // serialize the element that the iterator points to - std::cout << *it << '\n'; + // serialize the element that the iterator points to + std::cout << *it << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/cbor_tag_handler_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/cbor_tag_handler_t.cpp index 38d168ca..7e6d1bd0 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/cbor_tag_handler_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/cbor_tag_handler_t.cpp @@ -3,26 +3,25 @@ using json = nlohmann::json; -int main() -{ - // tagged byte string - std::vector vec = {{0xd8, 0x42, 0x44, 0xcA, 0xfe, 0xba, 0xbe}}; +int main() { + // tagged byte string + std::vector vec = {{0xd8, 0x42, 0x44, 0xcA, 0xfe, 0xba, 0xbe}}; - // cbor_tag_handler_t::error throws - try - { - auto b_throw_on_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::error); - } - catch (const json::parse_error& e) - { - std::cout << e.what() << std::endl; - } + // cbor_tag_handler_t::error throws + try { + auto b_throw_on_tag = + json::from_cbor(vec, true, true, json::cbor_tag_handler_t::error); + } catch (const json::parse_error &e) { + std::cout << e.what() << std::endl; + } - // cbor_tag_handler_t::ignore ignores the tag - auto b_ignore_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::ignore); - std::cout << b_ignore_tag << std::endl; + // cbor_tag_handler_t::ignore ignores the tag + auto b_ignore_tag = + json::from_cbor(vec, true, true, json::cbor_tag_handler_t::ignore); + std::cout << b_ignore_tag << std::endl; - // cbor_tag_handler_t::store stores the tag as binary subtype - auto b_store_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::store); - std::cout << b_store_tag << std::endl; + // cbor_tag_handler_t::store stores the tag as binary subtype + auto b_store_tag = + json::from_cbor(vec, true, true, json::cbor_tag_handler_t::store); + std::cout << b_store_tag << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/cend.cpp b/nlohmann_json/docs/mkdocs/docs/examples/cend.cpp index 3050f500..3449bc7e 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/cend.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/cend.cpp @@ -3,17 +3,16 @@ using json = nlohmann::json; -int main() -{ - // create an array value - json array = {1, 2, 3, 4, 5}; +int main() { + // create an array value + json array = {1, 2, 3, 4, 5}; - // get an iterator to one past the last element - json::const_iterator it = array.cend(); + // get an iterator to one past the last element + json::const_iterator it = array.cend(); - // decrement the iterator to point to the last element - --it; + // decrement the iterator to point to the last element + --it; - // serialize the element that the iterator points to - std::cout << *it << '\n'; + // serialize the element that the iterator points to + std::cout << *it << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/clear.cpp b/nlohmann_json/docs/mkdocs/docs/examples/clear.cpp index f081e7ed..5cd7f188 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/clear.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/clear.cpp @@ -3,32 +3,31 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; - // call clear() - j_null.clear(); - j_boolean.clear(); - j_number_integer.clear(); - j_number_float.clear(); - j_object.clear(); - j_array.clear(); - j_string.clear(); + // call clear() + j_null.clear(); + j_boolean.clear(); + j_number_integer.clear(); + j_number_float.clear(); + j_object.clear(); + j_array.clear(); + j_string.clear(); - // serialize the cleared values() - std::cout << j_null << '\n'; - std::cout << j_boolean << '\n'; - std::cout << j_number_integer << '\n'; - std::cout << j_number_float << '\n'; - std::cout << j_object << '\n'; - std::cout << j_array << '\n'; - std::cout << j_string << '\n'; + // serialize the cleared values() + std::cout << j_null << '\n'; + std::cout << j_boolean << '\n'; + std::cout << j_number_integer << '\n'; + std::cout << j_number_float << '\n'; + std::cout << j_object << '\n'; + std::cout << j_array << '\n'; + std::cout << j_string << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/comments.cpp b/nlohmann_json/docs/mkdocs/docs/examples/comments.cpp deleted file mode 100644 index fc8a0ac3..00000000 --- a/nlohmann_json/docs/mkdocs/docs/examples/comments.cpp +++ /dev/null @@ -1,31 +0,0 @@ - -#include -#include - -using json = nlohmann::json; - -int main() -{ - std::string s = R"( - { - // update in 2006: removed Pluto - "planets": ["Mercury", "Venus", "Earth", "Mars", - "Jupiter", "Uranus", "Neptune" /*, "Pluto" */] - } - )"; - - try - { - json j = json::parse(s); - } - catch (json::exception& e) - { - std::cout << e.what() << std::endl; - } - - json j = json::parse(s, - /* callback */ nullptr, - /* allow exceptions */ true, - /* ignore_comments */ true); - std::cout << j.dump(2) << '\n'; -} diff --git a/nlohmann_json/docs/mkdocs/docs/examples/comments.output b/nlohmann_json/docs/mkdocs/docs/examples/comments.output deleted file mode 100644 index 6e0d1c46..00000000 --- a/nlohmann_json/docs/mkdocs/docs/examples/comments.output +++ /dev/null @@ -1,12 +0,0 @@ -[json.exception.parse_error.101] parse error at line 3, column 9: syntax error while parsing object key - invalid literal; last read: ' { /'; expected string literal -{ - "planets": [ - "Mercury", - "Venus", - "Earth", - "Mars", - "Jupiter", - "Uranus", - "Neptune" - ] -} diff --git a/nlohmann_json/docs/mkdocs/docs/examples/contains__json_pointer.cpp b/nlohmann_json/docs/mkdocs/docs/examples/contains__json_pointer.cpp index 14d8514b..2f1874e9 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/contains__json_pointer.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/contains__json_pointer.cpp @@ -4,40 +4,29 @@ using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create a JSON value - json j = - { - {"number", 1}, {"string", "foo"}, {"array", {1, 2}} - }; +int main() { + // create a JSON value + json j = {{"number", 1}, {"string", "foo"}, {"array", {1, 2}}}; - std::cout << std::boolalpha - << j.contains("/number"_json_pointer) << '\n' - << j.contains("/string"_json_pointer) << '\n' - << j.contains("/array"_json_pointer) << '\n' - << j.contains("/array/1"_json_pointer) << '\n' - << j.contains("/array/-"_json_pointer) << '\n' - << j.contains("/array/4"_json_pointer) << '\n' - << j.contains("/baz"_json_pointer) << std::endl; + std::cout << std::boolalpha << j.contains("/number"_json_pointer) << '\n' + << j.contains("/string"_json_pointer) << '\n' + << j.contains("/array"_json_pointer) << '\n' + << j.contains("/array/1"_json_pointer) << '\n' + << j.contains("/array/-"_json_pointer) << '\n' + << j.contains("/array/4"_json_pointer) << '\n' + << j.contains("/baz"_json_pointer) << std::endl; - try - { - // try to use an array index with leading '0' - j.contains("/array/01"_json_pointer); - } - catch (const json::parse_error& e) - { - std::cout << e.what() << '\n'; - } + try { + // try to use an array index with leading '0' + j.contains("/array/01"_json_pointer); + } catch (const json::parse_error &e) { + std::cout << e.what() << '\n'; + } - try - { - // try to use an array index that is not a number - j.contains("/array/one"_json_pointer); - } - catch (const json::parse_error& e) - { - std::cout << e.what() << '\n'; - } + try { + // try to use an array index that is not a number + j.contains("/array/one"_json_pointer); + } catch (const json::parse_error &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/contains__keytype.c++17.cpp b/nlohmann_json/docs/mkdocs/docs/examples/contains__keytype.c++17.cpp index 43b62fab..894e6bbd 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/contains__keytype.c++17.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/contains__keytype.c++17.cpp @@ -1,20 +1,21 @@ #include -#include #include +#include using namespace std::string_view_literals; using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create some JSON values - json j_object = R"( {"key": "value"} )"_json; - json j_array = R"( [1, 2, 3] )"_json; +int main() { + // create some JSON values + json j_object = R"( {"key": "value"} )"_json; + json j_array = R"( [1, 2, 3] )"_json; - // call contains - std::cout << std::boolalpha << - "j_object contains 'key': " << j_object.contains("key"sv) << '\n' << - "j_object contains 'another': " << j_object.contains("another"sv) << '\n' << - "j_array contains 'key': " << j_array.contains("key"sv) << std::endl; + // call contains + std::cout << std::boolalpha + << "j_object contains 'key': " << j_object.contains("key"sv) << '\n' + << "j_object contains 'another': " << j_object.contains("another"sv) + << '\n' + << "j_array contains 'key': " << j_array.contains("key"sv) + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/contains__object_t_key_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/contains__object_t_key_type.cpp index a8bc8143..27fb33ce 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/contains__object_t_key_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/contains__object_t_key_type.cpp @@ -4,15 +4,16 @@ using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create some JSON values - json j_object = R"( {"key": "value"} )"_json; - json j_array = R"( [1, 2, 3] )"_json; +int main() { + // create some JSON values + json j_object = R"( {"key": "value"} )"_json; + json j_array = R"( [1, 2, 3] )"_json; - // call contains - std::cout << std::boolalpha << - "j_object contains 'key': " << j_object.contains("key") << '\n' << - "j_object contains 'another': " << j_object.contains("another") << '\n' << - "j_array contains 'key': " << j_array.contains("key") << std::endl; + // call contains + std::cout << std::boolalpha + << "j_object contains 'key': " << j_object.contains("key") << '\n' + << "j_object contains 'another': " << j_object.contains("another") + << '\n' + << "j_array contains 'key': " << j_array.contains("key") + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/count__keytype.c++17.cpp b/nlohmann_json/docs/mkdocs/docs/examples/count__keytype.c++17.cpp index ec6de060..2b671aef 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/count__keytype.c++17.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/count__keytype.c++17.cpp @@ -1,20 +1,19 @@ #include -#include #include +#include using namespace std::string_view_literals; using json = nlohmann::json; -int main() -{ - // create a JSON object - json j_object = {{"one", 1}, {"two", 2}}; +int main() { + // create a JSON object + json j_object = {{"one", 1}, {"two", 2}}; - // call count() - auto count_two = j_object.count("two"sv); - auto count_three = j_object.count("three"sv); + // call count() + auto count_two = j_object.count("two"sv); + auto count_three = j_object.count("three"sv); - // print values - std::cout << "number of elements with key \"two\": " << count_two << '\n'; - std::cout << "number of elements with key \"three\": " << count_three << '\n'; + // print values + std::cout << "number of elements with key \"two\": " << count_two << '\n'; + std::cout << "number of elements with key \"three\": " << count_three << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/count__object_t_key_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/count__object_t_key_type.cpp index a8d54b9d..fa848dda 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/count__object_t_key_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/count__object_t_key_type.cpp @@ -3,16 +3,15 @@ using json = nlohmann::json; -int main() -{ - // create a JSON object - json j_object = {{"one", 1}, {"two", 2}}; +int main() { + // create a JSON object + json j_object = {{"one", 1}, {"two", 2}}; - // call count() - auto count_two = j_object.count("two"); - auto count_three = j_object.count("three"); + // call count() + auto count_two = j_object.count("two"); + auto count_three = j_object.count("three"); - // print values - std::cout << "number of elements with key \"two\": " << count_two << '\n'; - std::cout << "number of elements with key \"three\": " << count_three << '\n'; + // print values + std::cout << "number of elements with key \"two\": " << count_two << '\n'; + std::cout << "number of elements with key \"three\": " << count_three << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/crbegin.cpp b/nlohmann_json/docs/mkdocs/docs/examples/crbegin.cpp index dc3209cf..df93777f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/crbegin.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/crbegin.cpp @@ -3,14 +3,13 @@ using json = nlohmann::json; -int main() -{ - // create an array value - json array = {1, 2, 3, 4, 5}; +int main() { + // create an array value + json array = {1, 2, 3, 4, 5}; - // get an iterator to the reverse-beginning - json::const_reverse_iterator it = array.crbegin(); + // get an iterator to the reverse-beginning + json::const_reverse_iterator it = array.crbegin(); - // serialize the element that the iterator points to - std::cout << *it << '\n'; + // serialize the element that the iterator points to + std::cout << *it << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/crend.cpp b/nlohmann_json/docs/mkdocs/docs/examples/crend.cpp index dff26093..06c99614 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/crend.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/crend.cpp @@ -3,17 +3,16 @@ using json = nlohmann::json; -int main() -{ - // create an array value - json array = {1, 2, 3, 4, 5}; +int main() { + // create an array value + json array = {1, 2, 3, 4, 5}; - // get an iterator to the reverse-end - json::const_reverse_iterator it = array.crend(); + // get an iterator to the reverse-end + json::const_reverse_iterator it = array.crend(); - // increment the iterator to point to the first element - --it; + // increment the iterator to point to the first element + --it; - // serialize the element that the iterator points to - std::cout << *it << '\n'; + // serialize the element that the iterator points to + std::cout << *it << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/default_object_comparator_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/default_object_comparator_t.cpp index 9f200fe6..273b7355 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/default_object_comparator_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/default_object_comparator_t.cpp @@ -3,9 +3,10 @@ using json = nlohmann::json; -int main() -{ - std::cout << std::boolalpha - << "one < two : " << json::default_object_comparator_t{}("one", "two") << "\n" - << "three < four : " << json::default_object_comparator_t{}("three", "four") << std::endl; +int main() { + std::cout << std::boolalpha << "one < two : " + << json::default_object_comparator_t{}("one", "two") << "\n" + << "three < four : " + << json::default_object_comparator_t{}("three", "four") + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/diagnostic_positions.cpp b/nlohmann_json/docs/mkdocs/docs/examples/diagnostic_positions.cpp index 259344cd..b5b3c980 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/diagnostic_positions.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/diagnostic_positions.cpp @@ -5,9 +5,8 @@ using json = nlohmann::json; -int main() -{ - std::string json_string = R"( +int main() { + std::string json_string = R"( { "address": { "street": "Fake Street", @@ -15,37 +14,54 @@ int main() } } )"; - json j = json::parse(json_string); + json j = json::parse(json_string); - std::cout << "Root diagnostic positions: \n"; - std::cout << "\tstart_pos: " << j.start_pos() << '\n'; - std::cout << "\tend_pos:" << j.end_pos() << "\n"; - std::cout << "Original string: \n"; - std::cout << "{\n \"address\": {\n \"street\": \"Fake Street\",\n \"housenumber\": 1\n }\n }" << "\n"; - std::cout << "Parsed string: \n"; - std::cout << json_string.substr(j.start_pos(), j.end_pos() - j.start_pos()) << "\n\n"; + std::cout << "Root diagnostic positions: \n"; + std::cout << "\tstart_pos: " << j.start_pos() << '\n'; + std::cout << "\tend_pos:" << j.end_pos() << "\n"; + std::cout << "Original string: \n"; + std::cout << "{\n \"address\": {\n \"street\": \"Fake " + "Street\",\n \"housenumber\": 1\n }\n }" + << "\n"; + std::cout << "Parsed string: \n"; + std::cout << json_string.substr(j.start_pos(), j.end_pos() - j.start_pos()) + << "\n\n"; - std::cout << "address diagnostic positions: \n"; - std::cout << "\tstart_pos:" << j["address"].start_pos() << '\n'; - std::cout << "\tend_pos:" << j["address"].end_pos() << "\n\n"; - std::cout << "Original string: \n"; - std::cout << "{ \"street\": \"Fake Street\",\n \"housenumber\": 1\n }" << "\n"; - std::cout << "Parsed string: \n"; - std::cout << json_string.substr(j["address"].start_pos(), j["address"].end_pos() - j["address"].start_pos()) << "\n\n"; + std::cout << "address diagnostic positions: \n"; + std::cout << "\tstart_pos:" << j["address"].start_pos() << '\n'; + std::cout << "\tend_pos:" << j["address"].end_pos() << "\n\n"; + std::cout << "Original string: \n"; + std::cout << "{ \"street\": \"Fake Street\",\n " + "\"housenumber\": 1\n }" + << "\n"; + std::cout << "Parsed string: \n"; + std::cout << json_string.substr(j["address"].start_pos(), + j["address"].end_pos() - + j["address"].start_pos()) + << "\n\n"; - std::cout << "street diagnostic positions: \n"; - std::cout << "\tstart_pos:" << j["address"]["street"].start_pos() << '\n'; - std::cout << "\tend_pos:" << j["address"]["street"].end_pos() << "\n\n"; - std::cout << "Original string: \n"; - std::cout << "\"Fake Street\"" << "\n"; - std::cout << "Parsed string: \n"; - std::cout << json_string.substr(j["address"]["street"].start_pos(), j["address"]["street"].end_pos() - j["address"]["street"].start_pos()) << "\n\n"; + std::cout << "street diagnostic positions: \n"; + std::cout << "\tstart_pos:" << j["address"]["street"].start_pos() << '\n'; + std::cout << "\tend_pos:" << j["address"]["street"].end_pos() << "\n\n"; + std::cout << "Original string: \n"; + std::cout << "\"Fake Street\"" + << "\n"; + std::cout << "Parsed string: \n"; + std::cout << json_string.substr(j["address"]["street"].start_pos(), + j["address"]["street"].end_pos() - + j["address"]["street"].start_pos()) + << "\n\n"; - std::cout << "housenumber diagnostic positions: \n"; - std::cout << "\tstart_pos:" << j["address"]["housenumber"].start_pos() << '\n'; - std::cout << "\tend_pos:" << j["address"]["housenumber"].end_pos() << "\n\n"; - std::cout << "Original string: \n"; - std::cout << "1" << "\n"; - std::cout << "Parsed string: \n"; - std::cout << json_string.substr(j["address"]["housenumber"].start_pos(), j["address"]["housenumber"].end_pos() - j["address"]["housenumber"].start_pos()) << "\n\n"; + std::cout << "housenumber diagnostic positions: \n"; + std::cout << "\tstart_pos:" << j["address"]["housenumber"].start_pos() + << '\n'; + std::cout << "\tend_pos:" << j["address"]["housenumber"].end_pos() << "\n\n"; + std::cout << "Original string: \n"; + std::cout << "1" + << "\n"; + std::cout << "Parsed string: \n"; + std::cout << json_string.substr(j["address"]["housenumber"].start_pos(), + j["address"]["housenumber"].end_pos() - + j["address"]["housenumber"].start_pos()) + << "\n\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/diagnostic_positions_exception.cpp b/nlohmann_json/docs/mkdocs/docs/examples/diagnostic_positions_exception.cpp index ea4c4139..bd4663b4 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/diagnostic_positions_exception.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/diagnostic_positions_exception.cpp @@ -5,11 +5,11 @@ using json = nlohmann::json; -/* Demonstration of type error exception with diagnostic postions support enabled */ -int main() -{ - //Invalid json string - housenumber type must be int instead of string - const std::string json_invalid_string = R"( +/* Demonstration of type error exception with diagnostic postions support + * enabled */ +int main() { + // Invalid json string - housenumber type must be int instead of string + const std::string json_invalid_string = R"( { "address": { "street": "Fake Street", @@ -17,14 +17,11 @@ int main() } } )"; - json j = json::parse(json_invalid_string); - try - { - int housenumber = j["address"]["housenumber"]; - std::cout << housenumber; - } - catch (const json::exception& e) - { - std::cout << e.what() << '\n'; - } + json j = json::parse(json_invalid_string); + try { + int housenumber = j["address"]["housenumber"]; + std::cout << housenumber; + } catch (const json::exception &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_extended.cpp b/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_extended.cpp index 3b9f484b..638b7f3f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_extended.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_extended.cpp @@ -1,22 +1,18 @@ #include -# define JSON_DIAGNOSTICS 1 +#define JSON_DIAGNOSTICS 1 #include using json = nlohmann::json; -int main() -{ - json j; - j["address"]["street"] = "Fake Street"; - j["address"]["housenumber"] = "12"; +int main() { + json j; + j["address"]["street"] = "Fake Street"; + j["address"]["housenumber"] = "12"; - try - { - int housenumber = j["address"]["housenumber"]; - } - catch (const json::exception& e) - { - std::cout << e.what() << '\n'; - } + try { + int housenumber = j["address"]["housenumber"]; + } catch (const json::exception &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_extended_positions.cpp b/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_extended_positions.cpp index 0e0c0294..aa6aa0e9 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_extended_positions.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_extended_positions.cpp @@ -6,11 +6,11 @@ using json = nlohmann::json; -/* Demonstration of type error exception with diagnostic postions support enabled */ -int main() -{ - //Invalid json string - housenumber type must be int instead of string - const std::string json_invalid_string = R"( +/* Demonstration of type error exception with diagnostic postions support + * enabled */ +int main() { + // Invalid json string - housenumber type must be int instead of string + const std::string json_invalid_string = R"( { "address": { "street": "Fake Street", @@ -18,14 +18,11 @@ int main() } } )"; - json j = json::parse(json_invalid_string); - try - { - int housenumber = j["address"]["housenumber"]; - std::cout << housenumber; - } - catch (const json::exception& e) - { - std::cout << e.what() << '\n'; - } + json j = json::parse(json_invalid_string); + try { + int housenumber = j["address"]["housenumber"]; + std::cout << housenumber; + } catch (const json::exception &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_standard.cpp b/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_standard.cpp index eae61a4a..a025f403 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_standard.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/diagnostics_standard.cpp @@ -3,18 +3,14 @@ using json = nlohmann::json; -int main() -{ - json j; - j["address"]["street"] = "Fake Street"; - j["address"]["housenumber"] = "12"; +int main() { + json j; + j["address"]["street"] = "Fake Street"; + j["address"]["housenumber"] = "12"; - try - { - int housenumber = j["address"]["housenumber"]; - } - catch (const json::exception& e) - { - std::cout << e.what() << '\n'; - } + try { + int housenumber = j["address"]["housenumber"]; + } catch (const json::exception &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/diff.cpp b/nlohmann_json/docs/mkdocs/docs/examples/diff.cpp index ef01332a..e91e2be1 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/diff.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/diff.cpp @@ -1,22 +1,21 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // the source document - json source = R"( +int main() { + // the source document + json source = R"( { "baz": "qux", "foo": "bar" } )"_json; - // the target document - json target = R"( + // the target document + json target = R"( { "baz": "boo", "hello": [ @@ -25,13 +24,13 @@ int main() } )"_json; - // create the patch - json patch = json::diff(source, target); + // create the patch + json patch = json::diff(source, target); - // roundtrip - json patched_source = source.patch(patch); + // roundtrip + json patched_source = source.patch(patch); - // output patch and roundtrip result - std::cout << std::setw(4) << patch << "\n\n" - << std::setw(4) << patched_source << std::endl; + // output patch and roundtrip result + std::cout << std::setw(4) << patch << "\n\n" + << std::setw(4) << patched_source << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/dump.cpp b/nlohmann_json/docs/mkdocs/docs/examples/dump.cpp index 009c95fd..7c8ea11c 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/dump.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/dump.cpp @@ -3,46 +3,42 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hellö 😀!"; +int main() { + // create JSON values + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hellö 😀!"; - // call dump() - std::cout << "objects:" << '\n' - << j_object.dump() << "\n\n" - << j_object.dump(-1) << "\n\n" - << j_object.dump(0) << "\n\n" - << j_object.dump(4) << "\n\n" - << j_object.dump(1, '\t') << "\n\n"; + // call dump() + std::cout << "objects:" << '\n' + << j_object.dump() << "\n\n" + << j_object.dump(-1) << "\n\n" + << j_object.dump(0) << "\n\n" + << j_object.dump(4) << "\n\n" + << j_object.dump(1, '\t') << "\n\n"; - std::cout << "arrays:" << '\n' - << j_array.dump() << "\n\n" - << j_array.dump(-1) << "\n\n" - << j_array.dump(0) << "\n\n" - << j_array.dump(4) << "\n\n" - << j_array.dump(1, '\t') << "\n\n"; + std::cout << "arrays:" << '\n' + << j_array.dump() << "\n\n" + << j_array.dump(-1) << "\n\n" + << j_array.dump(0) << "\n\n" + << j_array.dump(4) << "\n\n" + << j_array.dump(1, '\t') << "\n\n"; - std::cout << "strings:" << '\n' - << j_string.dump() << '\n' - << j_string.dump(-1, ' ', true) << '\n'; + std::cout << "strings:" << '\n' + << j_string.dump() << '\n' + << j_string.dump(-1, ' ', true) << '\n'; - // create JSON value with invalid UTF-8 byte sequence - json j_invalid = "ä\xA9ü"; - try - { - std::cout << j_invalid.dump() << std::endl; - } - catch (const json::type_error& e) - { - std::cout << e.what() << std::endl; - } + // create JSON value with invalid UTF-8 byte sequence + json j_invalid = "ä\xA9ü"; + try { + std::cout << j_invalid.dump() << std::endl; + } catch (const json::type_error &e) { + std::cout << e.what() << std::endl; + } - std::cout << "string with replaced invalid characters: " - << j_invalid.dump(-1, ' ', false, json::error_handler_t::replace) - << "\nstring with ignored invalid characters: " - << j_invalid.dump(-1, ' ', false, json::error_handler_t::ignore) - << '\n'; + std::cout << "string with replaced invalid characters: " + << j_invalid.dump(-1, ' ', false, json::error_handler_t::replace) + << "\nstring with ignored invalid characters: " + << j_invalid.dump(-1, ' ', false, json::error_handler_t::ignore) + << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/emplace.cpp b/nlohmann_json/docs/mkdocs/docs/examples/emplace.cpp index a5314910..39919525 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/emplace.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/emplace.cpp @@ -3,29 +3,28 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json object = {{"one", 1}, {"two", 2}}; - json null; +int main() { + // create JSON values + json object = {{"one", 1}, {"two", 2}}; + json null; - // print values - std::cout << object << '\n'; - std::cout << null << '\n'; + // print values + std::cout << object << '\n'; + std::cout << null << '\n'; - // add values - auto res1 = object.emplace("three", 3); - null.emplace("A", "a"); - null.emplace("B", "b"); + // add values + auto res1 = object.emplace("three", 3); + null.emplace("A", "a"); + null.emplace("B", "b"); - // the following call will not add an object, because there is already - // a value stored at key "B" - auto res2 = null.emplace("B", "c"); + // the following call will not add an object, because there is already + // a value stored at key "B" + auto res2 = null.emplace("B", "c"); - // print values - std::cout << object << '\n'; - std::cout << *res1.first << " " << std::boolalpha << res1.second << '\n'; + // print values + std::cout << object << '\n'; + std::cout << *res1.first << " " << std::boolalpha << res1.second << '\n'; - std::cout << null << '\n'; - std::cout << *res2.first << " " << std::boolalpha << res2.second << '\n'; + std::cout << null << '\n'; + std::cout << *res2.first << " " << std::boolalpha << res2.second << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/emplace_back.cpp b/nlohmann_json/docs/mkdocs/docs/examples/emplace_back.cpp index e979a945..9455b81d 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/emplace_back.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/emplace_back.cpp @@ -3,22 +3,21 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json array = {1, 2, 3, 4, 5}; - json null; +int main() { + // create JSON values + json array = {1, 2, 3, 4, 5}; + json null; - // print values - std::cout << array << '\n'; - std::cout << null << '\n'; + // print values + std::cout << array << '\n'; + std::cout << null << '\n'; - // add values - array.emplace_back(6); - null.emplace_back("first"); - null.emplace_back(3, "second"); + // add values + array.emplace_back(6); + null.emplace_back("first"); + null.emplace_back(3, "second"); - // print values - std::cout << array << '\n'; - std::cout << null << '\n'; + // print values + std::cout << array << '\n'; + std::cout << null << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/empty.cpp b/nlohmann_json/docs/mkdocs/docs/examples/empty.cpp index 6ef6e40e..9cadf013 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/empty.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/empty.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_object_empty(json::value_t::object); - json j_array = {1, 2, 4, 8, 16}; - json j_array_empty(json::value_t::array); - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_object_empty(json::value_t::object); + json j_array = {1, 2, 4, 8, 16}; + json j_array_empty(json::value_t::array); + json j_string = "Hello, world"; - // call empty() - std::cout << std::boolalpha; - std::cout << j_null.empty() << '\n'; - std::cout << j_boolean.empty() << '\n'; - std::cout << j_number_integer.empty() << '\n'; - std::cout << j_number_float.empty() << '\n'; - std::cout << j_object.empty() << '\n'; - std::cout << j_object_empty.empty() << '\n'; - std::cout << j_array.empty() << '\n'; - std::cout << j_array_empty.empty() << '\n'; - std::cout << j_string.empty() << '\n'; + // call empty() + std::cout << std::boolalpha; + std::cout << j_null.empty() << '\n'; + std::cout << j_boolean.empty() << '\n'; + std::cout << j_number_integer.empty() << '\n'; + std::cout << j_number_float.empty() << '\n'; + std::cout << j_object.empty() << '\n'; + std::cout << j_object_empty.empty() << '\n'; + std::cout << j_array.empty() << '\n'; + std::cout << j_array_empty.empty() << '\n'; + std::cout << j_string.empty() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/end.cpp b/nlohmann_json/docs/mkdocs/docs/examples/end.cpp index 47beedb7..efa55d45 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/end.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/end.cpp @@ -3,17 +3,16 @@ using json = nlohmann::json; -int main() -{ - // create an array value - json array = {1, 2, 3, 4, 5}; +int main() { + // create an array value + json array = {1, 2, 3, 4, 5}; - // get an iterator to one past the last element - json::iterator it = array.end(); + // get an iterator to one past the last element + json::iterator it = array.end(); - // decrement the iterator to point to the last element - --it; + // decrement the iterator to point to the last element + --it; - // serialize the element that the iterator points to - std::cout << *it << '\n'; + // serialize the element that the iterator points to + std::cout << *it << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/erase__IteratorType.cpp b/nlohmann_json/docs/mkdocs/docs/examples/erase__IteratorType.cpp index f0d4ec6f..a31a6e9e 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/erase__IteratorType.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/erase__IteratorType.cpp @@ -3,29 +3,28 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; - // call erase() - j_boolean.erase(j_boolean.begin()); - j_number_integer.erase(j_number_integer.begin()); - j_number_float.erase(j_number_float.begin()); - j_object.erase(j_object.find("two")); - j_array.erase(j_array.begin() + 2); - j_string.erase(j_string.begin()); + // call erase() + j_boolean.erase(j_boolean.begin()); + j_number_integer.erase(j_number_integer.begin()); + j_number_float.erase(j_number_float.begin()); + j_object.erase(j_object.find("two")); + j_array.erase(j_array.begin() + 2); + j_string.erase(j_string.begin()); - // print values - std::cout << j_boolean << '\n'; - std::cout << j_number_integer << '\n'; - std::cout << j_number_float << '\n'; - std::cout << j_object << '\n'; - std::cout << j_array << '\n'; - std::cout << j_string << '\n'; + // print values + std::cout << j_boolean << '\n'; + std::cout << j_number_integer << '\n'; + std::cout << j_number_float << '\n'; + std::cout << j_object << '\n'; + std::cout << j_array << '\n'; + std::cout << j_string << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/erase__IteratorType_IteratorType.cpp b/nlohmann_json/docs/mkdocs/docs/examples/erase__IteratorType_IteratorType.cpp index 392511ff..007ddd2f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/erase__IteratorType_IteratorType.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/erase__IteratorType_IteratorType.cpp @@ -3,29 +3,28 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; - // call erase() - j_boolean.erase(j_boolean.begin(), j_boolean.end()); - j_number_integer.erase(j_number_integer.begin(), j_number_integer.end()); - j_number_float.erase(j_number_float.begin(), j_number_float.end()); - j_object.erase(j_object.find("two"), j_object.end()); - j_array.erase(j_array.begin() + 1, j_array.begin() + 3); - j_string.erase(j_string.begin(), j_string.end()); + // call erase() + j_boolean.erase(j_boolean.begin(), j_boolean.end()); + j_number_integer.erase(j_number_integer.begin(), j_number_integer.end()); + j_number_float.erase(j_number_float.begin(), j_number_float.end()); + j_object.erase(j_object.find("two"), j_object.end()); + j_array.erase(j_array.begin() + 1, j_array.begin() + 3); + j_string.erase(j_string.begin(), j_string.end()); - // print values - std::cout << j_boolean << '\n'; - std::cout << j_number_integer << '\n'; - std::cout << j_number_float << '\n'; - std::cout << j_object << '\n'; - std::cout << j_array << '\n'; - std::cout << j_string << '\n'; + // print values + std::cout << j_boolean << '\n'; + std::cout << j_number_integer << '\n'; + std::cout << j_number_float << '\n'; + std::cout << j_object << '\n'; + std::cout << j_array << '\n'; + std::cout << j_string << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/erase__keytype.c++17.cpp b/nlohmann_json/docs/mkdocs/docs/examples/erase__keytype.c++17.cpp index c5e4bed5..2c1f7832 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/erase__keytype.c++17.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/erase__keytype.c++17.cpp @@ -1,20 +1,19 @@ #include -#include #include +#include using namespace std::string_view_literals; using json = nlohmann::json; -int main() -{ - // create a JSON object - json j_object = {{"one", 1}, {"two", 2}}; +int main() { + // create a JSON object + json j_object = {{"one", 1}, {"two", 2}}; - // call erase() - auto count_one = j_object.erase("one"sv); - auto count_three = j_object.erase("three"sv); + // call erase() + auto count_one = j_object.erase("one"sv); + auto count_three = j_object.erase("three"sv); - // print values - std::cout << j_object << '\n'; - std::cout << count_one << " " << count_three << '\n'; + // print values + std::cout << j_object << '\n'; + std::cout << count_one << " " << count_three << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/erase__object_t_key_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/erase__object_t_key_type.cpp index 2fd84c86..2a72510f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/erase__object_t_key_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/erase__object_t_key_type.cpp @@ -3,16 +3,15 @@ using json = nlohmann::json; -int main() -{ - // create a JSON object - json j_object = {{"one", 1}, {"two", 2}}; +int main() { + // create a JSON object + json j_object = {{"one", 1}, {"two", 2}}; - // call erase() - auto count_one = j_object.erase("one"); - auto count_three = j_object.erase("three"); + // call erase() + auto count_one = j_object.erase("one"); + auto count_three = j_object.erase("three"); - // print values - std::cout << j_object << '\n'; - std::cout << count_one << " " << count_three << '\n'; + // print values + std::cout << j_object << '\n'; + std::cout << count_one << " " << count_three << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/erase__size_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/erase__size_type.cpp index 81006238..c35ddba4 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/erase__size_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/erase__size_type.cpp @@ -3,14 +3,13 @@ using json = nlohmann::json; -int main() -{ - // create a JSON array - json j_array = {0, 1, 2, 3, 4, 5}; +int main() { + // create a JSON array + json j_array = {0, 1, 2, 3, 4, 5}; - // call erase() - j_array.erase(2); + // call erase() + j_array.erase(2); - // print values - std::cout << j_array << '\n'; + // print values + std::cout << j_array << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/error_handler_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/error_handler_t.cpp index b4718d7e..2e192055 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/error_handler_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/error_handler_t.cpp @@ -3,22 +3,18 @@ using json = nlohmann::json; -int main() -{ - // create JSON value with invalid UTF-8 byte sequence - json j_invalid = "ä\xA9ü"; - try - { - std::cout << j_invalid.dump() << std::endl; - } - catch (const json::type_error& e) - { - std::cout << e.what() << std::endl; - } +int main() { + // create JSON value with invalid UTF-8 byte sequence + json j_invalid = "ä\xA9ü"; + try { + std::cout << j_invalid.dump() << std::endl; + } catch (const json::type_error &e) { + std::cout << e.what() << std::endl; + } - std::cout << "string with replaced invalid characters: " - << j_invalid.dump(-1, ' ', false, json::error_handler_t::replace) - << "\nstring with ignored invalid characters: " - << j_invalid.dump(-1, ' ', false, json::error_handler_t::ignore) - << '\n'; + std::cout << "string with replaced invalid characters: " + << j_invalid.dump(-1, ' ', false, json::error_handler_t::replace) + << "\nstring with ignored invalid characters: " + << j_invalid.dump(-1, ' ', false, json::error_handler_t::ignore) + << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/exception.cpp b/nlohmann_json/docs/mkdocs/docs/examples/exception.cpp index 3e5a23b3..7fc89a2a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/exception.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/exception.cpp @@ -3,18 +3,14 @@ using json = nlohmann::json; -int main() -{ - try - { - // calling at() for a non-existing key - json j = {{"foo", "bar"}}; - json k = j.at("non-existing"); - } - catch (const json::exception& e) - { - // output exception information - std::cout << "message: " << e.what() << '\n' - << "exception id: " << e.id << std::endl; - } +int main() { + try { + // calling at() for a non-existing key + json j = {{"foo", "bar"}}; + json k = j.at("non-existing"); + } catch (const json::exception &e) { + // output exception information + std::cout << "message: " << e.what() << '\n' + << "exception id: " << e.id << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/find__keytype.c++17.cpp b/nlohmann_json/docs/mkdocs/docs/examples/find__keytype.c++17.cpp index da94cf0a..c4003825 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/find__keytype.c++17.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/find__keytype.c++17.cpp @@ -1,22 +1,21 @@ #include -#include #include +#include using namespace std::string_view_literals; using json = nlohmann::json; -int main() -{ - // create a JSON object - json j_object = {{"one", 1}, {"two", 2}}; +int main() { + // create a JSON object + json j_object = {{"one", 1}, {"two", 2}}; - // call find - auto it_two = j_object.find("two"sv); - auto it_three = j_object.find("three"sv); + // call find + auto it_two = j_object.find("two"sv); + auto it_three = j_object.find("three"sv); - // print values - std::cout << std::boolalpha; - std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n'; - std::cout << "value at key \"two\": " << *it_two << '\n'; - std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n'; + // print values + std::cout << std::boolalpha; + std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n'; + std::cout << "value at key \"two\": " << *it_two << '\n'; + std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/find__object_t_key_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/find__object_t_key_type.cpp index 685ba776..c5555769 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/find__object_t_key_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/find__object_t_key_type.cpp @@ -3,18 +3,17 @@ using json = nlohmann::json; -int main() -{ - // create a JSON object - json j_object = {{"one", 1}, {"two", 2}}; +int main() { + // create a JSON object + json j_object = {{"one", 1}, {"two", 2}}; - // call find - auto it_two = j_object.find("two"); - auto it_three = j_object.find("three"); + // call find + auto it_two = j_object.find("two"); + auto it_three = j_object.find("three"); - // print values - std::cout << std::boolalpha; - std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n'; - std::cout << "value at key \"two\": " << *it_two << '\n'; - std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n'; + // print values + std::cout << std::boolalpha; + std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n'; + std::cout << "value at key \"two\": " << *it_two << '\n'; + std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/flatten.cpp b/nlohmann_json/docs/mkdocs/docs/examples/flatten.cpp index 83f3ff6c..3746a71b 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/flatten.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/flatten.cpp @@ -1,32 +1,19 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create JSON value - json j = - { - {"pi", 3.141}, - {"happy", true}, - {"name", "Niels"}, - {"nothing", nullptr}, - { - "answer", { - {"everything", 42} - } - }, - {"list", {1, 0, 2}}, - { - "object", { - {"currency", "USD"}, - {"value", 42.99} - } - } - }; +int main() { + // create JSON value + json j = {{"pi", 3.141}, + {"happy", true}, + {"name", "Niels"}, + {"nothing", nullptr}, + {"answer", {{"everything", 42}}}, + {"list", {1, 0, 2}}, + {"object", {{"currency", "USD"}, {"value", 42.99}}}}; - // call flatten() - std::cout << std::setw(4) << j.flatten() << '\n'; + // call flatten() + std::cout << std::setw(4) << j.flatten() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/from_bjdata.cpp b/nlohmann_json/docs/mkdocs/docs/examples/from_bjdata.cpp index 961164c2..f723295e 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/from_bjdata.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/from_bjdata.cpp @@ -1,20 +1,18 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create byte vector - std::vector v = {0x7B, 0x69, 0x07, 0x63, 0x6F, 0x6D, 0x70, 0x61, - 0x63, 0x74, 0x54, 0x69, 0x06, 0x73, 0x63, 0x68, - 0x65, 0x6D, 0x61, 0x69, 0x00, 0x7D - }; +int main() { + // create byte vector + std::vector v = {0x7B, 0x69, 0x07, 0x63, 0x6F, 0x6D, 0x70, 0x61, + 0x63, 0x74, 0x54, 0x69, 0x06, 0x73, 0x63, 0x68, + 0x65, 0x6D, 0x61, 0x69, 0x00, 0x7D}; - // deserialize it with BJData - json j = json::from_bjdata(v); + // deserialize it with BJData + json j = json::from_bjdata(v); - // print the deserialized JSON value - std::cout << std::setw(2) << j << std::endl; + // print the deserialized JSON value + std::cout << std::setw(2) << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/from_bson.cpp b/nlohmann_json/docs/mkdocs/docs/examples/from_bson.cpp index c9d9fdfa..7d2c6148 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/from_bson.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/from_bson.cpp @@ -1,21 +1,19 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create byte vector - std::vector v = {0x1b, 0x00, 0x00, 0x00, 0x08, 0x63, 0x6f, 0x6d, - 0x70, 0x61, 0x63, 0x74, 0x00, 0x01, 0x10, 0x73, - 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00 - }; +int main() { + // create byte vector + std::vector v = {0x1b, 0x00, 0x00, 0x00, 0x08, 0x63, 0x6f, + 0x6d, 0x70, 0x61, 0x63, 0x74, 0x00, 0x01, + 0x10, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - // deserialize it with BSON - json j = json::from_bson(v); + // deserialize it with BSON + json j = json::from_bson(v); - // print the deserialized JSON value - std::cout << std::setw(2) << j << std::endl; + // print the deserialized JSON value + std::cout << std::setw(2) << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/from_cbor.cpp b/nlohmann_json/docs/mkdocs/docs/examples/from_cbor.cpp index e685329e..2e993b72 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/from_cbor.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/from_cbor.cpp @@ -1,20 +1,18 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create byte vector - std::vector v = {0xa2, 0x67, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, - 0x74, 0xf5, 0x66, 0x73, 0x63, 0x68, 0x65, 0x6d, - 0x61, 0x00 - }; +int main() { + // create byte vector + std::vector v = {0xa2, 0x67, 0x63, 0x6f, 0x6d, 0x70, + 0x61, 0x63, 0x74, 0xf5, 0x66, 0x73, + 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00}; - // deserialize it with CBOR - json j = json::from_cbor(v); + // deserialize it with CBOR + json j = json::from_cbor(v); - // print the deserialized JSON value - std::cout << std::setw(2) << j << std::endl; + // print the deserialized JSON value + std::cout << std::setw(2) << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/from_json__default_constructible.cpp b/nlohmann_json/docs/mkdocs/docs/examples/from_json__default_constructible.cpp index 07d71ac9..73d6bc00 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/from_json__default_constructible.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/from_json__default_constructible.cpp @@ -3,35 +3,31 @@ using json = nlohmann::json; -namespace ns -{ +namespace ns { // a simple struct to model a person -struct person -{ - std::string name; - std::string address; - int age; +struct person { + std::string name; + std::string address; + int age; }; } // namespace ns -namespace ns -{ -void from_json(const json& j, person& p) -{ - j.at("name").get_to(p.name); - j.at("address").get_to(p.address); - j.at("age").get_to(p.age); +namespace ns { +void from_json(const json &j, person &p) { + j.at("name").get_to(p.name); + j.at("address").get_to(p.address); + j.at("age").get_to(p.age); } } // namespace ns -int main() -{ - json j; - j["name"] = "Ned Flanders"; - j["address"] = "744 Evergreen Terrace"; - j["age"] = 60; +int main() { + json j; + j["name"] = "Ned Flanders"; + j["address"] = "744 Evergreen Terrace"; + j["age"] = 60; - auto p = j.template get(); + auto p = j.template get(); - std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl; + std::cout << p.name << " (" << p.age << ") lives in " << p.address + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/from_json__non_default_constructible.cpp b/nlohmann_json/docs/mkdocs/docs/examples/from_json__non_default_constructible.cpp index ec8206ea..7503be09 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/from_json__non_default_constructible.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/from_json__non_default_constructible.cpp @@ -3,51 +3,43 @@ using json = nlohmann::json; -namespace ns -{ +namespace ns { // a simple struct to model a person (not default constructible) -struct person -{ - person(std::string n, std::string a, int aa) - : name(std::move(n)), address(std::move(a)), age(aa) - {} - - std::string name; - std::string address; - int age; +struct person { + person(std::string n, std::string a, int aa) + : name(std::move(n)), address(std::move(a)), age(aa) {} + + std::string name; + std::string address; + int age; }; } // namespace ns -namespace nlohmann -{ -template <> -struct adl_serializer -{ - static ns::person from_json(const json& j) - { - return {j.at("name"), j.at("address"), j.at("age")}; - } - - // Here's the catch! You must provide a to_json method! Otherwise, you - // will not be able to convert person to json, since you fully - // specialized adl_serializer on that type - static void to_json(json& j, ns::person p) - { - j["name"] = p.name; - j["address"] = p.address; - j["age"] = p.age; - } +namespace nlohmann { +template <> struct adl_serializer { + static ns::person from_json(const json &j) { + return {j.at("name"), j.at("address"), j.at("age")}; + } + + // Here's the catch! You must provide a to_json method! Otherwise, you + // will not be able to convert person to json, since you fully + // specialized adl_serializer on that type + static void to_json(json &j, ns::person p) { + j["name"] = p.name; + j["address"] = p.address; + j["age"] = p.age; + } }; } // namespace nlohmann -int main() -{ - json j; - j["name"] = "Ned Flanders"; - j["address"] = "744 Evergreen Terrace"; - j["age"] = 60; +int main() { + json j; + j["name"] = "Ned Flanders"; + j["address"] = "744 Evergreen Terrace"; + j["age"] = 60; - auto p = j.template get(); + auto p = j.template get(); - std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl; + std::cout << p.name << " (" << p.age << ") lives in " << p.address + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/from_msgpack.cpp b/nlohmann_json/docs/mkdocs/docs/examples/from_msgpack.cpp index 5c2183f1..2a075cc4 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/from_msgpack.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/from_msgpack.cpp @@ -1,20 +1,18 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create byte vector - std::vector v = {0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, - 0x74, 0xc3, 0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d, - 0x61, 0x00 - }; +int main() { + // create byte vector + std::vector v = {0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, + 0x61, 0x63, 0x74, 0xc3, 0xa6, 0x73, + 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00}; - // deserialize it with MessagePack - json j = json::from_msgpack(v); + // deserialize it with MessagePack + json j = json::from_msgpack(v); - // print the deserialized JSON value - std::cout << std::setw(2) << j << std::endl; + // print the deserialized JSON value + std::cout << std::setw(2) << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/from_ubjson.cpp b/nlohmann_json/docs/mkdocs/docs/examples/from_ubjson.cpp index 1e85e4e3..0686e1eb 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/from_ubjson.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/from_ubjson.cpp @@ -1,20 +1,18 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create byte vector - std::vector v = {0x7B, 0x69, 0x07, 0x63, 0x6F, 0x6D, 0x70, 0x61, - 0x63, 0x74, 0x54, 0x69, 0x06, 0x73, 0x63, 0x68, - 0x65, 0x6D, 0x61, 0x69, 0x00, 0x7D - }; +int main() { + // create byte vector + std::vector v = {0x7B, 0x69, 0x07, 0x63, 0x6F, 0x6D, 0x70, 0x61, + 0x63, 0x74, 0x54, 0x69, 0x06, 0x73, 0x63, 0x68, + 0x65, 0x6D, 0x61, 0x69, 0x00, 0x7D}; - // deserialize it with UBJSON - json j = json::from_ubjson(v); + // deserialize it with UBJSON + json j = json::from_ubjson(v); - // print the deserialized JSON value - std::cout << std::setw(2) << j << std::endl; + // print the deserialized JSON value + std::cout << std::setw(2) << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/front.cpp b/nlohmann_json/docs/mkdocs/docs/examples/front.cpp index a0f63068..8e0db222 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/front.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/front.cpp @@ -3,27 +3,26 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_object_empty(json::value_t::object); - json j_array = {1, 2, 4, 8, 16}; - json j_array_empty(json::value_t::array); - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_object_empty(json::value_t::object); + json j_array = {1, 2, 4, 8, 16}; + json j_array_empty(json::value_t::array); + json j_string = "Hello, world"; - // call front() - //std::cout << j_null.front() << '\n'; // would throw - std::cout << j_boolean.front() << '\n'; - std::cout << j_number_integer.front() << '\n'; - std::cout << j_number_float.front() << '\n'; - std::cout << j_object.front() << '\n'; - //std::cout << j_object_empty.front() << '\n'; // undefined behavior - std::cout << j_array.front() << '\n'; - //std::cout << j_array_empty.front() << '\n'; // undefined behavior - std::cout << j_string.front() << '\n'; + // call front() + // std::cout << j_null.front() << '\n'; // would throw + std::cout << j_boolean.front() << '\n'; + std::cout << j_number_integer.front() << '\n'; + std::cout << j_number_float.front() << '\n'; + std::cout << j_object.front() << '\n'; + // std::cout << j_object_empty.front() << '\n'; // undefined behavior + std::cout << j_array.front() << '\n'; + // std::cout << j_array_empty.front() << '\n'; // undefined behavior + std::cout << j_string.front() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/get__PointerType.cpp b/nlohmann_json/docs/mkdocs/docs/examples/get__PointerType.cpp index 309c8dee..7a50da81 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/get__PointerType.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/get__PointerType.cpp @@ -3,19 +3,18 @@ using json = nlohmann::json; -int main() -{ - // create a JSON number - json value = 17; +int main() { + // create a JSON number + json value = 17; - // explicitly getting pointers - auto p1 = value.template get(); - auto p2 = value.template get(); - auto p3 = value.template get(); - auto p4 = value.template get(); - auto p5 = value.template get(); + // explicitly getting pointers + auto p1 = value.template get(); + auto p2 = value.template get(); + auto p3 = value.template get(); + auto p4 = value.template get(); + auto p5 = value.template get(); - // print the pointees - std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n'; - std::cout << std::boolalpha << (p5 == nullptr) << '\n'; + // print the pointees + std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n'; + std::cout << std::boolalpha << (p5 == nullptr) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/get__ValueType_const.cpp b/nlohmann_json/docs/mkdocs/docs/examples/get__ValueType_const.cpp index db63791f..c5be3392 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/get__ValueType_const.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/get__ValueType_const.cpp @@ -1,50 +1,39 @@ #include -#include #include +#include using json = nlohmann::json; -int main() -{ - // create a JSON value with different types - json json_types = - { - {"boolean", true}, - { - "number", { - {"integer", 42}, - {"floating-point", 17.23} - } - }, - {"string", "Hello, world!"}, - {"array", {1, 2, 3, 4, 5}}, - {"null", nullptr} - }; +int main() { + // create a JSON value with different types + json json_types = {{"boolean", true}, + {"number", {{"integer", 42}, {"floating-point", 17.23}}}, + {"string", "Hello, world!"}, + {"array", {1, 2, 3, 4, 5}}, + {"null", nullptr}}; - // use explicit conversions - auto v1 = json_types["boolean"].template get(); - auto v2 = json_types["number"]["integer"].template get(); - auto v3 = json_types["number"]["integer"].template get(); - auto v4 = json_types["number"]["floating-point"].template get(); - auto v5 = json_types["number"]["floating-point"].template get(); - auto v6 = json_types["string"].template get(); - auto v7 = json_types["array"].template get>(); - auto v8 = json_types.template get>(); + // use explicit conversions + auto v1 = json_types["boolean"].template get(); + auto v2 = json_types["number"]["integer"].template get(); + auto v3 = json_types["number"]["integer"].template get(); + auto v4 = json_types["number"]["floating-point"].template get(); + auto v5 = json_types["number"]["floating-point"].template get(); + auto v6 = json_types["string"].template get(); + auto v7 = json_types["array"].template get>(); + auto v8 = json_types.template get>(); - // print the conversion results - std::cout << v1 << '\n'; - std::cout << v2 << ' ' << v3 << '\n'; - std::cout << v4 << ' ' << v5 << '\n'; - std::cout << v6 << '\n'; + // print the conversion results + std::cout << v1 << '\n'; + std::cout << v2 << ' ' << v3 << '\n'; + std::cout << v4 << ' ' << v5 << '\n'; + std::cout << v6 << '\n'; - for (auto i : v7) - { - std::cout << i << ' '; - } - std::cout << "\n\n"; + for (auto i : v7) { + std::cout << i << ' '; + } + std::cout << "\n\n"; - for (auto i : v8) - { - std::cout << i.first << ": " << i.second << '\n'; - } + for (auto i : v8) { + std::cout << i.first << ": " << i.second << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/get_allocator.cpp b/nlohmann_json/docs/mkdocs/docs/examples/get_allocator.cpp index 35079a10..f9657618 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/get_allocator.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/get_allocator.cpp @@ -3,16 +3,15 @@ using json = nlohmann::json; -int main() -{ - auto alloc = json::get_allocator(); - using traits_t = std::allocator_traits; +int main() { + auto alloc = json::get_allocator(); + using traits_t = std::allocator_traits; - json* j = traits_t::allocate(alloc, 1); - traits_t::construct(alloc, j, "Hello, world!"); + json *j = traits_t::allocate(alloc, 1); + traits_t::construct(alloc, j, "Hello, world!"); - std::cout << *j << std::endl; + std::cout << *j << std::endl; - traits_t::destroy(alloc, j); - traits_t::deallocate(alloc, j, 1); + traits_t::destroy(alloc, j); + traits_t::deallocate(alloc, j, 1); } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/get_binary.cpp b/nlohmann_json/docs/mkdocs/docs/examples/get_binary.cpp index 617ce609..acfc2019 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/get_binary.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/get_binary.cpp @@ -3,14 +3,14 @@ using json = nlohmann::json; -int main() -{ - // create a binary vector - std::vector vec = {0xCA, 0xFE, 0xBA, 0xBE}; +int main() { + // create a binary vector + std::vector vec = {0xCA, 0xFE, 0xBA, 0xBE}; - // create a binary JSON value with subtype 42 - json j = json::binary(vec, 42); + // create a binary JSON value with subtype 42 + json j = json::binary(vec, 42); - // output type and subtype - std::cout << "type: " << j.type_name() << ", subtype: " << j.get_binary().subtype() << std::endl; + // output type and subtype + std::cout << "type: " << j.type_name() + << ", subtype: " << j.get_binary().subtype() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/get_ptr.cpp b/nlohmann_json/docs/mkdocs/docs/examples/get_ptr.cpp index 564ce0f4..e6006f74 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/get_ptr.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/get_ptr.cpp @@ -3,19 +3,18 @@ using json = nlohmann::json; -int main() -{ - // create a JSON number - json value = 17; +int main() { + // create a JSON number + json value = 17; - // explicitly getting pointers - auto p1 = value.get_ptr(); - auto p2 = value.get_ptr(); - auto p3 = value.get_ptr(); - auto p4 = value.get_ptr(); - auto p5 = value.get_ptr(); + // explicitly getting pointers + auto p1 = value.get_ptr(); + auto p2 = value.get_ptr(); + auto p3 = value.get_ptr(); + auto p4 = value.get_ptr(); + auto p5 = value.get_ptr(); - // print the pointees - std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n'; - std::cout << std::boolalpha << (p5 == nullptr) << '\n'; + // print the pointees + std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n'; + std::cout << std::boolalpha << (p5 == nullptr) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/get_ref.cpp b/nlohmann_json/docs/mkdocs/docs/examples/get_ref.cpp index 0183a653..8e906a7f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/get_ref.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/get_ref.cpp @@ -3,25 +3,21 @@ using json = nlohmann::json; -int main() -{ - // create a JSON number - json value = 17; +int main() { + // create a JSON number + json value = 17; - // explicitly getting references - auto r1 = value.get_ref(); - auto r2 = value.get_ref(); + // explicitly getting references + auto r1 = value.get_ref(); + auto r2 = value.get_ref(); - // print the values - std::cout << r1 << ' ' << r2 << '\n'; + // print the values + std::cout << r1 << ' ' << r2 << '\n'; - // incompatible type throws exception - try - { - auto r3 = value.get_ref(); - } - catch (const json::type_error& ex) - { - std::cout << ex.what() << '\n'; - } + // incompatible type throws exception + try { + auto r3 = value.get_ref(); + } catch (const json::type_error &ex) { + std::cout << ex.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/get_to.cpp b/nlohmann_json/docs/mkdocs/docs/examples/get_to.cpp index 358c8d43..6fcfbc53 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/get_to.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/get_to.cpp @@ -1,59 +1,48 @@ #include -#include #include +#include using json = nlohmann::json; -int main() -{ - // create a JSON value with different types - json json_types = - { - {"boolean", true}, - { - "number", { - {"integer", 42}, - {"floating-point", 17.23} - } - }, - {"string", "Hello, world!"}, - {"array", {1, 2, 3, 4, 5}}, - {"null", nullptr} - }; +int main() { + // create a JSON value with different types + json json_types = {{"boolean", true}, + {"number", {{"integer", 42}, {"floating-point", 17.23}}}, + {"string", "Hello, world!"}, + {"array", {1, 2, 3, 4, 5}}, + {"null", nullptr}}; - bool v1; - int v2; - short v3; - float v4; - int v5; - std::string v6; - std::vector v7; - std::unordered_map v8; + bool v1; + int v2; + short v3; + float v4; + int v5; + std::string v6; + std::vector v7; + std::unordered_map v8; - // use explicit conversions - json_types["boolean"].get_to(v1); - json_types["number"]["integer"].get_to(v2); - json_types["number"]["integer"].get_to(v3); - json_types["number"]["floating-point"].get_to(v4); - json_types["number"]["floating-point"].get_to(v5); - json_types["string"].get_to(v6); - json_types["array"].get_to(v7); - json_types.get_to(v8); + // use explicit conversions + json_types["boolean"].get_to(v1); + json_types["number"]["integer"].get_to(v2); + json_types["number"]["integer"].get_to(v3); + json_types["number"]["floating-point"].get_to(v4); + json_types["number"]["floating-point"].get_to(v5); + json_types["string"].get_to(v6); + json_types["array"].get_to(v7); + json_types.get_to(v8); - // print the conversion results - std::cout << v1 << '\n'; - std::cout << v2 << ' ' << v3 << '\n'; - std::cout << v4 << ' ' << v5 << '\n'; - std::cout << v6 << '\n'; + // print the conversion results + std::cout << v1 << '\n'; + std::cout << v2 << ' ' << v3 << '\n'; + std::cout << v4 << ' ' << v5 << '\n'; + std::cout << v6 << '\n'; - for (auto i : v7) - { - std::cout << i << ' '; - } - std::cout << "\n\n"; + for (auto i : v7) { + std::cout << i << ' '; + } + std::cout << "\n\n"; - for (auto i : v8) - { - std::cout << i.first << ": " << i.second << '\n'; - } + for (auto i : v8) { + std::cout << i.first << ": " << i.second << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/insert.cpp b/nlohmann_json/docs/mkdocs/docs/examples/insert.cpp index 4ee60987..8c3c3d7b 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/insert.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/insert.cpp @@ -3,15 +3,14 @@ using json = nlohmann::json; -int main() -{ - // create a JSON array - json v = {1, 2, 3, 4}; +int main() { + // create a JSON array + json v = {1, 2, 3, 4}; - // insert number 10 before number 3 - auto new_pos = v.insert(v.begin() + 2, 10); + // insert number 10 before number 3 + auto new_pos = v.insert(v.begin() + 2, 10); - // output new array and result of insert call - std::cout << *new_pos << '\n'; - std::cout << v << '\n'; + // output new array and result of insert call + std::cout << *new_pos << '\n'; + std::cout << v << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/insert__count.cpp b/nlohmann_json/docs/mkdocs/docs/examples/insert__count.cpp index ce33b93e..d5986150 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/insert__count.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/insert__count.cpp @@ -3,15 +3,14 @@ using json = nlohmann::json; -int main() -{ - // create a JSON array - json v = {1, 2, 3, 4}; +int main() { + // create a JSON array + json v = {1, 2, 3, 4}; - // insert number 7 copies of number 7 before number 3 - auto new_pos = v.insert(v.begin() + 2, 7, 7); + // insert number 7 copies of number 7 before number 3 + auto new_pos = v.insert(v.begin() + 2, 7, 7); - // output new array and result of insert call - std::cout << *new_pos << '\n'; - std::cout << v << '\n'; + // output new array and result of insert call + std::cout << *new_pos << '\n'; + std::cout << v << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/insert__ilist.cpp b/nlohmann_json/docs/mkdocs/docs/examples/insert__ilist.cpp index a20766a1..820d44c4 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/insert__ilist.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/insert__ilist.cpp @@ -3,15 +3,14 @@ using json = nlohmann::json; -int main() -{ - // create a JSON array - json v = {1, 2, 3, 4}; +int main() { + // create a JSON array + json v = {1, 2, 3, 4}; - // insert range from v2 before the end of array v - auto new_pos = v.insert(v.end(), {7, 8, 9}); + // insert range from v2 before the end of array v + auto new_pos = v.insert(v.end(), {7, 8, 9}); - // output new array and result of insert call - std::cout << *new_pos << '\n'; - std::cout << v << '\n'; + // output new array and result of insert call + std::cout << *new_pos << '\n'; + std::cout << v << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/insert__range.cpp b/nlohmann_json/docs/mkdocs/docs/examples/insert__range.cpp index 92fe63b0..6aa8754d 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/insert__range.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/insert__range.cpp @@ -3,18 +3,17 @@ using json = nlohmann::json; -int main() -{ - // create a JSON array - json v = {1, 2, 3, 4}; +int main() { + // create a JSON array + json v = {1, 2, 3, 4}; - // create a JSON array to copy values from - json v2 = {"one", "two", "three", "four"}; + // create a JSON array to copy values from + json v2 = {"one", "two", "three", "four"}; - // insert range from v2 before the end of array v - auto new_pos = v.insert(v.end(), v2.begin(), v2.end()); + // insert range from v2 before the end of array v + auto new_pos = v.insert(v.end(), v2.begin(), v2.end()); - // output new array and result of insert call - std::cout << *new_pos << '\n'; - std::cout << v << '\n'; + // output new array and result of insert call + std::cout << *new_pos << '\n'; + std::cout << v << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/insert__range_object.cpp b/nlohmann_json/docs/mkdocs/docs/examples/insert__range_object.cpp index 97373d3b..cb65c111 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/insert__range_object.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/insert__range_object.cpp @@ -3,19 +3,18 @@ using json = nlohmann::json; -int main() -{ - // create two JSON objects - json j1 = {{"one", "eins"}, {"two", "zwei"}}; - json j2 = {{"eleven", "elf"}, {"seventeen", "siebzehn"}}; +int main() { + // create two JSON objects + json j1 = {{"one", "eins"}, {"two", "zwei"}}; + json j2 = {{"eleven", "elf"}, {"seventeen", "siebzehn"}}; - // output objects - std::cout << j1 << '\n'; - std::cout << j2 << '\n'; + // output objects + std::cout << j1 << '\n'; + std::cout << j2 << '\n'; - // insert range from j2 to j1 - j1.insert(j2.begin(), j2.end()); + // insert range from j2 to j1 + j1.insert(j2.begin(), j2.end()); - // output result of insert call - std::cout << j1 << '\n'; + // output result of insert call + std::cout << j1 << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/invalid_iterator.cpp b/nlohmann_json/docs/mkdocs/docs/examples/invalid_iterator.cpp index ecde12e6..8af49932 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/invalid_iterator.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/invalid_iterator.cpp @@ -3,19 +3,15 @@ using json = nlohmann::json; -int main() -{ - try - { - // calling iterator::key() on non-object iterator - json j = "string"; - json::iterator it = j.begin(); - auto k = it.key(); - } - catch (const json::invalid_iterator& e) - { - // output exception information - std::cout << "message: " << e.what() << '\n' - << "exception id: " << e.id << std::endl; - } +int main() { + try { + // calling iterator::key() on non-object iterator + json j = "string"; + json::iterator it = j.begin(); + auto k = it.key(); + } catch (const json::invalid_iterator &e) { + // output exception information + std::cout << "message: " << e.what() << '\n' + << "exception id: " << e.id << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_array.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_array.cpp index 8ecc4503..702321b1 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_array.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_array.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_unsigned_integer = 12345678987654321u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_unsigned_integer = 12345678987654321u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_array() - std::cout << std::boolalpha; - std::cout << j_null.is_array() << '\n'; - std::cout << j_boolean.is_array() << '\n'; - std::cout << j_number_integer.is_array() << '\n'; - std::cout << j_number_unsigned_integer.is_array() << '\n'; - std::cout << j_number_float.is_array() << '\n'; - std::cout << j_object.is_array() << '\n'; - std::cout << j_array.is_array() << '\n'; - std::cout << j_string.is_array() << '\n'; - std::cout << j_binary.is_array() << '\n'; + // call is_array() + std::cout << std::boolalpha; + std::cout << j_null.is_array() << '\n'; + std::cout << j_boolean.is_array() << '\n'; + std::cout << j_number_integer.is_array() << '\n'; + std::cout << j_number_unsigned_integer.is_array() << '\n'; + std::cout << j_number_float.is_array() << '\n'; + std::cout << j_object.is_array() << '\n'; + std::cout << j_array.is_array() << '\n'; + std::cout << j_string.is_array() << '\n'; + std::cout << j_binary.is_array() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_binary.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_binary.cpp index d7f049ec..dc90c81d 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_binary.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_binary.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_unsigned_integer = 12345678987654321u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_unsigned_integer = 12345678987654321u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_binary() - std::cout << std::boolalpha; - std::cout << j_null.is_binary() << '\n'; - std::cout << j_boolean.is_binary() << '\n'; - std::cout << j_number_integer.is_binary() << '\n'; - std::cout << j_number_unsigned_integer.is_binary() << '\n'; - std::cout << j_number_float.is_binary() << '\n'; - std::cout << j_object.is_binary() << '\n'; - std::cout << j_array.is_binary() << '\n'; - std::cout << j_string.is_binary() << '\n'; - std::cout << j_binary.is_binary() << '\n'; + // call is_binary() + std::cout << std::boolalpha; + std::cout << j_null.is_binary() << '\n'; + std::cout << j_boolean.is_binary() << '\n'; + std::cout << j_number_integer.is_binary() << '\n'; + std::cout << j_number_unsigned_integer.is_binary() << '\n'; + std::cout << j_number_float.is_binary() << '\n'; + std::cout << j_object.is_binary() << '\n'; + std::cout << j_array.is_binary() << '\n'; + std::cout << j_string.is_binary() << '\n'; + std::cout << j_binary.is_binary() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_boolean.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_boolean.cpp index 0b798195..129eacdc 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_boolean.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_boolean.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_unsigned_integer = 12345678987654321u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_unsigned_integer = 12345678987654321u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_boolean() - std::cout << std::boolalpha; - std::cout << j_null.is_boolean() << '\n'; - std::cout << j_boolean.is_boolean() << '\n'; - std::cout << j_number_integer.is_boolean() << '\n'; - std::cout << j_number_unsigned_integer.is_boolean() << '\n'; - std::cout << j_number_float.is_boolean() << '\n'; - std::cout << j_object.is_boolean() << '\n'; - std::cout << j_array.is_boolean() << '\n'; - std::cout << j_string.is_boolean() << '\n'; - std::cout << j_binary.is_boolean() << '\n'; + // call is_boolean() + std::cout << std::boolalpha; + std::cout << j_null.is_boolean() << '\n'; + std::cout << j_boolean.is_boolean() << '\n'; + std::cout << j_number_integer.is_boolean() << '\n'; + std::cout << j_number_unsigned_integer.is_boolean() << '\n'; + std::cout << j_number_float.is_boolean() << '\n'; + std::cout << j_object.is_boolean() << '\n'; + std::cout << j_array.is_boolean() << '\n'; + std::cout << j_string.is_boolean() << '\n'; + std::cout << j_binary.is_boolean() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_discarded.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_discarded.cpp index 09016655..58356688 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_discarded.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_discarded.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_unsigned_integer = 12345678987654321u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_unsigned_integer = 12345678987654321u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_discarded() - std::cout << std::boolalpha; - std::cout << j_null.is_discarded() << '\n'; - std::cout << j_boolean.is_discarded() << '\n'; - std::cout << j_number_integer.is_discarded() << '\n'; - std::cout << j_number_unsigned_integer.is_discarded() << '\n'; - std::cout << j_number_float.is_discarded() << '\n'; - std::cout << j_object.is_discarded() << '\n'; - std::cout << j_array.is_discarded() << '\n'; - std::cout << j_string.is_discarded() << '\n'; - std::cout << j_binary.is_discarded() << '\n'; + // call is_discarded() + std::cout << std::boolalpha; + std::cout << j_null.is_discarded() << '\n'; + std::cout << j_boolean.is_discarded() << '\n'; + std::cout << j_number_integer.is_discarded() << '\n'; + std::cout << j_number_unsigned_integer.is_discarded() << '\n'; + std::cout << j_number_float.is_discarded() << '\n'; + std::cout << j_object.is_discarded() << '\n'; + std::cout << j_array.is_discarded() << '\n'; + std::cout << j_string.is_discarded() << '\n'; + std::cout << j_binary.is_discarded() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_null.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_null.cpp index 8a843326..0b1f49aa 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_null.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_null.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_unsigned_integer = 12345678987654321u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_unsigned_integer = 12345678987654321u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_null() - std::cout << std::boolalpha; - std::cout << j_null.is_null() << '\n'; - std::cout << j_boolean.is_null() << '\n'; - std::cout << j_number_integer.is_null() << '\n'; - std::cout << j_number_unsigned_integer.is_null() << '\n'; - std::cout << j_number_float.is_null() << '\n'; - std::cout << j_object.is_null() << '\n'; - std::cout << j_array.is_null() << '\n'; - std::cout << j_string.is_null() << '\n'; - std::cout << j_binary.is_null() << '\n'; + // call is_null() + std::cout << std::boolalpha; + std::cout << j_null.is_null() << '\n'; + std::cout << j_boolean.is_null() << '\n'; + std::cout << j_number_integer.is_null() << '\n'; + std::cout << j_number_unsigned_integer.is_null() << '\n'; + std::cout << j_number_float.is_null() << '\n'; + std::cout << j_object.is_null() << '\n'; + std::cout << j_array.is_null() << '\n'; + std::cout << j_string.is_null() << '\n'; + std::cout << j_binary.is_null() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_number.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_number.cpp index f107a048..d7c2a754 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_number.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_number.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_unsigned_integer = 12345678987654321u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_unsigned_integer = 12345678987654321u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_number() - std::cout << std::boolalpha; - std::cout << j_null.is_number() << '\n'; - std::cout << j_boolean.is_number() << '\n'; - std::cout << j_number_integer.is_number() << '\n'; - std::cout << j_number_unsigned_integer.is_number() << '\n'; - std::cout << j_number_float.is_number() << '\n'; - std::cout << j_object.is_number() << '\n'; - std::cout << j_array.is_number() << '\n'; - std::cout << j_string.is_number() << '\n'; - std::cout << j_binary.is_number() << '\n'; + // call is_number() + std::cout << std::boolalpha; + std::cout << j_null.is_number() << '\n'; + std::cout << j_boolean.is_number() << '\n'; + std::cout << j_number_integer.is_number() << '\n'; + std::cout << j_number_unsigned_integer.is_number() << '\n'; + std::cout << j_number_float.is_number() << '\n'; + std::cout << j_object.is_number() << '\n'; + std::cout << j_array.is_number() << '\n'; + std::cout << j_string.is_number() << '\n'; + std::cout << j_binary.is_number() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_number_float.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_number_float.cpp index bba2b446..95eded6d 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_number_float.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_number_float.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_unsigned_integer = 12345678987654321u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_unsigned_integer = 12345678987654321u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_number_float() - std::cout << std::boolalpha; - std::cout << j_null.is_number_float() << '\n'; - std::cout << j_boolean.is_number_float() << '\n'; - std::cout << j_number_integer.is_number_float() << '\n'; - std::cout << j_number_unsigned_integer.is_number_float() << '\n'; - std::cout << j_number_float.is_number_float() << '\n'; - std::cout << j_object.is_number_float() << '\n'; - std::cout << j_array.is_number_float() << '\n'; - std::cout << j_string.is_number_float() << '\n'; - std::cout << j_binary.is_number_float() << '\n'; + // call is_number_float() + std::cout << std::boolalpha; + std::cout << j_null.is_number_float() << '\n'; + std::cout << j_boolean.is_number_float() << '\n'; + std::cout << j_number_integer.is_number_float() << '\n'; + std::cout << j_number_unsigned_integer.is_number_float() << '\n'; + std::cout << j_number_float.is_number_float() << '\n'; + std::cout << j_object.is_number_float() << '\n'; + std::cout << j_array.is_number_float() << '\n'; + std::cout << j_string.is_number_float() << '\n'; + std::cout << j_binary.is_number_float() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_number_integer.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_number_integer.cpp index 8d6a5ae1..d9e72931 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_number_integer.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_number_integer.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_unsigned_integer = 12345678987654321u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_unsigned_integer = 12345678987654321u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_number_integer() - std::cout << std::boolalpha; - std::cout << j_null.is_number_integer() << '\n'; - std::cout << j_boolean.is_number_integer() << '\n'; - std::cout << j_number_integer.is_number_integer() << '\n'; - std::cout << j_number_unsigned_integer.is_number_integer() << '\n'; - std::cout << j_number_float.is_number_integer() << '\n'; - std::cout << j_object.is_number_integer() << '\n'; - std::cout << j_array.is_number_integer() << '\n'; - std::cout << j_string.is_number_integer() << '\n'; - std::cout << j_binary.is_number_integer() << '\n'; + // call is_number_integer() + std::cout << std::boolalpha; + std::cout << j_null.is_number_integer() << '\n'; + std::cout << j_boolean.is_number_integer() << '\n'; + std::cout << j_number_integer.is_number_integer() << '\n'; + std::cout << j_number_unsigned_integer.is_number_integer() << '\n'; + std::cout << j_number_float.is_number_integer() << '\n'; + std::cout << j_object.is_number_integer() << '\n'; + std::cout << j_array.is_number_integer() << '\n'; + std::cout << j_string.is_number_integer() << '\n'; + std::cout << j_binary.is_number_integer() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_number_unsigned.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_number_unsigned.cpp index b52ac6b3..dda4bab5 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_number_unsigned.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_number_unsigned.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_unsigned_integer = 12345678987654321u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_unsigned_integer = 12345678987654321u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_number_unsigned() - std::cout << std::boolalpha; - std::cout << j_null.is_number_unsigned() << '\n'; - std::cout << j_boolean.is_number_unsigned() << '\n'; - std::cout << j_number_integer.is_number_unsigned() << '\n'; - std::cout << j_number_unsigned_integer.is_number_unsigned() << '\n'; - std::cout << j_number_float.is_number_unsigned() << '\n'; - std::cout << j_object.is_number_unsigned() << '\n'; - std::cout << j_array.is_number_unsigned() << '\n'; - std::cout << j_string.is_number_unsigned() << '\n'; - std::cout << j_binary.is_number_unsigned() << '\n'; + // call is_number_unsigned() + std::cout << std::boolalpha; + std::cout << j_null.is_number_unsigned() << '\n'; + std::cout << j_boolean.is_number_unsigned() << '\n'; + std::cout << j_number_integer.is_number_unsigned() << '\n'; + std::cout << j_number_unsigned_integer.is_number_unsigned() << '\n'; + std::cout << j_number_float.is_number_unsigned() << '\n'; + std::cout << j_object.is_number_unsigned() << '\n'; + std::cout << j_array.is_number_unsigned() << '\n'; + std::cout << j_string.is_number_unsigned() << '\n'; + std::cout << j_binary.is_number_unsigned() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_object.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_object.cpp index a0216fd2..77b2d2b6 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_object.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_object.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_number_unsigned_integer = 12345678987654321u; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_number_unsigned_integer = 12345678987654321u; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_object() - std::cout << std::boolalpha; - std::cout << j_null.is_object() << '\n'; - std::cout << j_boolean.is_object() << '\n'; - std::cout << j_number_integer.is_object() << '\n'; - std::cout << j_number_unsigned_integer.is_object() << '\n'; - std::cout << j_number_float.is_object() << '\n'; - std::cout << j_object.is_object() << '\n'; - std::cout << j_array.is_object() << '\n'; - std::cout << j_string.is_object() << '\n'; - std::cout << j_binary.is_object() << '\n'; + // call is_object() + std::cout << std::boolalpha; + std::cout << j_null.is_object() << '\n'; + std::cout << j_boolean.is_object() << '\n'; + std::cout << j_number_integer.is_object() << '\n'; + std::cout << j_number_unsigned_integer.is_object() << '\n'; + std::cout << j_number_float.is_object() << '\n'; + std::cout << j_object.is_object() << '\n'; + std::cout << j_array.is_object() << '\n'; + std::cout << j_string.is_object() << '\n'; + std::cout << j_binary.is_object() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_primitive.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_primitive.cpp index af3968e8..85fc797a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_primitive.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_primitive.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_number_unsigned_integer = 12345678987654321u; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_number_unsigned_integer = 12345678987654321u; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_primitive() - std::cout << std::boolalpha; - std::cout << j_null.is_primitive() << '\n'; - std::cout << j_boolean.is_primitive() << '\n'; - std::cout << j_number_integer.is_primitive() << '\n'; - std::cout << j_number_unsigned_integer.is_primitive() << '\n'; - std::cout << j_number_float.is_primitive() << '\n'; - std::cout << j_object.is_primitive() << '\n'; - std::cout << j_array.is_primitive() << '\n'; - std::cout << j_string.is_primitive() << '\n'; - std::cout << j_binary.is_primitive() << '\n'; + // call is_primitive() + std::cout << std::boolalpha; + std::cout << j_null.is_primitive() << '\n'; + std::cout << j_boolean.is_primitive() << '\n'; + std::cout << j_number_integer.is_primitive() << '\n'; + std::cout << j_number_unsigned_integer.is_primitive() << '\n'; + std::cout << j_number_float.is_primitive() << '\n'; + std::cout << j_object.is_primitive() << '\n'; + std::cout << j_array.is_primitive() << '\n'; + std::cout << j_string.is_primitive() << '\n'; + std::cout << j_binary.is_primitive() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_string.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_string.cpp index c89f550b..f3107527 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_string.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_string.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_number_unsigned_integer = 12345678987654321u; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_number_unsigned_integer = 12345678987654321u; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_string() - std::cout << std::boolalpha; - std::cout << j_null.is_string() << '\n'; - std::cout << j_boolean.is_string() << '\n'; - std::cout << j_number_integer.is_string() << '\n'; - std::cout << j_number_unsigned_integer.is_string() << '\n'; - std::cout << j_number_float.is_string() << '\n'; - std::cout << j_object.is_string() << '\n'; - std::cout << j_array.is_string() << '\n'; - std::cout << j_string.is_string() << '\n'; - std::cout << j_binary.is_string() << '\n'; + // call is_string() + std::cout << std::boolalpha; + std::cout << j_null.is_string() << '\n'; + std::cout << j_boolean.is_string() << '\n'; + std::cout << j_number_integer.is_string() << '\n'; + std::cout << j_number_unsigned_integer.is_string() << '\n'; + std::cout << j_number_float.is_string() << '\n'; + std::cout << j_object.is_string() << '\n'; + std::cout << j_array.is_string() << '\n'; + std::cout << j_string.is_string() << '\n'; + std::cout << j_binary.is_string() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/is_structured.cpp b/nlohmann_json/docs/mkdocs/docs/examples/is_structured.cpp index 41947b1b..565d04e0 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/is_structured.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/is_structured.cpp @@ -3,28 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_number_unsigned_integer = 12345678987654321u; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; - json j_binary = json::binary({1, 2, 3}); +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_number_unsigned_integer = 12345678987654321u; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + json j_binary = json::binary({1, 2, 3}); - // call is_structured() - std::cout << std::boolalpha; - std::cout << j_null.is_structured() << '\n'; - std::cout << j_boolean.is_structured() << '\n'; - std::cout << j_number_integer.is_structured() << '\n'; - std::cout << j_number_unsigned_integer.is_structured() << '\n'; - std::cout << j_number_float.is_structured() << '\n'; - std::cout << j_object.is_structured() << '\n'; - std::cout << j_array.is_structured() << '\n'; - std::cout << j_string.is_structured() << '\n'; - std::cout << j_binary.is_structured() << '\n'; + // call is_structured() + std::cout << std::boolalpha; + std::cout << j_null.is_structured() << '\n'; + std::cout << j_boolean.is_structured() << '\n'; + std::cout << j_number_integer.is_structured() << '\n'; + std::cout << j_number_unsigned_integer.is_structured() << '\n'; + std::cout << j_number_float.is_structured() << '\n'; + std::cout << j_object.is_structured() << '\n'; + std::cout << j_array.is_structured() << '\n'; + std::cout << j_string.is_structured() << '\n'; + std::cout << j_binary.is_structured() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/items.cpp b/nlohmann_json/docs/mkdocs/docs/examples/items.cpp index 9cd2b51b..bcee4d1c 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/items.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/items.cpp @@ -3,21 +3,18 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; +int main() { + // create JSON values + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; - // example for an object - for (auto& x : j_object.items()) - { - std::cout << "key: " << x.key() << ", value: " << x.value() << '\n'; - } + // example for an object + for (auto &x : j_object.items()) { + std::cout << "key: " << x.key() << ", value: " << x.value() << '\n'; + } - // example for an array - for (auto& x : j_array.items()) - { - std::cout << "key: " << x.key() << ", value: " << x.value() << '\n'; - } + // example for an array + for (auto &x : j_array.items()) { + std::cout << "key: " << x.key() << ", value: " << x.value() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_base_class_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_base_class_t.cpp index 3fb2d46a..8e37290d 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_base_class_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_base_class_t.cpp @@ -1,88 +1,71 @@ #include #include -class visitor_adaptor_with_metadata -{ - public: - template - void visit(const Fnc& fnc) const; +class visitor_adaptor_with_metadata { +public: + template void visit(const Fnc &fnc) const; - int metadata = 42; - private: - template - void do_visit(const Ptr& ptr, const Fnc& fnc) const; + int metadata = 42; + +private: + template + void do_visit(const Ptr &ptr, const Fnc &fnc) const; }; -using json = nlohmann::basic_json < - std::map, - std::vector, - std::string, - bool, - std::int64_t, - std::uint64_t, - double, - std::allocator, - nlohmann::adl_serializer, - std::vector, - visitor_adaptor_with_metadata - >; +using json = + nlohmann::basic_json, + visitor_adaptor_with_metadata>; template -void visitor_adaptor_with_metadata::visit(const Fnc& fnc) const -{ - do_visit(json::json_pointer{}, fnc); +void visitor_adaptor_with_metadata::visit(const Fnc &fnc) const { + do_visit(json::json_pointer{}, fnc); } template -void visitor_adaptor_with_metadata::do_visit(const Ptr& ptr, const Fnc& fnc) const -{ - using value_t = nlohmann::detail::value_t; - const json& j = *static_cast(this); - switch (j.type()) - { - case value_t::object: - fnc(ptr, j); - for (const auto& entry : j.items()) - { - entry.value().do_visit(ptr / entry.key(), fnc); - } - break; - case value_t::array: - fnc(ptr, j); - for (std::size_t i = 0; i < j.size(); ++i) - { - j.at(i).do_visit(ptr / std::to_string(i), fnc); - } - break; - case value_t::null: - case value_t::string: - case value_t::boolean: - case value_t::number_integer: - case value_t::number_unsigned: - case value_t::number_float: - case value_t::binary: - fnc(ptr, j); - break; - case value_t::discarded: - default: - break; +void visitor_adaptor_with_metadata::do_visit(const Ptr &ptr, + const Fnc &fnc) const { + using value_t = nlohmann::detail::value_t; + const json &j = *static_cast(this); + switch (j.type()) { + case value_t::object: + fnc(ptr, j); + for (const auto &entry : j.items()) { + entry.value().do_visit(ptr / entry.key(), fnc); + } + break; + case value_t::array: + fnc(ptr, j); + for (std::size_t i = 0; i < j.size(); ++i) { + j.at(i).do_visit(ptr / std::to_string(i), fnc); } + break; + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + fnc(ptr, j); + break; + case value_t::discarded: + default: + break; + } } -int main() -{ - // create a json object - json j; - j["null"]; - j["object"]["uint"] = 1U; - j["object"].metadata = 21; +int main() { + // create a json object + json j; + j["null"]; + j["object"]["uint"] = 1U; + j["object"].metadata = 21; - // visit and output - j.visit( - [&](const json::json_pointer & p, - const json & j) - { - std::cout << (p.empty() ? std::string{"/"} : p.to_string()) - << " - metadata = " << j.metadata << " -> " << j.dump() << '\n'; - }); + // visit and output + j.visit([&](const json::json_pointer &p, const json &j) { + std::cout << (p.empty() ? std::string{"/"} : p.to_string()) + << " - metadata = " << j.metadata << " -> " << j.dump() << '\n'; + }); } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_lines.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_lines.cpp index 233c81a4..9dc71137 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_lines.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_lines.cpp @@ -1,22 +1,21 @@ -#include #include #include +#include using json = nlohmann::json; -int main() -{ - // JSON Lines (see https://jsonlines.org) - std::stringstream input; - input << R"({"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]} +int main() { + // JSON Lines (see https://jsonlines.org) + std::stringstream input; + input + << R"({"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]} {"name": "Alexa", "wins": [["two pair", "4♠"], ["two pair", "9♠"]]} {"name": "May", "wins": []} {"name": "Deloise", "wins": [["three of a kind", "5♣"]]} )"; - std::string line; - while (std::getline(input, line)) - { - std::cout << json::parse(line) << std::endl; - } + std::string line; + while (std::getline(input, line)) { + std::cout << json::parse(line) << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer.cpp index 8705cf49..9f2a5a98 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer.cpp @@ -3,45 +3,35 @@ using json = nlohmann::json; -int main() -{ - // correct JSON pointers - json::json_pointer p1; - json::json_pointer p2(""); - json::json_pointer p3("/"); - json::json_pointer p4("//"); - json::json_pointer p5("/foo/bar"); - json::json_pointer p6("/foo/bar/-"); - json::json_pointer p7("/foo/~0"); - json::json_pointer p8("/foo/~1"); +int main() { + // correct JSON pointers + json::json_pointer p1; + json::json_pointer p2(""); + json::json_pointer p3("/"); + json::json_pointer p4("//"); + json::json_pointer p5("/foo/bar"); + json::json_pointer p6("/foo/bar/-"); + json::json_pointer p7("/foo/~0"); + json::json_pointer p8("/foo/~1"); - // error: JSON pointer does not begin with a slash - try - { - json::json_pointer p9("foo"); - } - catch (const json::parse_error& e) - { - std::cout << e.what() << '\n'; - } + // error: JSON pointer does not begin with a slash + try { + json::json_pointer p9("foo"); + } catch (const json::parse_error &e) { + std::cout << e.what() << '\n'; + } - // error: JSON pointer uses escape symbol ~ not followed by 0 or 1 - try - { - json::json_pointer p10("/foo/~"); - } - catch (const json::parse_error& e) - { - std::cout << e.what() << '\n'; - } + // error: JSON pointer uses escape symbol ~ not followed by 0 or 1 + try { + json::json_pointer p10("/foo/~"); + } catch (const json::parse_error &e) { + std::cout << e.what() << '\n'; + } - // error: JSON pointer uses escape symbol ~ not followed by 0 or 1 - try - { - json::json_pointer p11("/foo/~3"); - } - catch (const json::parse_error& e) - { - std::cout << e.what() << '\n'; - } + // error: JSON pointer uses escape symbol ~ not followed by 0 or 1 + try { + json::json_pointer p11("/foo/~3"); + } catch (const json::parse_error &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__back.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__back.cpp index dd3b210b..950d95a1 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__back.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__back.cpp @@ -3,13 +3,14 @@ using json = nlohmann::json; -int main() -{ - // different JSON Pointers - json::json_pointer ptr1("/foo"); - json::json_pointer ptr2("/foo/0"); +int main() { + // different JSON Pointers + json::json_pointer ptr1("/foo"); + json::json_pointer ptr2("/foo/0"); - // call empty() - std::cout << "last reference token of \"" << ptr1 << "\" is \"" << ptr1.back() << "\"\n" - << "last reference token of \"" << ptr2 << "\" is \"" << ptr2.back() << "\"" << std::endl; + // call empty() + std::cout << "last reference token of \"" << ptr1 << "\" is \"" << ptr1.back() + << "\"\n" + << "last reference token of \"" << ptr2 << "\" is \"" << ptr2.back() + << "\"" << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__empty.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__empty.cpp index 57257e8b..50cd31b8 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__empty.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__empty.cpp @@ -3,18 +3,16 @@ using json = nlohmann::json; -int main() -{ - // different JSON Pointers - json::json_pointer ptr0; - json::json_pointer ptr1(""); - json::json_pointer ptr2("/foo"); - json::json_pointer ptr3("/foo/0"); +int main() { + // different JSON Pointers + json::json_pointer ptr0; + json::json_pointer ptr1(""); + json::json_pointer ptr2("/foo"); + json::json_pointer ptr3("/foo/0"); - // call empty() - std::cout << std::boolalpha - << "\"" << ptr0 << "\": " << ptr0.empty() << '\n' - << "\"" << ptr1 << "\": " << ptr1.empty() << '\n' - << "\"" << ptr2 << "\": " << ptr2.empty() << '\n' - << "\"" << ptr3 << "\": " << ptr3.empty() << std::endl; + // call empty() + std::cout << std::boolalpha << "\"" << ptr0 << "\": " << ptr0.empty() << '\n' + << "\"" << ptr1 << "\": " << ptr1.empty() << '\n' + << "\"" << ptr2 << "\": " << ptr2.empty() << '\n' + << "\"" << ptr3 << "\": " << ptr3.empty() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__equal.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__equal.cpp index dce6df03..241719ca 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__equal.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__equal.cpp @@ -3,17 +3,19 @@ using json = nlohmann::json; -int main() -{ - // different JSON pointers - json::json_pointer ptr0; - json::json_pointer ptr1(""); - json::json_pointer ptr2("/foo"); +int main() { + // different JSON pointers + json::json_pointer ptr0; + json::json_pointer ptr1(""); + json::json_pointer ptr2("/foo"); - // compare JSON pointers - std::cout << std::boolalpha - << "\"" << ptr0 << "\" == \"" << ptr0 << "\": " << (ptr0 == ptr0) << '\n' - << "\"" << ptr0 << "\" == \"" << ptr1 << "\": " << (ptr0 == ptr1) << '\n' - << "\"" << ptr1 << "\" == \"" << ptr2 << "\": " << (ptr1 == ptr2) << '\n' - << "\"" << ptr2 << "\" == \"" << ptr2 << "\": " << (ptr2 == ptr2) << std::endl; + // compare JSON pointers + std::cout << std::boolalpha << "\"" << ptr0 << "\" == \"" << ptr0 + << "\": " << (ptr0 == ptr0) << '\n' + << "\"" << ptr0 << "\" == \"" << ptr1 << "\": " << (ptr0 == ptr1) + << '\n' + << "\"" << ptr1 << "\" == \"" << ptr2 << "\": " << (ptr1 == ptr2) + << '\n' + << "\"" << ptr2 << "\" == \"" << ptr2 << "\": " << (ptr2 == ptr2) + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__equal_stringtype.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__equal_stringtype.cpp index af8ec5a2..27ac2ba0 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__equal_stringtype.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__equal_stringtype.cpp @@ -4,30 +4,29 @@ using json = nlohmann::json; -int main() -{ - // different JSON pointers - json::json_pointer ptr0; - json::json_pointer ptr1(""); - json::json_pointer ptr2("/foo"); +int main() { + // different JSON pointers + json::json_pointer ptr0; + json::json_pointer ptr1(""); + json::json_pointer ptr2("/foo"); - // different strings - std::string str0(""); - std::string str1("/foo"); - std::string str2("bar"); + // different strings + std::string str0(""); + std::string str1("/foo"); + std::string str2("bar"); - // compare JSON pointers and strings - std::cout << std::boolalpha - << "\"" << ptr0 << "\" == \"" << str0 << "\": " << (ptr0 == str0) << '\n' - << "\"" << str0 << "\" == \"" << ptr1 << "\": " << (str0 == ptr1) << '\n' - << "\"" << ptr2 << "\" == \"" << str1 << "\": " << (ptr2 == str1) << std::endl; + // compare JSON pointers and strings + std::cout << std::boolalpha << "\"" << ptr0 << "\" == \"" << str0 + << "\": " << (ptr0 == str0) << '\n' + << "\"" << str0 << "\" == \"" << ptr1 << "\": " << (str0 == ptr1) + << '\n' + << "\"" << ptr2 << "\" == \"" << str1 << "\": " << (ptr2 == str1) + << std::endl; - try - { - std::cout << "\"" << str2 << "\" == \"" << ptr2 << "\": " << (str2 == ptr2) << std::endl; - } - catch (const json::parse_error& ex) - { - std::cout << ex.what() << std::endl; - } + try { + std::cout << "\"" << str2 << "\" == \"" << ptr2 << "\": " << (str2 == ptr2) + << std::endl; + } catch (const json::parse_error &ex) { + std::cout << ex.what() << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__notequal.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__notequal.cpp index 9bbdd531..a8cdef19 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__notequal.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__notequal.cpp @@ -3,17 +3,19 @@ using json = nlohmann::json; -int main() -{ - // different JSON pointers - json::json_pointer ptr0; - json::json_pointer ptr1(""); - json::json_pointer ptr2("/foo"); +int main() { + // different JSON pointers + json::json_pointer ptr0; + json::json_pointer ptr1(""); + json::json_pointer ptr2("/foo"); - // compare JSON pointers - std::cout << std::boolalpha - << "\"" << ptr0 << "\" != \"" << ptr0 << "\": " << (ptr0 != ptr0) << '\n' - << "\"" << ptr0 << "\" != \"" << ptr1 << "\": " << (ptr0 != ptr1) << '\n' - << "\"" << ptr1 << "\" != \"" << ptr2 << "\": " << (ptr1 != ptr2) << '\n' - << "\"" << ptr2 << "\" != \"" << ptr2 << "\": " << (ptr2 != ptr2) << std::endl; + // compare JSON pointers + std::cout << std::boolalpha << "\"" << ptr0 << "\" != \"" << ptr0 + << "\": " << (ptr0 != ptr0) << '\n' + << "\"" << ptr0 << "\" != \"" << ptr1 << "\": " << (ptr0 != ptr1) + << '\n' + << "\"" << ptr1 << "\" != \"" << ptr2 << "\": " << (ptr1 != ptr2) + << '\n' + << "\"" << ptr2 << "\" != \"" << ptr2 << "\": " << (ptr2 != ptr2) + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__notequal_stringtype.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__notequal_stringtype.cpp index b9b89872..27f85a2e 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__notequal_stringtype.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator__notequal_stringtype.cpp @@ -3,30 +3,29 @@ using json = nlohmann::json; -int main() -{ - // different JSON pointers - json::json_pointer ptr0; - json::json_pointer ptr1(""); - json::json_pointer ptr2("/foo"); +int main() { + // different JSON pointers + json::json_pointer ptr0; + json::json_pointer ptr1(""); + json::json_pointer ptr2("/foo"); - // different strings - std::string str0(""); - std::string str1("/foo"); - std::string str2("bar"); + // different strings + std::string str0(""); + std::string str1("/foo"); + std::string str2("bar"); - // compare JSON pointers and strings - std::cout << std::boolalpha - << "\"" << ptr0 << "\" != \"" << str0 << "\": " << (ptr0 != str0) << '\n' - << "\"" << str0 << "\" != \"" << ptr1 << "\": " << (str0 != ptr1) << '\n' - << "\"" << ptr2 << "\" != \"" << str1 << "\": " << (ptr2 != str1) << std::endl; + // compare JSON pointers and strings + std::cout << std::boolalpha << "\"" << ptr0 << "\" != \"" << str0 + << "\": " << (ptr0 != str0) << '\n' + << "\"" << str0 << "\" != \"" << ptr1 << "\": " << (str0 != ptr1) + << '\n' + << "\"" << ptr2 << "\" != \"" << str1 << "\": " << (ptr2 != str1) + << std::endl; - try - { - std::cout << "\"" << str2 << "\" != \"" << ptr2 << "\": " << (str2 != ptr2) << std::endl; - } - catch (const json::parse_error& ex) - { - std::cout << ex.what() << std::endl; - } + try { + std::cout << "\"" << str2 << "\" != \"" << ptr2 << "\": " << (str2 != ptr2) + << std::endl; + } catch (const json::parse_error &ex) { + std::cout << ex.what() << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_add.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_add.cpp index 14bd7456..2a67c636 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_add.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_add.cpp @@ -3,21 +3,20 @@ using json = nlohmann::json; -int main() -{ - // create a JSON pointer - json::json_pointer ptr("/foo"); - std::cout << "\"" << ptr << "\"\n"; +int main() { + // create a JSON pointer + json::json_pointer ptr("/foo"); + std::cout << "\"" << ptr << "\"\n"; - // append a JSON Pointer - ptr /= json::json_pointer("/bar/baz"); - std::cout << "\"" << ptr << "\"\n"; + // append a JSON Pointer + ptr /= json::json_pointer("/bar/baz"); + std::cout << "\"" << ptr << "\"\n"; - // append a string - ptr /= "fob"; - std::cout << "\"" << ptr << "\"\n"; + // append a string + ptr /= "fob"; + std::cout << "\"" << ptr << "\"\n"; - // append an array index - ptr /= 42; - std::cout << "\"" << ptr << "\"" << std::endl; + // append an array index + ptr /= 42; + std::cout << "\"" << ptr << "\"" << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_add_binary.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_add_binary.cpp index d26a0d17..b96395e5 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_add_binary.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_add_binary.cpp @@ -3,17 +3,17 @@ using json = nlohmann::json; -int main() -{ - // create a JSON pointer - json::json_pointer ptr("/foo"); +int main() { + // create a JSON pointer + json::json_pointer ptr("/foo"); - // append a JSON Pointer - std::cout << "\"" << ptr / json::json_pointer("/bar/baz") << "\"\n"; + // append a JSON Pointer + std::cout << "\"" << ptr / json::json_pointer("/bar/baz") << "\"\n"; - // append a string - std::cout << "\"" << ptr / "fob" << "\"\n"; + // append a string + std::cout << "\"" << ptr / "fob" + << "\"\n"; - // append an array index - std::cout << "\"" << ptr / 42 << "\"" << std::endl; + // append an array index + std::cout << "\"" << ptr / 42 << "\"" << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_string_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_string_t.cpp index 56f21302..80863b1f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_string_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__operator_string_t.cpp @@ -3,17 +3,16 @@ using json = nlohmann::json; -int main() -{ - // different JSON Pointers - json::json_pointer ptr1("/foo/0"); - json::json_pointer ptr2("/a~1b"); +int main() { + // different JSON Pointers + json::json_pointer ptr1("/foo/0"); + json::json_pointer ptr2("/a~1b"); - // implicit conversion to string - std::string s; - s += ptr1; - s += "\n"; - s += ptr2; + // implicit conversion to string + std::string s; + s += ptr1; + s += "\n"; + s += ptr2; - std::cout << s << std::endl; + std::cout << s << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__parent_pointer.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__parent_pointer.cpp index ef9df453..81cad5e7 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__parent_pointer.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__parent_pointer.cpp @@ -3,16 +3,17 @@ using json = nlohmann::json; -int main() -{ - // different JSON Pointers - json::json_pointer ptr1(""); - json::json_pointer ptr2("/foo"); - json::json_pointer ptr3("/foo/0"); +int main() { + // different JSON Pointers + json::json_pointer ptr1(""); + json::json_pointer ptr2("/foo"); + json::json_pointer ptr3("/foo/0"); - // call parent_pointer() - std::cout << std::boolalpha - << "parent of \"" << ptr1 << "\" is \"" << ptr1.parent_pointer() << "\"\n" - << "parent of \"" << ptr2 << "\" is \"" << ptr2.parent_pointer() << "\"\n" - << "parent of \"" << ptr3 << "\" is \"" << ptr3.parent_pointer() << "\"" << std::endl; + // call parent_pointer() + std::cout << std::boolalpha << "parent of \"" << ptr1 << "\" is \"" + << ptr1.parent_pointer() << "\"\n" + << "parent of \"" << ptr2 << "\" is \"" << ptr2.parent_pointer() + << "\"\n" + << "parent of \"" << ptr3 << "\" is \"" << ptr3.parent_pointer() + << "\"" << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__pop_back.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__pop_back.cpp index fd077b7e..0e670e38 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__pop_back.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__pop_back.cpp @@ -3,19 +3,18 @@ using json = nlohmann::json; -int main() -{ - // create empty JSON Pointer - json::json_pointer ptr("/foo/bar/baz"); - std::cout << "\"" << ptr << "\"\n"; +int main() { + // create empty JSON Pointer + json::json_pointer ptr("/foo/bar/baz"); + std::cout << "\"" << ptr << "\"\n"; - // call pop_back() - ptr.pop_back(); - std::cout << "\"" << ptr << "\"\n"; + // call pop_back() + ptr.pop_back(); + std::cout << "\"" << ptr << "\"\n"; - ptr.pop_back(); - std::cout << "\"" << ptr << "\"\n"; + ptr.pop_back(); + std::cout << "\"" << ptr << "\"\n"; - ptr.pop_back(); - std::cout << "\"" << ptr << "\"\n"; + ptr.pop_back(); + std::cout << "\"" << ptr << "\"\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__push_back.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__push_back.cpp index e6b59a12..974eba0a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__push_back.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__push_back.cpp @@ -3,19 +3,18 @@ using json = nlohmann::json; -int main() -{ - // create empty JSON Pointer - json::json_pointer ptr; - std::cout << "\"" << ptr << "\"\n"; +int main() { + // create empty JSON Pointer + json::json_pointer ptr; + std::cout << "\"" << ptr << "\"\n"; - // call push_back() - ptr.push_back("foo"); - std::cout << "\"" << ptr << "\"\n"; + // call push_back() + ptr.push_back("foo"); + std::cout << "\"" << ptr << "\"\n"; - ptr.push_back("0"); - std::cout << "\"" << ptr << "\"\n"; + ptr.push_back("0"); + std::cout << "\"" << ptr << "\"\n"; - ptr.push_back("bar"); - std::cout << "\"" << ptr << "\"\n"; + ptr.push_back("bar"); + std::cout << "\"" << ptr << "\"\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__string_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__string_t.cpp index fbe0f179..ec27b400 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__string_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__string_t.cpp @@ -3,11 +3,12 @@ using json = nlohmann::json; -int main() -{ - json::json_pointer::string_t s = "This is a string."; +int main() { + json::json_pointer::string_t s = "This is a string."; - std::cout << s << std::endl; + std::cout << s << std::endl; - std::cout << std::boolalpha << std::is_same::value << std::endl; + std::cout << std::boolalpha + << std::is_same::value + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__to_string.cpp b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__to_string.cpp index 31d35a72..823e12ff 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__to_string.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/json_pointer__to_string.cpp @@ -3,32 +3,31 @@ using json = nlohmann::json; -int main() -{ - // different JSON Pointers - json::json_pointer ptr1(""); - json::json_pointer ptr2("/foo"); - json::json_pointer ptr3("/foo/0"); - json::json_pointer ptr4("/"); - json::json_pointer ptr5("/a~1b"); - json::json_pointer ptr6("/c%d"); - json::json_pointer ptr7("/e^f"); - json::json_pointer ptr8("/g|h"); - json::json_pointer ptr9("/i\\j"); - json::json_pointer ptr10("/k\"l"); - json::json_pointer ptr11("/ "); - json::json_pointer ptr12("/m~0n"); +int main() { + // different JSON Pointers + json::json_pointer ptr1(""); + json::json_pointer ptr2("/foo"); + json::json_pointer ptr3("/foo/0"); + json::json_pointer ptr4("/"); + json::json_pointer ptr5("/a~1b"); + json::json_pointer ptr6("/c%d"); + json::json_pointer ptr7("/e^f"); + json::json_pointer ptr8("/g|h"); + json::json_pointer ptr9("/i\\j"); + json::json_pointer ptr10("/k\"l"); + json::json_pointer ptr11("/ "); + json::json_pointer ptr12("/m~0n"); - std::cout << "\"" << ptr1.to_string() << "\"\n" - << "\"" << ptr2.to_string() << "\"\n" - << "\"" << ptr3.to_string() << "\"\n" - << "\"" << ptr4.to_string() << "\"\n" - << "\"" << ptr5.to_string() << "\"\n" - << "\"" << ptr6.to_string() << "\"\n" - << "\"" << ptr7.to_string() << "\"\n" - << "\"" << ptr8.to_string() << "\"\n" - << "\"" << ptr9.to_string() << "\"\n" - << "\"" << ptr10.to_string() << "\"\n" - << "\"" << ptr11.to_string() << "\"\n" - << "\"" << ptr12.to_string() << "\"" << std::endl; + std::cout << "\"" << ptr1.to_string() << "\"\n" + << "\"" << ptr2.to_string() << "\"\n" + << "\"" << ptr3.to_string() << "\"\n" + << "\"" << ptr4.to_string() << "\"\n" + << "\"" << ptr5.to_string() << "\"\n" + << "\"" << ptr6.to_string() << "\"\n" + << "\"" << ptr7.to_string() << "\"\n" + << "\"" << ptr8.to_string() << "\"\n" + << "\"" << ptr9.to_string() << "\"\n" + << "\"" << ptr10.to_string() << "\"\n" + << "\"" << ptr11.to_string() << "\"\n" + << "\"" << ptr12.to_string() << "\"" << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/max_size.cpp b/nlohmann_json/docs/mkdocs/docs/examples/max_size.cpp index c2ffc546..9de88ed9 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/max_size.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/max_size.cpp @@ -3,23 +3,22 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; - // call max_size() - std::cout << j_null.max_size() << '\n'; - std::cout << j_boolean.max_size() << '\n'; - std::cout << j_number_integer.max_size() << '\n'; - std::cout << j_number_float.max_size() << '\n'; - std::cout << j_object.max_size() << '\n'; - std::cout << j_array.max_size() << '\n'; - std::cout << j_string.max_size() << '\n'; + // call max_size() + std::cout << j_null.max_size() << '\n'; + std::cout << j_boolean.max_size() << '\n'; + std::cout << j_number_integer.max_size() << '\n'; + std::cout << j_number_float.max_size() << '\n'; + std::cout << j_object.max_size() << '\n'; + std::cout << j_array.max_size() << '\n'; + std::cout << j_string.max_size() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/merge_patch.cpp b/nlohmann_json/docs/mkdocs/docs/examples/merge_patch.cpp index f3fee1ed..b5a21f21 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/merge_patch.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/merge_patch.cpp @@ -1,14 +1,13 @@ +#include // for std::setw #include #include -#include // for std::setw using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // the original document - json document = R"({ +int main() { + // the original document + json document = R"({ "title": "Goodbye!", "author": { "givenName": "John", @@ -21,8 +20,8 @@ int main() "content": "This will be unchanged" })"_json; - // the patch - json patch = R"({ + // the patch + json patch = R"({ "title": "Hello!", "phoneNumber": "+01-123-456-7890", "author": { @@ -33,9 +32,9 @@ int main() ] })"_json; - // apply the patch - document.merge_patch(patch); + // apply the patch + document.merge_patch(patch); - // output original and patched document - std::cout << std::setw(4) << document << std::endl; + // output original and patched document + std::cout << std::setw(4) << document << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/meta.cpp b/nlohmann_json/docs/mkdocs/docs/examples/meta.cpp index a051575b..7b236ced 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/meta.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/meta.cpp @@ -1,11 +1,10 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // call meta() - std::cout << std::setw(4) << json::meta() << '\n'; +int main() { + // call meta() + std::cout << std::setw(4) << json::meta() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_derived_type_intrusive_macro.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_derived_type_intrusive_macro.cpp index 0dca7816..f4e11bbb 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_derived_type_intrusive_macro.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_derived_type_intrusive_macro.cpp @@ -1,37 +1,34 @@ -#include #include +#include #include using nlohmann::json; -class A -{ - private: - double Aa = 0.0; - double Ab = 0.0; +class A { +private: + double Aa = 0.0; + double Ab = 0.0; - public: - A() = default; - A(double a, double b) : Aa(a), Ab(b) {} - NLOHMANN_DEFINE_TYPE_INTRUSIVE(A, Aa, Ab) +public: + A() = default; + A(double a, double b) : Aa(a), Ab(b) {} + NLOHMANN_DEFINE_TYPE_INTRUSIVE(A, Aa, Ab) }; -class B : public A -{ - private: - int Ba = 0; - int Bb = 0; +class B : public A { +private: + int Ba = 0; + int Bb = 0; - public: - B() = default; - B(int a, int b, double aa, double ab) : A(aa, ab), Ba(a), Bb(b) {} - NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(B, A, Ba, Bb) +public: + B() = default; + B(int a, int b, double aa, double ab) : A(aa, ab), Ba(a), Bb(b) {} + NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(B, A, Ba, Bb) }; -int main() -{ - B example(23, 42, 3.142, 1.777); - json example_json = example; +int main() { + B example(23, 42, 3.142, 1.777); + json example_json = example; - std::cout << std::setw(4) << example_json << std::endl; + std::cout << std::setw(4) << example_json << std::endl; } \ No newline at end of file diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_explicit.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_explicit.cpp index e2021e23..d1d6ba78 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_explicit.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_explicit.cpp @@ -4,59 +4,54 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -class person -{ - private: - std::string name = "John Doe"; - std::string address = "123 Fake St"; - int age = -1; - - public: - person() = default; - person(std::string name_, std::string address_, int age_) - : name(std::move(name_)), address(std::move(address_)), age(age_) - {} - - template - friend void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t) - { - nlohmann_json_j["name"] = nlohmann_json_t.name; - nlohmann_json_j["address"] = nlohmann_json_t.address; - nlohmann_json_j["age"] = nlohmann_json_t.age; - } - - template - friend void from_json(const BasicJsonType& nlohmann_json_j, person& nlohmann_json_t) - { - nlohmann_json_t.name = nlohmann_json_j.at("name"); - nlohmann_json_t.address = nlohmann_json_j.at("address"); - nlohmann_json_t.age = nlohmann_json_j.at("age"); - } +namespace ns { +class person { +private: + std::string name = "John Doe"; + std::string address = "123 Fake St"; + int age = -1; + +public: + person() = default; + person(std::string name_, std::string address_, int age_) + : name(std::move(name_)), address(std::move(address_)), age(age_) {} + + template + friend void to_json(BasicJsonType &nlohmann_json_j, + const person &nlohmann_json_t) { + nlohmann_json_j["name"] = nlohmann_json_t.name; + nlohmann_json_j["address"] = nlohmann_json_t.address; + nlohmann_json_j["age"] = nlohmann_json_t.age; + } + + template + friend void from_json(const BasicJsonType &nlohmann_json_j, + person &nlohmann_json_t) { + nlohmann_json_t.name = nlohmann_json_j.at("name"); + nlohmann_json_t.address = nlohmann_json_j.at("address"); + nlohmann_json_t.age = nlohmann_json_j.at("age"); + } }; } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; - - // deserialization: json -> person - json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; - auto p2 = j2.template get(); - - // incomplete deserialization: - json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; - try - { - auto p3 = j3.template get(); - } - catch (const json::exception& e) - { - std::cout << "deserialization failed: " << e.what() << std::endl; - } +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; + + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; + + // deserialization: json -> person + json j2 = + R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; + auto p2 = j2.template get(); + + // incomplete deserialization: + json j3 = + R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; + try { + auto p3 = j3.template get(); + } catch (const json::exception &e) { + std::cout << "deserialization failed: " << e.what() << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_macro.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_macro.cpp index 4ecd4294..985d9e95 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_macro.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_macro.cpp @@ -4,45 +4,40 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -class person -{ - private: - std::string name = "John Doe"; - std::string address = "123 Fake St"; - int age = -1; - - public: - person() = default; - person(std::string name_, std::string address_, int age_) - : name(std::move(name_)), address(std::move(address_)), age(age_) - {} - - NLOHMANN_DEFINE_TYPE_INTRUSIVE(person, name, address, age) +namespace ns { +class person { +private: + std::string name = "John Doe"; + std::string address = "123 Fake St"; + int age = -1; + +public: + person() = default; + person(std::string name_, std::string address_, int age_) + : name(std::move(name_)), address(std::move(address_)), age(age_) {} + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(person, name, address, age) }; } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; - - // deserialization: json -> person - json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; - auto p2 = j2.template get(); - - // incomplete deserialization: - json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; - try - { - auto p3 = j3.template get(); - } - catch (const json::exception& e) - { - std::cout << "deserialization failed: " << e.what() << std::endl; - } +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; + + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; + + // deserialization: json -> person + json j2 = + R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; + auto p2 = j2.template get(); + + // incomplete deserialization: + json j3 = + R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; + try { + auto p3 = j3.template get(); + } catch (const json::exception &e) { + std::cout << "deserialization failed: " << e.what() << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_only_serialize_explicit.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_only_serialize_explicit.cpp index dd6a9a67..b66627dd 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_only_serialize_explicit.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_only_serialize_explicit.cpp @@ -4,36 +4,32 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -class person -{ - private: - std::string name = "John Doe"; - std::string address = "123 Fake St"; - int age = -1; +namespace ns { +class person { +private: + std::string name = "John Doe"; + std::string address = "123 Fake St"; + int age = -1; - public: - // No default constructor - person(std::string name_, std::string address_, int age_) - : name(std::move(name_)), address(std::move(address_)), age(age_) - {} +public: + // No default constructor + person(std::string name_, std::string address_, int age_) + : name(std::move(name_)), address(std::move(address_)), age(age_) {} - template - friend void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t) - { - nlohmann_json_j["name"] = nlohmann_json_t.name; - nlohmann_json_j["address"] = nlohmann_json_t.address; - nlohmann_json_j["age"] = nlohmann_json_t.age; - } + template + friend void to_json(BasicJsonType &nlohmann_json_j, + const person &nlohmann_json_t) { + nlohmann_json_j["name"] = nlohmann_json_t.name; + nlohmann_json_j["address"] = nlohmann_json_t.address; + nlohmann_json_j["age"] = nlohmann_json_t.age; + } }; } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_only_serialize_macro.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_only_serialize_macro.cpp index 8213f906..4d9af3b2 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_only_serialize_macro.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_only_serialize_macro.cpp @@ -4,30 +4,26 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -class person -{ - private: - std::string name = "John Doe"; - std::string address = "123 Fake St"; - int age = -1; +namespace ns { +class person { +private: + std::string name = "John Doe"; + std::string address = "123 Fake St"; + int age = -1; - public: - // No default constructor - person(std::string name_, std::string address_, int age_) - : name(std::move(name_)), address(std::move(address_)), age(age_) - {} +public: + // No default constructor + person(std::string name_, std::string address_, int age_) + : name(std::move(name_)), address(std::move(address_)), age(age_) {} - NLOHMANN_DEFINE_TYPE_INTRUSIVE(person, name, address, age) + NLOHMANN_DEFINE_TYPE_INTRUSIVE(person, name, address, age) }; } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_with_default_explicit.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_with_default_explicit.cpp index 39779557..acf46aa7 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_with_default_explicit.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_with_default_explicit.cpp @@ -4,54 +4,55 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -class person -{ - private: - std::string name = "John Doe"; - std::string address = "123 Fake St"; - int age = -1; - - public: - person() = default; - person(std::string name_, std::string address_, int age_) - : name(std::move(name_)), address(std::move(address_)), age(age_) - {} - - template - friend void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t) - { - nlohmann_json_j["name"] = nlohmann_json_t.name; - nlohmann_json_j["address"] = nlohmann_json_t.address; - nlohmann_json_j["age"] = nlohmann_json_t.age; - } - - template - friend void from_json(const BasicJsonType& nlohmann_json_j, person& nlohmann_json_t) - { - person nlohmann_json_default_obj; - nlohmann_json_t.name = nlohmann_json_j.value("name", nlohmann_json_default_obj.name); - nlohmann_json_t.address = nlohmann_json_j.value("address", nlohmann_json_default_obj.address); - nlohmann_json_t.age = nlohmann_json_j.value("age", nlohmann_json_default_obj.age); - } +namespace ns { +class person { +private: + std::string name = "John Doe"; + std::string address = "123 Fake St"; + int age = -1; + +public: + person() = default; + person(std::string name_, std::string address_, int age_) + : name(std::move(name_)), address(std::move(address_)), age(age_) {} + + template + friend void to_json(BasicJsonType &nlohmann_json_j, + const person &nlohmann_json_t) { + nlohmann_json_j["name"] = nlohmann_json_t.name; + nlohmann_json_j["address"] = nlohmann_json_t.address; + nlohmann_json_j["age"] = nlohmann_json_t.age; + } + + template + friend void from_json(const BasicJsonType &nlohmann_json_j, + person &nlohmann_json_t) { + person nlohmann_json_default_obj; + nlohmann_json_t.name = + nlohmann_json_j.value("name", nlohmann_json_default_obj.name); + nlohmann_json_t.address = + nlohmann_json_j.value("address", nlohmann_json_default_obj.address); + nlohmann_json_t.age = + nlohmann_json_j.value("age", nlohmann_json_default_obj.age); + } }; } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; - // deserialization: json -> person - json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; - auto p2 = j2.template get(); + // deserialization: json -> person + json j2 = + R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; + auto p2 = j2.template get(); - // incomplete deserialization: - json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; - auto p3 = j3.template get(); - std::cout << "roundtrip: " << json(p3) << std::endl; + // incomplete deserialization: + json j3 = + R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; + auto p3 = j3.template get(); + std::cout << "roundtrip: " << json(p3) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_with_default_macro.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_with_default_macro.cpp index 52668516..3588ead0 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_with_default_macro.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_with_default_macro.cpp @@ -4,39 +4,37 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -class person -{ - private: - std::string name = "John Doe"; - std::string address = "123 Fake St"; - int age = -1; - - public: - person() = default; - person(std::string name_, std::string address_, int age_) - : name(std::move(name_)), address(std::move(address_)), age(age_) - {} - - NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(person, name, address, age) +namespace ns { +class person { +private: + std::string name = "John Doe"; + std::string address = "123 Fake St"; + int age = -1; + +public: + person() = default; + person(std::string name_, std::string address_, int age_) + : name(std::move(name_)), address(std::move(address_)), age(age_) {} + + NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(person, name, address, age) }; } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; - // deserialization: json -> person - json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; - auto p2 = j2.template get(); + // deserialization: json -> person + json j2 = + R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; + auto p2 = j2.template get(); - // incomplete deserialization: - json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; - auto p3 = j3.template get(); - std::cout << "roundtrip: " << json(p3) << std::endl; + // incomplete deserialization: + json j3 = + R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; + auto p3 = j3.template get(); + std::cout << "roundtrip: " << json(p3) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_explicit.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_explicit.cpp index 9f5cdc17..4d0abed6 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_explicit.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_explicit.cpp @@ -4,52 +4,46 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -struct person -{ - std::string name; - std::string address; - int age; +namespace ns { +struct person { + std::string name; + std::string address; + int age; }; -template -void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t) -{ - nlohmann_json_j["name"] = nlohmann_json_t.name; - nlohmann_json_j["address"] = nlohmann_json_t.address; - nlohmann_json_j["age"] = nlohmann_json_t.age; +template +void to_json(BasicJsonType &nlohmann_json_j, const person &nlohmann_json_t) { + nlohmann_json_j["name"] = nlohmann_json_t.name; + nlohmann_json_j["address"] = nlohmann_json_t.address; + nlohmann_json_j["age"] = nlohmann_json_t.age; } -template -void from_json(const BasicJsonType& nlohmann_json_j, person& nlohmann_json_t) -{ - nlohmann_json_t.name = nlohmann_json_j.at("name"); - nlohmann_json_t.address = nlohmann_json_j.at("address"); - nlohmann_json_t.age = nlohmann_json_j.at("age"); +template +void from_json(const BasicJsonType &nlohmann_json_j, person &nlohmann_json_t) { + nlohmann_json_t.name = nlohmann_json_j.at("name"); + nlohmann_json_t.address = nlohmann_json_j.at("address"); + nlohmann_json_t.age = nlohmann_json_j.at("age"); } } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; - - // deserialization: json -> person - json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; - auto p2 = j2.template get(); - - // incomplete deserialization: - json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; - try - { - auto p3 = j3.template get(); - } - catch (const json::exception& e) - { - std::cout << "deserialization failed: " << e.what() << std::endl; - } +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; + + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; + + // deserialization: json -> person + json j2 = + R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; + auto p2 = j2.template get(); + + // incomplete deserialization: + json j3 = + R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; + try { + auto p3 = j3.template get(); + } catch (const json::exception &e) { + std::cout << "deserialization failed: " << e.what() << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_macro.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_macro.cpp index d11691b7..26121d97 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_macro.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_macro.cpp @@ -4,38 +4,34 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -struct person -{ - std::string name; - std::string address; - int age; +namespace ns { +struct person { + std::string name; + std::string address; + int age; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person, name, address, age) } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; - // deserialization: json -> person - json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; - auto p2 = j2.template get(); + // deserialization: json -> person + json j2 = + R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; + auto p2 = j2.template get(); - // incomplete deserialization: - json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; - try - { - auto p3 = j3.template get(); - } - catch (const json::exception& e) - { - std::cout << "deserialization failed: " << e.what() << std::endl; - } + // incomplete deserialization: + json j3 = + R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; + try { + auto p3 = j3.template get(); + } catch (const json::exception &e) { + std::cout << "deserialization failed: " << e.what() << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_only_serialize_explicit.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_only_serialize_explicit.cpp index ead75b74..11cdf268 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_only_serialize_explicit.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_only_serialize_explicit.cpp @@ -4,29 +4,25 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -struct person -{ - std::string name; - std::string address; - int age; +namespace ns { +struct person { + std::string name; + std::string address; + int age; }; -template -void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t) -{ - nlohmann_json_j["name"] = nlohmann_json_t.name; - nlohmann_json_j["address"] = nlohmann_json_t.address; - nlohmann_json_j["age"] = nlohmann_json_t.age; +template +void to_json(BasicJsonType &nlohmann_json_j, const person &nlohmann_json_t) { + nlohmann_json_j["name"] = nlohmann_json_t.name; + nlohmann_json_j["address"] = nlohmann_json_t.address; + nlohmann_json_j["age"] = nlohmann_json_t.age; } } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_only_serialize_macro.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_only_serialize_macro.cpp index 7aef23af..6031d5de 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_only_serialize_macro.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_only_serialize_macro.cpp @@ -4,23 +4,20 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -struct person -{ - std::string name; - std::string address; - int age; +namespace ns { +struct person { + std::string name; + std::string address; + int age; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(person, name, address, age) } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_with_default_explicit.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_with_default_explicit.cpp index 1bdd25ed..dcefd796 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_with_default_explicit.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_with_default_explicit.cpp @@ -4,52 +4,51 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -struct person -{ - std::string name = "John Doe"; - std::string address = "123 Fake St"; - int age = -1; - - person() = default; - person(std::string name_, std::string address_, int age_) - : name(std::move(name_)), address(std::move(address_)), age(age_) - {} +namespace ns { +struct person { + std::string name = "John Doe"; + std::string address = "123 Fake St"; + int age = -1; + + person() = default; + person(std::string name_, std::string address_, int age_) + : name(std::move(name_)), address(std::move(address_)), age(age_) {} }; -template -void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t) -{ - nlohmann_json_j["name"] = nlohmann_json_t.name; - nlohmann_json_j["address"] = nlohmann_json_t.address; - nlohmann_json_j["age"] = nlohmann_json_t.age; +template +void to_json(BasicJsonType &nlohmann_json_j, const person &nlohmann_json_t) { + nlohmann_json_j["name"] = nlohmann_json_t.name; + nlohmann_json_j["address"] = nlohmann_json_t.address; + nlohmann_json_j["age"] = nlohmann_json_t.age; } -template -void from_json(const BasicJsonType& nlohmann_json_j, person& nlohmann_json_t) -{ - person nlohmann_json_default_obj; - nlohmann_json_t.name = nlohmann_json_j.value("name", nlohmann_json_default_obj.name); - nlohmann_json_t.address = nlohmann_json_j.value("address", nlohmann_json_default_obj.address); - nlohmann_json_t.age = nlohmann_json_j.value("age", nlohmann_json_default_obj.age); +template +void from_json(const BasicJsonType &nlohmann_json_j, person &nlohmann_json_t) { + person nlohmann_json_default_obj; + nlohmann_json_t.name = + nlohmann_json_j.value("name", nlohmann_json_default_obj.name); + nlohmann_json_t.address = + nlohmann_json_j.value("address", nlohmann_json_default_obj.address); + nlohmann_json_t.age = + nlohmann_json_j.value("age", nlohmann_json_default_obj.age); } } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; - // deserialization: json -> person - json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; - auto p2 = j2.template get(); + // deserialization: json -> person + json j2 = + R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; + auto p2 = j2.template get(); - // incomplete deserialization: - json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; - auto p3 = j3.template get(); - std::cout << "roundtrip: " << json(p3) << std::endl; + // incomplete deserialization: + json j3 = + R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; + auto p3 = j3.template get(); + std::cout << "roundtrip: " << json(p3) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_with_default_macro.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_with_default_macro.cpp index 8c41c65e..a83f24d4 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_with_default_macro.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_with_default_macro.cpp @@ -4,37 +4,35 @@ using json = nlohmann::json; using namespace nlohmann::literals; -namespace ns -{ -struct person -{ - std::string name = "John Doe"; - std::string address = "123 Fake St"; - int age = -1; - - person() = default; - person(std::string name_, std::string address_, int age_) - : name(std::move(name_)), address(std::move(address_)), age(age_) - {} +namespace ns { +struct person { + std::string name = "John Doe"; + std::string address = "123 Fake St"; + int age = -1; + + person() = default; + person(std::string name_, std::string address_, int age_) + : name(std::move(name_)), address(std::move(address_)), age(age_) {} }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(person, name, address, age) } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - // serialization: person -> json - json j = p; - std::cout << "serialization: " << j << std::endl; + // serialization: person -> json + json j = p; + std::cout << "serialization: " << j << std::endl; - // deserialization: json -> person - json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; - auto p2 = j2.template get(); + // deserialization: json -> person + json j2 = + R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json; + auto p2 = j2.template get(); - // incomplete deserialization: - json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; - auto p3 = j3.template get(); - std::cout << "roundtrip: " << json(p3) << std::endl; + // incomplete deserialization: + json j3 = + R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json; + auto p3 = j3.template get(); + std::cout << "roundtrip: " << json(p3) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace.cpp index 4bad91f4..b3f1c98a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace.cpp @@ -8,7 +8,4 @@ using json = NLOHMANN_JSON_NAMESPACE::json; #define Q(x) #x #define QUOTE(x) Q(x) -int main() -{ - std::cout << QUOTE(NLOHMANN_JSON_NAMESPACE) << std::endl; -} +int main() { std::cout << QUOTE(NLOHMANN_JSON_NAMESPACE) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace_begin.c++17.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace_begin.c++17.cpp index 9385d593..0e68403d 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace_begin.c++17.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace_begin.c++17.cpp @@ -1,33 +1,27 @@ #include -#include #include +#include -// partial specialization (see https://json.nlohmann.me/features/arbitrary_types/) +// partial specialization (see +// https://json.nlohmann.me/features/arbitrary_types/) NLOHMANN_JSON_NAMESPACE_BEGIN -template -struct adl_serializer> -{ - static void to_json(json& j, const std::optional& opt) - { - if (opt == std::nullopt) - { - j = nullptr; - } - else - { - j = *opt; - } +template struct adl_serializer> { + static void to_json(json &j, const std::optional &opt) { + if (opt == std::nullopt) { + j = nullptr; + } else { + j = *opt; } + } }; NLOHMANN_JSON_NAMESPACE_END -int main() -{ - std::optional o1 = 1; - std::optional o2 = std::nullopt; +int main() { + std::optional o1 = 1; + std::optional o2 = std::nullopt; - NLOHMANN_JSON_NAMESPACE::json j; - j.push_back(o1); - j.push_back(o2); - std::cout << j << std::endl; + NLOHMANN_JSON_NAMESPACE::json j; + j.push_back(o1); + j.push_back(o2); + std::cout << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace_no_version.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace_no_version.cpp index 97948dd7..fdad0aac 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace_no_version.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_namespace_no_version.cpp @@ -7,7 +7,4 @@ #define Q(x) #x #define QUOTE(x) Q(x) -int main() -{ - std::cout << QUOTE(NLOHMANN_JSON_NAMESPACE) << std::endl; -} +int main() { std::cout << QUOTE(NLOHMANN_JSON_NAMESPACE) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_serialize_enum.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_serialize_enum.cpp index a40db49e..71aa3356 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_serialize_enum.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_serialize_enum.cpp @@ -3,57 +3,42 @@ using json = nlohmann::json; -namespace ns -{ -enum TaskState -{ - TS_STOPPED, - TS_RUNNING, - TS_COMPLETED, - TS_INVALID = -1 -}; - -NLOHMANN_JSON_SERIALIZE_ENUM(TaskState, -{ - { TS_INVALID, nullptr }, - { TS_STOPPED, "stopped" }, - { TS_RUNNING, "running" }, - { TS_COMPLETED, "completed" } -}) - -enum class Color -{ - red, green, blue, unknown -}; - -NLOHMANN_JSON_SERIALIZE_ENUM(Color, -{ - { Color::unknown, "unknown" }, { Color::red, "red" }, - { Color::green, "green" }, { Color::blue, "blue" } -}) +namespace ns { +enum TaskState { TS_STOPPED, TS_RUNNING, TS_COMPLETED, TS_INVALID = -1 }; + +NLOHMANN_JSON_SERIALIZE_ENUM(TaskState, {{TS_INVALID, nullptr}, + {TS_STOPPED, "stopped"}, + {TS_RUNNING, "running"}, + {TS_COMPLETED, "completed"}}) + +enum class Color { red, green, blue, unknown }; + +NLOHMANN_JSON_SERIALIZE_ENUM(Color, {{Color::unknown, "unknown"}, + {Color::red, "red"}, + {Color::green, "green"}, + {Color::blue, "blue"}}) } // namespace ns -int main() -{ - // serialization - json j_stopped = ns::TS_STOPPED; - json j_red = ns::Color::red; - std::cout << "ns::TS_STOPPED -> " << j_stopped - << ", ns::Color::red -> " << j_red << std::endl; - - // deserialization - json j_running = "running"; - json j_blue = "blue"; - auto running = j_running.template get(); - auto blue = j_blue.template get(); - std::cout << j_running << " -> " << running - << ", " << j_blue << " -> " << static_cast(blue) << std::endl; - - // deserializing undefined JSON value to enum - // (where the first map entry above is the default) - json j_pi = 3.14; - auto invalid = j_pi.template get(); - auto unknown = j_pi.template get(); - std::cout << j_pi << " -> " << invalid << ", " - << j_pi << " -> " << static_cast(unknown) << std::endl; +int main() { + // serialization + json j_stopped = ns::TS_STOPPED; + json j_red = ns::Color::red; + std::cout << "ns::TS_STOPPED -> " << j_stopped << ", ns::Color::red -> " + << j_red << std::endl; + + // deserialization + json j_running = "running"; + json j_blue = "blue"; + auto running = j_running.template get(); + auto blue = j_blue.template get(); + std::cout << j_running << " -> " << running << ", " << j_blue << " -> " + << static_cast(blue) << std::endl; + + // deserializing undefined JSON value to enum + // (where the first map entry above is the default) + json j_pi = 3.14; + auto invalid = j_pi.template get(); + auto unknown = j_pi.template get(); + std::cout << j_pi << " -> " << invalid << ", " << j_pi << " -> " + << static_cast(unknown) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_serialize_enum_2.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_serialize_enum_2.cpp index b35e94cc..027fd6cf 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_serialize_enum_2.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_serialize_enum_2.cpp @@ -3,31 +3,29 @@ using json = nlohmann::json; -namespace ns -{ -enum class Color -{ - red, green, blue, unknown -}; +namespace ns { +enum class Color { red, green, blue, unknown }; NLOHMANN_JSON_SERIALIZE_ENUM(Color, -{ - { Color::unknown, "unknown" }, { Color::red, "red" }, - { Color::green, "green" }, { Color::blue, "blue" }, - { Color::red, "rot" } // a second conversion for Color::red -}) -} + { + {Color::unknown, "unknown"}, + {Color::red, "red"}, + {Color::green, "green"}, + {Color::blue, "blue"}, + {Color::red, + "rot"} // a second conversion for Color::red + }) +} // namespace ns -int main() -{ - // serialization - json j_red = ns::Color::red; - std::cout << static_cast(ns::Color::red) << " -> " << j_red << std::endl; +int main() { + // serialization + json j_red = ns::Color::red; + std::cout << static_cast(ns::Color::red) << " -> " << j_red << std::endl; - // deserialization - json j_rot = "rot"; - auto rot = j_rot.template get(); - auto red = j_red.template get(); - std::cout << j_rot << " -> " << static_cast(rot) << std::endl; - std::cout << j_red << " -> " << static_cast(red) << std::endl; + // deserialization + json j_rot = "rot"; + auto rot = j_rot.template get(); + auto red = j_red.template get(); + std::cout << j_rot << " -> " << static_cast(rot) << std::endl; + std::cout << j_red << " -> " << static_cast(red) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_version.cpp b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_version.cpp index ca5f5372..625f898f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_version.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/nlohmann_json_version.cpp @@ -3,10 +3,8 @@ using json = nlohmann::json; -int main() -{ - std::cout << "JSON for Modern C++ version " - << NLOHMANN_JSON_VERSION_MAJOR << "." - << NLOHMANN_JSON_VERSION_MINOR << "." - << NLOHMANN_JSON_VERSION_PATCH << std::endl; +int main() { + std::cout << "JSON for Modern C++ version " << NLOHMANN_JSON_VERSION_MAJOR + << "." << NLOHMANN_JSON_VERSION_MINOR << "." + << NLOHMANN_JSON_VERSION_PATCH << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/number_float_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/number_float_t.cpp index 21211dc5..02b90685 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/number_float_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/number_float_t.cpp @@ -1,10 +1,10 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - std::cout << std::boolalpha << std::is_same::value << std::endl; +int main() { + std::cout << std::boolalpha + << std::is_same::value << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/number_integer_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/number_integer_t.cpp index 75ee57b6..f8720f8d 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/number_integer_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/number_integer_t.cpp @@ -1,10 +1,11 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - std::cout << std::boolalpha << std::is_same::value << std::endl; +int main() { + std::cout << std::boolalpha + << std::is_same::value + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/number_unsigned_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/number_unsigned_t.cpp index ff3b86df..106da52b 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/number_unsigned_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/number_unsigned_t.cpp @@ -1,10 +1,11 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - std::cout << std::boolalpha << std::is_same::value << std::endl; +int main() { + std::cout << std::boolalpha + << std::is_same::value + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/object.cpp b/nlohmann_json/docs/mkdocs/docs/examples/object.cpp index ad167d4a..871fa605 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/object.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/object.cpp @@ -3,26 +3,22 @@ using json = nlohmann::json; -int main() -{ - // create JSON objects - json j_no_init_list = json::object(); - json j_empty_init_list = json::object({}); - json j_list_of_pairs = json::object({ {"one", 1}, {"two", 2} }); +int main() { + // create JSON objects + json j_no_init_list = json::object(); + json j_empty_init_list = json::object({}); + json j_list_of_pairs = json::object({{"one", 1}, {"two", 2}}); - // serialize the JSON objects - std::cout << j_no_init_list << '\n'; - std::cout << j_empty_init_list << '\n'; - std::cout << j_list_of_pairs << '\n'; + // serialize the JSON objects + std::cout << j_no_init_list << '\n'; + std::cout << j_empty_init_list << '\n'; + std::cout << j_list_of_pairs << '\n'; - // example for an exception - try - { - // can only create an object from a list of pairs - json j_invalid_object = json::object({{ "one", 1, 2 }}); - } - catch (const json::type_error& e) - { - std::cout << e.what() << '\n'; - } + // example for an exception + try { + // can only create an object from a list of pairs + json j_invalid_object = json::object({{"one", 1, 2}}); + } catch (const json::type_error &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/object_comparator_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/object_comparator_t.cpp index 6b82c7ca..1af78365 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/object_comparator_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/object_comparator_t.cpp @@ -3,9 +3,10 @@ using json = nlohmann::json; -int main() -{ - std::cout << std::boolalpha - << "json::object_comparator_t(\"one\", \"two\") = " << json::object_comparator_t{}("one", "two") << "\n" - << "json::object_comparator_t(\"three\", \"four\") = " << json::object_comparator_t{}("three", "four") << std::endl; +int main() { + std::cout << std::boolalpha + << "json::object_comparator_t(\"one\", \"two\") = " + << json::object_comparator_t{}("one", "two") << "\n" + << "json::object_comparator_t(\"three\", \"four\") = " + << json::object_comparator_t{}("three", "four") << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/object_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/object_t.cpp index 85cfa3e3..b78aa189 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/object_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/object_t.cpp @@ -1,10 +1,12 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - std::cout << std::boolalpha << std::is_same, json::object_t>::value << std::endl; +int main() { + std::cout + << std::boolalpha + << std::is_same, json::object_t>::value + << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__ValueType.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__ValueType.cpp index e8a1d349..446bf768 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__ValueType.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__ValueType.cpp @@ -1,60 +1,46 @@ #include -#include #include +#include using json = nlohmann::json; -int main() -{ - // create a JSON value with different types - json json_types = - { - {"boolean", true}, - { - "number", { - {"integer", 42}, - {"floating-point", 17.23} - } - }, - {"string", "Hello, world!"}, - {"array", {1, 2, 3, 4, 5}}, - {"null", nullptr} - }; +int main() { + // create a JSON value with different types + json json_types = {{"boolean", true}, + {"number", {{"integer", 42}, {"floating-point", 17.23}}}, + {"string", "Hello, world!"}, + {"array", {1, 2, 3, 4, 5}}, + {"null", nullptr}}; - // use implicit conversions - bool v1 = json_types["boolean"]; - int v2 = json_types["number"]["integer"]; - short v3 = json_types["number"]["integer"]; - float v4 = json_types["number"]["floating-point"]; - int v5 = json_types["number"]["floating-point"]; - std::string v6 = json_types["string"]; - std::vector v7 = json_types["array"]; - std::unordered_map v8 = json_types; + // use implicit conversions + bool v1 = json_types["boolean"]; + int v2 = json_types["number"]["integer"]; + short v3 = json_types["number"]["integer"]; + float v4 = json_types["number"]["floating-point"]; + int v5 = json_types["number"]["floating-point"]; + std::string v6 = json_types["string"]; + std::vector v7 = json_types["array"]; + std::unordered_map v8 = json_types; - // print the conversion results - std::cout << v1 << '\n'; - std::cout << v2 << ' ' << v3 << '\n'; - std::cout << v4 << ' ' << v5 << '\n'; - std::cout << v6 << '\n'; + // print the conversion results + std::cout << v1 << '\n'; + std::cout << v2 << ' ' << v3 << '\n'; + std::cout << v4 << ' ' << v5 << '\n'; + std::cout << v6 << '\n'; - for (auto i : v7) - { - std::cout << i << ' '; - } - std::cout << "\n\n"; + for (auto i : v7) { + std::cout << i << ' '; + } + std::cout << "\n\n"; - for (auto i : v8) - { - std::cout << i.first << ": " << i.second << '\n'; - } + for (auto i : v8) { + std::cout << i.first << ": " << i.second << '\n'; + } - // example for an exception - try - { - bool v1 = json_types["string"]; - } - catch (const json::type_error& e) - { - std::cout << e.what() << '\n'; - } + // example for an exception + try { + bool v1 = json_types["string"]; + } catch (const json::type_error &e) { + std::cout << e.what() << '\n'; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__equal.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__equal.cpp index 1426f489..e43ee52c 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__equal.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__equal.cpp @@ -3,22 +3,25 @@ using json = nlohmann::json; -int main() -{ - // create several JSON values - json array_1 = {1, 2, 3}; - json array_2 = {1, 2, 4}; - json object_1 = {{"A", "a"}, {"B", "b"}}; - json object_2 = {{"B", "b"}, {"A", "a"}}; - json number_1 = 17; - json number_2 = 17.000000000000001L; - json string_1 = "foo"; - json string_2 = "bar"; +int main() { + // create several JSON values + json array_1 = {1, 2, 3}; + json array_2 = {1, 2, 4}; + json object_1 = {{"A", "a"}, {"B", "b"}}; + json object_2 = {{"B", "b"}, {"A", "a"}}; + json number_1 = 17; + json number_2 = 17.000000000000001L; + json string_1 = "foo"; + json string_2 = "bar"; - // output values and comparisons - std::cout << std::boolalpha; - std::cout << array_1 << " == " << array_2 << " " << (array_1 == array_2) << '\n'; - std::cout << object_1 << " == " << object_2 << " " << (object_1 == object_2) << '\n'; - std::cout << number_1 << " == " << number_2 << " " << (number_1 == number_2) << '\n'; - std::cout << string_1 << " == " << string_2 << " " << (string_1 == string_2) << '\n'; + // output values and comparisons + std::cout << std::boolalpha; + std::cout << array_1 << " == " << array_2 << " " << (array_1 == array_2) + << '\n'; + std::cout << object_1 << " == " << object_2 << " " << (object_1 == object_2) + << '\n'; + std::cout << number_1 << " == " << number_2 << " " << (number_1 == number_2) + << '\n'; + std::cout << string_1 << " == " << string_2 << " " << (string_1 == string_2) + << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__equal__nullptr_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__equal__nullptr_t.cpp index dbb21037..81d9876a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__equal__nullptr_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__equal__nullptr_t.cpp @@ -3,20 +3,19 @@ using json = nlohmann::json; -int main() -{ - // create several JSON values - json array = {1, 2, 3}; - json object = {{"A", "a"}, {"B", "b"}}; - json number = 17; - json string = "foo"; - json null; +int main() { + // create several JSON values + json array = {1, 2, 3}; + json object = {{"A", "a"}, {"B", "b"}}; + json number = 17; + json string = "foo"; + json null; - // output values and comparisons - std::cout << std::boolalpha; - std::cout << array << " == nullptr " << (array == nullptr) << '\n'; - std::cout << object << " == nullptr " << (object == nullptr) << '\n'; - std::cout << number << " == nullptr " << (number == nullptr) << '\n'; - std::cout << string << " == nullptr " << (string == nullptr) << '\n'; - std::cout << null << " == nullptr " << (null == nullptr) << '\n'; + // output values and comparisons + std::cout << std::boolalpha; + std::cout << array << " == nullptr " << (array == nullptr) << '\n'; + std::cout << object << " == nullptr " << (object == nullptr) << '\n'; + std::cout << number << " == nullptr " << (number == nullptr) << '\n'; + std::cout << string << " == nullptr " << (string == nullptr) << '\n'; + std::cout << null << " == nullptr " << (null == nullptr) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__equal__specializations.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__equal__specializations.cpp index 97d5ecea..0b2973a2 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__equal__specializations.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__equal__specializations.cpp @@ -1,16 +1,16 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - nlohmann::json uj1 = {{"version", 1}, {"type", "integer"}}; - nlohmann::json uj2 = {{"type", "integer"}, {"version", 1}}; +int main() { + nlohmann::json uj1 = {{"version", 1}, {"type", "integer"}}; + nlohmann::json uj2 = {{"type", "integer"}, {"version", 1}}; - nlohmann::ordered_json oj1 = {{"version", 1}, {"type", "integer"}}; - nlohmann::ordered_json oj2 = {{"type", "integer"}, {"version", 1}}; + nlohmann::ordered_json oj1 = {{"version", 1}, {"type", "integer"}}; + nlohmann::ordered_json oj2 = {{"type", "integer"}, {"version", 1}}; - std::cout << std::boolalpha << (uj1 == uj2) << '\n' << (oj1 == oj2) << std::endl; + std::cout << std::boolalpha << (uj1 == uj2) << '\n' + << (oj1 == oj2) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__greater.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__greater.cpp index 65bb9c04..04e3180c 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__greater.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__greater.cpp @@ -3,22 +3,25 @@ using json = nlohmann::json; -int main() -{ - // create several JSON values - json array_1 = {1, 2, 3}; - json array_2 = {1, 2, 4}; - json object_1 = {{"A", "a"}, {"B", "b"}}; - json object_2 = {{"B", "b"}, {"A", "a"}}; - json number_1 = 17; - json number_2 = 17.0000000000001L; - json string_1 = "foo"; - json string_2 = "bar"; +int main() { + // create several JSON values + json array_1 = {1, 2, 3}; + json array_2 = {1, 2, 4}; + json object_1 = {{"A", "a"}, {"B", "b"}}; + json object_2 = {{"B", "b"}, {"A", "a"}}; + json number_1 = 17; + json number_2 = 17.0000000000001L; + json string_1 = "foo"; + json string_2 = "bar"; - // output values and comparisons - std::cout << std::boolalpha; - std::cout << array_1 << " > " << array_2 << " " << (array_1 > array_2) << '\n'; - std::cout << object_1 << " > " << object_2 << " " << (object_1 > object_2) << '\n'; - std::cout << number_1 << " > " << number_2 << " " << (number_1 > number_2) << '\n'; - std::cout << string_1 << " > " << string_2 << " " << (string_1 > string_2) << '\n'; + // output values and comparisons + std::cout << std::boolalpha; + std::cout << array_1 << " > " << array_2 << " " << (array_1 > array_2) + << '\n'; + std::cout << object_1 << " > " << object_2 << " " << (object_1 > object_2) + << '\n'; + std::cout << number_1 << " > " << number_2 << " " << (number_1 > number_2) + << '\n'; + std::cout << string_1 << " > " << string_2 << " " << (string_1 > string_2) + << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__greaterequal.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__greaterequal.cpp index f8659ee0..7386c493 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__greaterequal.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__greaterequal.cpp @@ -3,22 +3,25 @@ using json = nlohmann::json; -int main() -{ - // create several JSON values - json array_1 = {1, 2, 3}; - json array_2 = {1, 2, 4}; - json object_1 = {{"A", "a"}, {"B", "b"}}; - json object_2 = {{"B", "b"}, {"A", "a"}}; - json number_1 = 17; - json number_2 = 17.0000000000001L; - json string_1 = "foo"; - json string_2 = "bar"; +int main() { + // create several JSON values + json array_1 = {1, 2, 3}; + json array_2 = {1, 2, 4}; + json object_1 = {{"A", "a"}, {"B", "b"}}; + json object_2 = {{"B", "b"}, {"A", "a"}}; + json number_1 = 17; + json number_2 = 17.0000000000001L; + json string_1 = "foo"; + json string_2 = "bar"; - // output values and comparisons - std::cout << std::boolalpha; - std::cout << array_1 << " >= " << array_2 << " " << (array_1 >= array_2) << '\n'; - std::cout << object_1 << " >= " << object_2 << " " << (object_1 >= object_2) << '\n'; - std::cout << number_1 << " >= " << number_2 << " " << (number_1 >= number_2) << '\n'; - std::cout << string_1 << " >= " << string_2 << " " << (string_1 >= string_2) << '\n'; + // output values and comparisons + std::cout << std::boolalpha; + std::cout << array_1 << " >= " << array_2 << " " << (array_1 >= array_2) + << '\n'; + std::cout << object_1 << " >= " << object_2 << " " << (object_1 >= object_2) + << '\n'; + std::cout << number_1 << " >= " << number_2 << " " << (number_1 >= number_2) + << '\n'; + std::cout << string_1 << " >= " << string_2 << " " << (string_1 >= string_2) + << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__less.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__less.cpp index 64209a22..8a08b503 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__less.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__less.cpp @@ -3,22 +3,25 @@ using json = nlohmann::json; -int main() -{ - // create several JSON values - json array_1 = {1, 2, 3}; - json array_2 = {1, 2, 4}; - json object_1 = {{"A", "a"}, {"B", "b"}}; - json object_2 = {{"B", "b"}, {"A", "a"}}; - json number_1 = 17; - json number_2 = 17.0000000000001L; - json string_1 = "foo"; - json string_2 = "bar"; +int main() { + // create several JSON values + json array_1 = {1, 2, 3}; + json array_2 = {1, 2, 4}; + json object_1 = {{"A", "a"}, {"B", "b"}}; + json object_2 = {{"B", "b"}, {"A", "a"}}; + json number_1 = 17; + json number_2 = 17.0000000000001L; + json string_1 = "foo"; + json string_2 = "bar"; - // output values and comparisons - std::cout << std::boolalpha; - std::cout << array_1 << " == " << array_2 << " " << (array_1 < array_2) << '\n'; - std::cout << object_1 << " == " << object_2 << " " << (object_1 < object_2) << '\n'; - std::cout << number_1 << " == " << number_2 << " " << (number_1 < number_2) << '\n'; - std::cout << string_1 << " == " << string_2 << " " << (string_1 < string_2) << '\n'; + // output values and comparisons + std::cout << std::boolalpha; + std::cout << array_1 << " == " << array_2 << " " << (array_1 < array_2) + << '\n'; + std::cout << object_1 << " == " << object_2 << " " << (object_1 < object_2) + << '\n'; + std::cout << number_1 << " == " << number_2 << " " << (number_1 < number_2) + << '\n'; + std::cout << string_1 << " == " << string_2 << " " << (string_1 < string_2) + << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__lessequal.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__lessequal.cpp index 543b9543..d17450b3 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__lessequal.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__lessequal.cpp @@ -3,22 +3,25 @@ using json = nlohmann::json; -int main() -{ - // create several JSON values - json array_1 = {1, 2, 3}; - json array_2 = {1, 2, 4}; - json object_1 = {{"A", "a"}, {"B", "b"}}; - json object_2 = {{"B", "b"}, {"A", "a"}}; - json number_1 = 17; - json number_2 = 17.0000000000001L; - json string_1 = "foo"; - json string_2 = "bar"; +int main() { + // create several JSON values + json array_1 = {1, 2, 3}; + json array_2 = {1, 2, 4}; + json object_1 = {{"A", "a"}, {"B", "b"}}; + json object_2 = {{"B", "b"}, {"A", "a"}}; + json number_1 = 17; + json number_2 = 17.0000000000001L; + json string_1 = "foo"; + json string_2 = "bar"; - // output values and comparisons - std::cout << std::boolalpha; - std::cout << array_1 << " <= " << array_2 << " " << (array_1 <= array_2) << '\n'; - std::cout << object_1 << " <= " << object_2 << " " << (object_1 <= object_2) << '\n'; - std::cout << number_1 << " <= " << number_2 << " " << (number_1 <= number_2) << '\n'; - std::cout << string_1 << " <= " << string_2 << " " << (string_1 <= string_2) << '\n'; + // output values and comparisons + std::cout << std::boolalpha; + std::cout << array_1 << " <= " << array_2 << " " << (array_1 <= array_2) + << '\n'; + std::cout << object_1 << " <= " << object_2 << " " << (object_1 <= object_2) + << '\n'; + std::cout << number_1 << " <= " << number_2 << " " << (number_1 <= number_2) + << '\n'; + std::cout << string_1 << " <= " << string_2 << " " << (string_1 <= string_2) + << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__notequal.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__notequal.cpp index 43e89509..c928194d 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__notequal.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__notequal.cpp @@ -3,22 +3,25 @@ using json = nlohmann::json; -int main() -{ - // create several JSON values - json array_1 = {1, 2, 3}; - json array_2 = {1, 2, 4}; - json object_1 = {{"A", "a"}, {"B", "b"}}; - json object_2 = {{"B", "b"}, {"A", "a"}}; - json number_1 = 17; - json number_2 = 17.000000000000001L; - json string_1 = "foo"; - json string_2 = "bar"; +int main() { + // create several JSON values + json array_1 = {1, 2, 3}; + json array_2 = {1, 2, 4}; + json object_1 = {{"A", "a"}, {"B", "b"}}; + json object_2 = {{"B", "b"}, {"A", "a"}}; + json number_1 = 17; + json number_2 = 17.000000000000001L; + json string_1 = "foo"; + json string_2 = "bar"; - // output values and comparisons - std::cout << std::boolalpha; - std::cout << array_1 << " != " << array_2 << " " << (array_1 != array_2) << '\n'; - std::cout << object_1 << " != " << object_2 << " " << (object_1 != object_2) << '\n'; - std::cout << number_1 << " != " << number_2 << " " << (number_1 != number_2) << '\n'; - std::cout << string_1 << " != " << string_2 << " " << (string_1 != string_2) << '\n'; + // output values and comparisons + std::cout << std::boolalpha; + std::cout << array_1 << " != " << array_2 << " " << (array_1 != array_2) + << '\n'; + std::cout << object_1 << " != " << object_2 << " " << (object_1 != object_2) + << '\n'; + std::cout << number_1 << " != " << number_2 << " " << (number_1 != number_2) + << '\n'; + std::cout << string_1 << " != " << string_2 << " " << (string_1 != string_2) + << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__notequal__nullptr_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__notequal__nullptr_t.cpp index dc7e6ac4..12ae1ce0 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__notequal__nullptr_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__notequal__nullptr_t.cpp @@ -3,20 +3,19 @@ using json = nlohmann::json; -int main() -{ - // create several JSON values - json array = {1, 2, 3}; - json object = {{"A", "a"}, {"B", "b"}}; - json number = 17; - json string = "foo"; - json null; +int main() { + // create several JSON values + json array = {1, 2, 3}; + json object = {{"A", "a"}, {"B", "b"}}; + json number = 17; + json string = "foo"; + json null; - // output values and comparisons - std::cout << std::boolalpha; - std::cout << array << " != nullptr " << (array != nullptr) << '\n'; - std::cout << object << " != nullptr " << (object != nullptr) << '\n'; - std::cout << number << " != nullptr " << (number != nullptr) << '\n'; - std::cout << string << " != nullptr " << (string != nullptr) << '\n'; - std::cout << null << " != nullptr " << (null != nullptr) << '\n'; + // output values and comparisons + std::cout << std::boolalpha; + std::cout << array << " != nullptr " << (array != nullptr) << '\n'; + std::cout << object << " != nullptr " << (object != nullptr) << '\n'; + std::cout << number << " != nullptr " << (number != nullptr) << '\n'; + std::cout << string << " != nullptr " << (string != nullptr) << '\n'; + std::cout << null << " != nullptr " << (null != nullptr) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator__value_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator__value_t.cpp index d9aac797..4cfa6001 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator__value_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator__value_t.cpp @@ -3,36 +3,35 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = -17; - json j_number_unsigned = 42u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = -17; + json j_number_unsigned = 42u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; - // call operator value_t() - json::value_t t_null = j_null; - json::value_t t_boolean = j_boolean; - json::value_t t_number_integer = j_number_integer; - json::value_t t_number_unsigned = j_number_unsigned; - json::value_t t_number_float = j_number_float; - json::value_t t_object = j_object; - json::value_t t_array = j_array; - json::value_t t_string = j_string; + // call operator value_t() + json::value_t t_null = j_null; + json::value_t t_boolean = j_boolean; + json::value_t t_number_integer = j_number_integer; + json::value_t t_number_unsigned = j_number_unsigned; + json::value_t t_number_float = j_number_float; + json::value_t t_object = j_object; + json::value_t t_array = j_array; + json::value_t t_string = j_string; - // print types - std::cout << std::boolalpha; - std::cout << (t_null == json::value_t::null) << '\n'; - std::cout << (t_boolean == json::value_t::boolean) << '\n'; - std::cout << (t_number_integer == json::value_t::number_integer) << '\n'; - std::cout << (t_number_unsigned == json::value_t::number_unsigned) << '\n'; - std::cout << (t_number_float == json::value_t::number_float) << '\n'; - std::cout << (t_object == json::value_t::object) << '\n'; - std::cout << (t_array == json::value_t::array) << '\n'; - std::cout << (t_string == json::value_t::string) << '\n'; + // print types + std::cout << std::boolalpha; + std::cout << (t_null == json::value_t::null) << '\n'; + std::cout << (t_boolean == json::value_t::boolean) << '\n'; + std::cout << (t_number_integer == json::value_t::number_integer) << '\n'; + std::cout << (t_number_unsigned == json::value_t::number_unsigned) << '\n'; + std::cout << (t_number_float == json::value_t::number_float) << '\n'; + std::cout << (t_object == json::value_t::object) << '\n'; + std::cout << (t_array == json::value_t::array) << '\n'; + std::cout << (t_string == json::value_t::string) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__json_pointer.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__json_pointer.cpp index 0fa207f0..d05b7a43 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__json_pointer.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__json_pointer.cpp @@ -4,46 +4,42 @@ using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create a JSON value - json j = - { - {"number", 1}, {"string", "foo"}, {"array", {1, 2}} - }; - - // read-only access - - // output element with JSON pointer "/number" - std::cout << j["/number"_json_pointer] << '\n'; - // output element with JSON pointer "/string" - std::cout << j["/string"_json_pointer] << '\n'; - // output element with JSON pointer "/array" - std::cout << j["/array"_json_pointer] << '\n'; - // output element with JSON pointer "/array/1" - std::cout << j["/array/1"_json_pointer] << '\n'; - - // writing access - - // change the string - j["/string"_json_pointer] = "bar"; - // output the changed string - std::cout << j["string"] << '\n'; - - // "change" a nonexisting object entry - j["/boolean"_json_pointer] = true; - // output the changed object - std::cout << j << '\n'; - - // change an array element - j["/array/1"_json_pointer] = 21; - // "change" an array element with nonexisting index - j["/array/4"_json_pointer] = 44; - // output the changed array - std::cout << j["array"] << '\n'; - - // "change" the array element past the end - j["/array/-"_json_pointer] = 55; - // output the changed array - std::cout << j["array"] << '\n'; +int main() { + // create a JSON value + json j = {{"number", 1}, {"string", "foo"}, {"array", {1, 2}}}; + + // read-only access + + // output element with JSON pointer "/number" + std::cout << j["/number"_json_pointer] << '\n'; + // output element with JSON pointer "/string" + std::cout << j["/string"_json_pointer] << '\n'; + // output element with JSON pointer "/array" + std::cout << j["/array"_json_pointer] << '\n'; + // output element with JSON pointer "/array/1" + std::cout << j["/array/1"_json_pointer] << '\n'; + + // writing access + + // change the string + j["/string"_json_pointer] = "bar"; + // output the changed string + std::cout << j["string"] << '\n'; + + // "change" a nonexisting object entry + j["/boolean"_json_pointer] = true; + // output the changed object + std::cout << j << '\n'; + + // change an array element + j["/array/1"_json_pointer] = 21; + // "change" an array element with nonexisting index + j["/array/4"_json_pointer] = 44; + // output the changed array + std::cout << j["array"] << '\n'; + + // "change" the array element past the end + j["/array/-"_json_pointer] = 55; + // output the changed array + std::cout << j["array"] << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__json_pointer_const.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__json_pointer_const.cpp index f40e2494..8a5d4e3a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__json_pointer_const.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__json_pointer_const.cpp @@ -4,22 +4,18 @@ using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create a JSON value - const json j = - { - {"number", 1}, {"string", "foo"}, {"array", {1, 2}} - }; +int main() { + // create a JSON value + const json j = {{"number", 1}, {"string", "foo"}, {"array", {1, 2}}}; - // read-only access + // read-only access - // output element with JSON pointer "/number" - std::cout << j["/number"_json_pointer] << '\n'; - // output element with JSON pointer "/string" - std::cout << j["/string"_json_pointer] << '\n'; - // output element with JSON pointer "/array" - std::cout << j["/array"_json_pointer] << '\n'; - // output element with JSON pointer "/array/1" - std::cout << j["/array/1"_json_pointer] << '\n'; + // output element with JSON pointer "/number" + std::cout << j["/number"_json_pointer] << '\n'; + // output element with JSON pointer "/string" + std::cout << j["/string"_json_pointer] << '\n'; + // output element with JSON pointer "/array" + std::cout << j["/array"_json_pointer] << '\n'; + // output element with JSON pointer "/array/1" + std::cout << j["/array/1"_json_pointer] << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__keytype.c++17.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__keytype.c++17.cpp index 7f2b41dd..5cadb467 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__keytype.c++17.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__keytype.c++17.cpp @@ -1,34 +1,30 @@ -#include #include -#include +#include #include +#include using namespace std::string_view_literals; using json = nlohmann::json; -int main() -{ - // create a JSON object - json object = - { - {"one", 1}, {"two", 2}, {"three", 2.9} - }; +int main() { + // create a JSON object + json object = {{"one", 1}, {"two", 2}, {"three", 2.9}}; - // output element with key "two" - std::cout << object["two"sv] << "\n\n"; + // output element with key "two" + std::cout << object["two"sv] << "\n\n"; - // change element with key "three" - object["three"sv] = 3; + // change element with key "three" + object["three"sv] = 3; - // output changed array - std::cout << std::setw(4) << object << "\n\n"; + // output changed array + std::cout << std::setw(4) << object << "\n\n"; - // mention nonexisting key - object["four"sv]; + // mention nonexisting key + object["four"sv]; - // write to nonexisting key - object["five"sv]["really"sv]["nested"sv] = true; + // write to nonexisting key + object["five"sv]["really"sv]["nested"sv] = true; - // output changed object - std::cout << std::setw(4) << object << '\n'; + // output changed object + std::cout << std::setw(4) << object << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__keytype_const.c++17.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__keytype_const.c++17.cpp index 2cf94f40..d067dad8 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__keytype_const.c++17.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__keytype_const.c++17.cpp @@ -1,18 +1,14 @@ #include -#include #include +#include using namespace std::string_view_literals; using json = nlohmann::json; -int main() -{ - // create a JSON object - const json object = - { - {"one", 1}, {"two", 2}, {"three", 2.9} - }; +int main() { + // create a JSON object + const json object = {{"one", 1}, {"two", 2}, {"three", 2.9}}; - // output element with key "two" - std::cout << object["two"sv] << '\n'; + // output element with key "two" + std::cout << object["two"sv] << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__object_t_key_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__object_t_key_type.cpp index f9b7f731..4ef8dd62 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__object_t_key_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__object_t_key_type.cpp @@ -1,32 +1,28 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create a JSON object - json object = - { - {"one", 1}, {"two", 2}, {"three", 2.9} - }; +int main() { + // create a JSON object + json object = {{"one", 1}, {"two", 2}, {"three", 2.9}}; - // output element with key "two" - std::cout << object["two"] << "\n\n"; + // output element with key "two" + std::cout << object["two"] << "\n\n"; - // change element with key "three" - object["three"] = 3; + // change element with key "three" + object["three"] = 3; - // output changed array - std::cout << std::setw(4) << object << "\n\n"; + // output changed array + std::cout << std::setw(4) << object << "\n\n"; - // mention nonexisting key - object["four"]; + // mention nonexisting key + object["four"]; - // write to nonexisting key - object["five"]["really"]["nested"] = true; + // write to nonexisting key + object["five"]["really"]["nested"] = true; - // output changed object - std::cout << std::setw(4) << object << '\n'; + // output changed object + std::cout << std::setw(4) << object << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__object_t_key_type_const.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__object_t_key_type_const.cpp index 1bdb3402..5e9d7d1a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__object_t_key_type_const.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__object_t_key_type_const.cpp @@ -3,14 +3,10 @@ using json = nlohmann::json; -int main() -{ - // create a JSON object - const json object = - { - {"one", 1}, {"two", 2}, {"three", 2.9} - }; +int main() { + // create a JSON object + const json object = {{"one", 1}, {"two", 2}, {"three", 2.9}}; - // output element with key "two" - std::cout << object["two"] << '\n'; + // output element with key "two" + std::cout << object["two"] << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__size_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__size_type.cpp index d6f3e153..ef4b36b1 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__size_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__size_type.cpp @@ -3,23 +3,22 @@ using json = nlohmann::json; -int main() -{ - // create a JSON array - json array = {1, 2, 3, 4, 5}; +int main() { + // create a JSON array + json array = {1, 2, 3, 4, 5}; - // output element at index 3 (fourth element) - std::cout << array[3] << '\n'; + // output element at index 3 (fourth element) + std::cout << array[3] << '\n'; - // change last element to 6 - array[array.size() - 1] = 6; + // change last element to 6 + array[array.size() - 1] = 6; - // output changed array - std::cout << array << '\n'; + // output changed array + std::cout << array << '\n'; - // write beyond array limit - array[10] = 11; + // write beyond array limit + array[10] = 11; - // output changed array - std::cout << array << '\n'; + // output changed array + std::cout << array << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__size_type_const.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__size_type_const.cpp index d56fa0a4..93fddd3e 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_array__size_type_const.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_array__size_type_const.cpp @@ -3,11 +3,10 @@ using json = nlohmann::json; -int main() -{ - // create JSON array - const json array = {"first", "2nd", "third", "fourth"}; +int main() { + // create JSON array + const json array = {"first", "2nd", "third", "fourth"}; - // output element at index 2 (third element) - std::cout << array.at(2) << '\n'; + // output element at index 2 (third element) + std::cout << array.at(2) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_deserialize.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_deserialize.cpp index 8e3d8bd8..58de2560 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_deserialize.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_deserialize.cpp @@ -1,15 +1,14 @@ -#include #include -#include +#include #include +#include using json = nlohmann::json; -int main() -{ - // create stream with serialized JSON - std::stringstream ss; - ss << R"({ +int main() { + // create stream with serialized JSON + std::stringstream ss; + ss << R"({ "number": 23, "string": "Hello, world!", "array": [1, 2, 3, 4, 5], @@ -17,10 +16,10 @@ int main() "null": null })"; - // create JSON value and read the serialization from the stream - json j; - ss >> j; + // create JSON value and read the serialization from the stream + json j; + ss >> j; - // serialize JSON - std::cout << std::setw(2) << j << '\n'; + // serialize JSON + std::cout << std::setw(2) << j << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_literal_json.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_literal_json.cpp index 84ca6297..114e10d0 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_literal_json.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_literal_json.cpp @@ -1,13 +1,12 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - json j = R"( {"hello": "world", "answer": 42} )"_json; +int main() { + json j = R"( {"hello": "world", "answer": 42} )"_json; - std::cout << std::setw(2) << j << '\n'; + std::cout << std::setw(2) << j << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_literal_json_pointer.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_literal_json_pointer.cpp index aba93e88..89ba39fa 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_literal_json_pointer.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_literal_json_pointer.cpp @@ -1,14 +1,13 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - json j = R"( {"hello": "world", "answer": 42} )"_json; - auto val = j["/hello"_json_pointer]; +int main() { + json j = R"( {"hello": "world", "answer": 42} )"_json; + auto val = j["/hello"_json_pointer]; - std::cout << std::setw(2) << val << '\n'; + std::cout << std::setw(2) << val << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_ltlt__basic_json.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_ltlt__basic_json.cpp index 3bd4ad57..4f4adefb 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_ltlt__basic_json.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_ltlt__basic_json.cpp @@ -1,21 +1,20 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create JSON values - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; +int main() { + // create JSON values + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; - // serialize without indentation - std::cout << j_object << "\n\n"; - std::cout << j_array << "\n\n"; + // serialize without indentation + std::cout << j_object << "\n\n"; + std::cout << j_array << "\n\n"; - // serialize with indentation - std::cout << std::setw(4) << j_object << "\n\n"; - std::cout << std::setw(2) << j_array << "\n\n"; - std::cout << std::setw(1) << std::setfill('\t') << j_object << "\n\n"; + // serialize with indentation + std::cout << std::setw(4) << j_object << "\n\n"; + std::cout << std::setw(2) << j_array << "\n\n"; + std::cout << std::setw(1) << std::setfill('\t') << j_object << "\n\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_ltlt__json_pointer.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_ltlt__json_pointer.cpp index f4fac886..b8914108 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_ltlt__json_pointer.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_ltlt__json_pointer.cpp @@ -3,11 +3,10 @@ using json = nlohmann::json; -int main() -{ - // create JSON poiner - json::json_pointer ptr("/foo/bar/baz"); +int main() { + // create JSON poiner + json::json_pointer ptr("/foo/bar/baz"); - // write string representation to stream - std::cout << ptr << std::endl; + // write string representation to stream + std::cout << ptr << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_spaceship__const_reference.c++20.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_spaceship__const_reference.c++20.cpp index 9e7c9e9b..c7852f4f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_spaceship__const_reference.c++20.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_spaceship__const_reference.c++20.cpp @@ -4,37 +4,34 @@ using json = nlohmann::json; -const char* to_string(const std::partial_ordering& po) -{ - if (std::is_lt(po)) - { - return "less"; - } - else if (std::is_gt(po)) - { - return "greater"; - } - else if (std::is_eq(po)) - { - return "equivalent"; - } - return "unordered"; +const char *to_string(const std::partial_ordering &po) { + if (std::is_lt(po)) { + return "less"; + } else if (std::is_gt(po)) { + return "greater"; + } else if (std::is_eq(po)) { + return "equivalent"; + } + return "unordered"; } -int main() -{ - // create several JSON values - json array_1 = {1, 2, 3}; - json array_2 = {1, 2, 4}; - json object_1 = {{"A", "a"}, {"B", "b"}}; - json object_2 = {{"B", "b"}, {"A", "a"}}; - json number = 17; - json string = "foo"; - json discarded = json(json::value_t::discarded); +int main() { + // create several JSON values + json array_1 = {1, 2, 3}; + json array_2 = {1, 2, 4}; + json object_1 = {{"A", "a"}, {"B", "b"}}; + json object_2 = {{"B", "b"}, {"A", "a"}}; + json number = 17; + json string = "foo"; + json discarded = json(json::value_t::discarded); - // output values and comparisons - std::cout << array_1 << " <=> " << array_2 << " := " << to_string(array_1 <=> array_2) << '\n'; // *NOPAD* - std::cout << object_1 << " <=> " << object_2 << " := " << to_string(object_1 <=> object_2) << '\n'; // *NOPAD* - std::cout << string << " <=> " << number << " := " << to_string(string <=> number) << '\n'; // *NOPAD* - std::cout << string << " <=> " << discarded << " := " << to_string(string <=> discarded) << '\n'; // *NOPAD* + // output values and comparisons + std::cout << array_1 << " <=> " << array_2 + << " := " << to_string(array_1 <=> array_2) << '\n'; // *NOPAD* + std::cout << object_1 << " <=> " << object_2 + << " := " << to_string(object_1 <=> object_2) << '\n'; // *NOPAD* + std::cout << string << " <=> " << number + << " := " << to_string(string <=> number) << '\n'; // *NOPAD* + std::cout << string << " <=> " << discarded + << " := " << to_string(string <=> discarded) << '\n'; // *NOPAD* } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/operator_spaceship__scalartype.c++20.cpp b/nlohmann_json/docs/mkdocs/docs/examples/operator_spaceship__scalartype.c++20.cpp index ebb5b434..4c5541b9 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/operator_spaceship__scalartype.c++20.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/operator_spaceship__scalartype.c++20.cpp @@ -4,37 +4,34 @@ using json = nlohmann::json; -const char* to_string(const std::partial_ordering& po) -{ - if (std::is_lt(po)) - { - return "less"; - } - else if (std::is_gt(po)) - { - return "greater"; - } - else if (std::is_eq(po)) - { - return "equivalent"; - } - return "unordered"; +const char *to_string(const std::partial_ordering &po) { + if (std::is_lt(po)) { + return "less"; + } else if (std::is_gt(po)) { + return "greater"; + } else if (std::is_eq(po)) { + return "equivalent"; + } + return "unordered"; } -int main() -{ - using float_limits = std::numeric_limits; - constexpr auto nan = float_limits::quiet_NaN(); +int main() { + using float_limits = std::numeric_limits; + constexpr auto nan = float_limits::quiet_NaN(); - // create several JSON values - json boolean = false; - json number = 17; - json string = "17"; + // create several JSON values + json boolean = false; + json number = 17; + json string = "17"; - // output values and comparisons - std::cout << std::boolalpha << std::fixed; - std::cout << boolean << " <=> " << true << " := " << to_string(boolean <=> true) << '\n'; // *NOPAD* - std::cout << number << " <=> " << 17.0 << " := " << to_string(number <=> 17.0) << '\n'; // *NOPAD* - std::cout << number << " <=> " << nan << " := " << to_string(number <=> nan) << '\n'; // *NOPAD* - std::cout << string << " <=> " << 17 << " := " << to_string(string <=> 17) << '\n'; // *NOPAD* + // output values and comparisons + std::cout << std::boolalpha << std::fixed; + std::cout << boolean << " <=> " << true + << " := " << to_string(boolean <=> true) << '\n'; // *NOPAD* + std::cout << number << " <=> " << 17.0 << " := " << to_string(number <=> 17.0) + << '\n'; // *NOPAD* + std::cout << number << " <=> " << nan << " := " << to_string(number <=> nan) + << '\n'; // *NOPAD* + std::cout << string << " <=> " << 17 << " := " << to_string(string <=> 17) + << '\n'; // *NOPAD* } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/ordered_json.cpp b/nlohmann_json/docs/mkdocs/docs/examples/ordered_json.cpp index effad530..f50f5795 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/ordered_json.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/ordered_json.cpp @@ -3,12 +3,11 @@ using ordered_json = nlohmann::ordered_json; -int main() -{ - ordered_json j; - j["one"] = 1; - j["two"] = 2; - j["three"] = 3; +int main() { + ordered_json j; + j["one"] = 1; + j["two"] = 2; + j["three"] = 3; - std::cout << j.dump(2) << '\n'; + std::cout << j.dump(2) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/ordered_map.cpp b/nlohmann_json/docs/mkdocs/docs/examples/ordered_map.cpp index dcc60cb5..ff6e74a9 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/ordered_map.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/ordered_map.cpp @@ -2,42 +2,39 @@ #include // simple output function -template -void output(const char* prefix, const Map& m) -{ - std::cout << prefix << " = { "; - for (auto& element : m) - { - std::cout << element.first << ":" << element.second << ' '; - } - std::cout << "}" << std::endl; +template void output(const char *prefix, const Map &m) { + std::cout << prefix << " = { "; + for (auto &element : m) { + std::cout << element.first << ":" << element.second << ' '; + } + std::cout << "}" << std::endl; } -int main() -{ - // create and fill two maps - nlohmann::ordered_map m_ordered; - m_ordered["one"] = "eins"; - m_ordered["two"] = "zwei"; - m_ordered["three"] = "drei"; +int main() { + // create and fill two maps + nlohmann::ordered_map m_ordered; + m_ordered["one"] = "eins"; + m_ordered["two"] = "zwei"; + m_ordered["three"] = "drei"; - std::map m_std; - m_std["one"] = "eins"; - m_std["two"] = "zwei"; - m_std["three"] = "drei"; + std::map m_std; + m_std["one"] = "eins"; + m_std["two"] = "zwei"; + m_std["three"] = "drei"; - // output: m_ordered is ordered by insertion order, m_std is ordered by key - output("m_ordered", m_ordered); - output("m_std", m_std); + // output: m_ordered is ordered by insertion order, m_std is ordered by key + output("m_ordered", m_ordered); + output("m_std", m_std); - // erase and re-add "one" key - m_ordered.erase("one"); - m_ordered["one"] = "eins"; + // erase and re-add "one" key + m_ordered.erase("one"); + m_ordered["one"] = "eins"; - m_std.erase("one"); - m_std["one"] = "eins"; + m_std.erase("one"); + m_std["one"] = "eins"; - // output: m_ordered shows newly added key at the end; m_std is again ordered by key - output("m_ordered", m_ordered); - output("m_std", m_std); + // output: m_ordered shows newly added key at the end; m_std is again ordered + // by key + output("m_ordered", m_ordered); + output("m_std", m_std); } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/other_error.cpp b/nlohmann_json/docs/mkdocs/docs/examples/other_error.cpp index 56aa8ae6..3849d10f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/other_error.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/other_error.cpp @@ -4,27 +4,23 @@ using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - try - { - // executing a failing JSON Patch operation - json value = R"({ +int main() { + try { + // executing a failing JSON Patch operation + json value = R"({ "best_biscuit": { "name": "Oreo" } })"_json; - json patch = R"([{ + json patch = R"([{ "op": "test", "path": "/best_biscuit/name", "value": "Choco Leibniz" }])"_json; - value.patch(patch); - } - catch (const json::other_error& e) - { - // output exception information - std::cout << "message: " << e.what() << '\n' - << "exception id: " << e.id << std::endl; - } + value.patch(patch); + } catch (const json::other_error &e) { + // output exception information + std::cout << "message: " << e.what() << '\n' + << "exception id: " << e.id << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/out_of_range.cpp b/nlohmann_json/docs/mkdocs/docs/examples/out_of_range.cpp index 03282082..11b8c1d5 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/out_of_range.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/out_of_range.cpp @@ -3,18 +3,14 @@ using json = nlohmann::json; -int main() -{ - try - { - // calling at() for an invalid index - json j = {1, 2, 3, 4}; - j.at(4) = 10; - } - catch (const json::out_of_range& e) - { - // output exception information - std::cout << "message: " << e.what() << '\n' - << "exception id: " << e.id << std::endl; - } +int main() { + try { + // calling at() for an invalid index + json j = {1, 2, 3, 4}; + j.at(4) = 10; + } catch (const json::out_of_range &e) { + // output exception information + std::cout << "message: " << e.what() << '\n' + << "exception id: " << e.id << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/parse__allow_exceptions.cpp b/nlohmann_json/docs/mkdocs/docs/examples/parse__allow_exceptions.cpp index f396c347..baf3078c 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/parse__allow_exceptions.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/parse__allow_exceptions.cpp @@ -3,34 +3,27 @@ using json = nlohmann::json; -int main() -{ - // an invalid JSON text - std::string text = R"( +int main() { + // an invalid JSON text + std::string text = R"( { "key": "value without closing quotes } )"; - // parse with exceptions - try - { - json j = json::parse(text); - } - catch (const json::parse_error& e) - { - std::cout << e.what() << std::endl; - } + // parse with exceptions + try { + json j = json::parse(text); + } catch (const json::parse_error &e) { + std::cout << e.what() << std::endl; + } - // parse without exceptions - json j = json::parse(text, nullptr, false); + // parse without exceptions + json j = json::parse(text, nullptr, false); - if (j.is_discarded()) - { - std::cout << "the input is invalid JSON" << std::endl; - } - else - { - std::cout << "the input is valid JSON: " << j << std::endl; - } + if (j.is_discarded()) { + std::cout << "the input is invalid JSON" << std::endl; + } else { + std::cout << "the input is valid JSON: " << j << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/parse__array__parser_callback_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/parse__array__parser_callback_t.cpp index 63f0a0e4..45a23890 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/parse__array__parser_callback_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/parse__array__parser_callback_t.cpp @@ -1,13 +1,12 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // a JSON text - char text[] = R"( +int main() { + // a JSON text + char text[] = R"( { "Image": { "Width": 800, @@ -24,7 +23,7 @@ int main() } )"; - // parse and serialize JSON - json j_complete = json::parse(text); - std::cout << std::setw(4) << j_complete << "\n\n"; + // parse and serialize JSON + json j_complete = json::parse(text); + std::cout << std::setw(4) << j_complete << "\n\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/parse__contiguouscontainer__parser_callback_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/parse__contiguouscontainer__parser_callback_t.cpp index 6eb409bb..703027a8 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/parse__contiguouscontainer__parser_callback_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/parse__contiguouscontainer__parser_callback_t.cpp @@ -1,15 +1,14 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // a JSON text given as std::vector - std::vector text = {'[', '1', ',', '2', ',', '3', ']', '\0'}; +int main() { + // a JSON text given as std::vector + std::vector text = {'[', '1', ',', '2', ',', '3', ']', '\0'}; - // parse and serialize JSON - json j_complete = json::parse(text); - std::cout << std::setw(4) << j_complete << "\n\n"; + // parse and serialize JSON + json j_complete = json::parse(text); + std::cout << std::setw(4) << j_complete << "\n\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/parse__istream__parser_callback_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/parse__istream__parser_callback_t.cpp index 2ef14dab..37fdc66c 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/parse__istream__parser_callback_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/parse__istream__parser_callback_t.cpp @@ -1,14 +1,13 @@ -#include #include -#include +#include #include +#include using json = nlohmann::json; -int main() -{ - // a JSON text - auto text = R"( +int main() { + // a JSON text + auto text = R"( { "Image": { "Width": 800, @@ -25,33 +24,30 @@ int main() } )"; - // fill a stream with JSON text - std::stringstream ss; - ss << text; + // fill a stream with JSON text + std::stringstream ss; + ss << text; - // parse and serialize JSON - json j_complete = json::parse(ss); - std::cout << std::setw(4) << j_complete << "\n\n"; + // parse and serialize JSON + json j_complete = json::parse(ss); + std::cout << std::setw(4) << j_complete << "\n\n"; - // define parser callback - json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed) - { - // skip object elements with key "Thumbnail" - if (event == json::parse_event_t::key and parsed == json("Thumbnail")) - { - return false; - } - else - { - return true; - } - }; + // define parser callback + json::parser_callback_t cb = [](int depth, json::parse_event_t event, + json &parsed) { + // skip object elements with key "Thumbnail" + if (event == json::parse_event_t::key and parsed == json("Thumbnail")) { + return false; + } else { + return true; + } + }; - // fill a stream with JSON text - ss.clear(); - ss << text; + // fill a stream with JSON text + ss.clear(); + ss << text; - // parse (with callback) and serialize JSON - json j_filtered = json::parse(ss, cb); - std::cout << std::setw(4) << j_filtered << '\n'; + // parse (with callback) and serialize JSON + json j_filtered = json::parse(ss, cb); + std::cout << std::setw(4) << j_filtered << '\n'; } \ No newline at end of file diff --git a/nlohmann_json/docs/mkdocs/docs/examples/parse__iterator_pair.cpp b/nlohmann_json/docs/mkdocs/docs/examples/parse__iterator_pair.cpp index d0c30c1a..223b6f9b 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/parse__iterator_pair.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/parse__iterator_pair.cpp @@ -1,15 +1,15 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // a JSON text given an input with other values - std::vector input = {'[', '1', ',', '2', ',', '3', ']', 'o', 't', 'h', 'e', 'r'}; +int main() { + // a JSON text given an input with other values + std::vector input = {'[', '1', ',', '2', ',', '3', + ']', 'o', 't', 'h', 'e', 'r'}; - // parse and serialize JSON - json j_complete = json::parse(input.begin(), input.begin() + 7); - std::cout << std::setw(4) << j_complete << "\n\n"; + // parse and serialize JSON + json j_complete = json::parse(input.begin(), input.begin() + 7); + std::cout << std::setw(4) << j_complete << "\n\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/parse__pointers.cpp b/nlohmann_json/docs/mkdocs/docs/examples/parse__pointers.cpp index a5a16eea..831d072c 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/parse__pointers.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/parse__pointers.cpp @@ -1,15 +1,14 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // a JSON text given as string that is not null-terminated - const char* ptr = "[1,2,3]another value"; +int main() { + // a JSON text given as string that is not null-terminated + const char *ptr = "[1,2,3]another value"; - // parse and serialize JSON - json j_complete = json::parse(ptr, ptr + 7); - std::cout << std::setw(4) << j_complete << "\n\n"; + // parse and serialize JSON + json j_complete = json::parse(ptr, ptr + 7); + std::cout << std::setw(4) << j_complete << "\n\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/parse__string__parser_callback_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/parse__string__parser_callback_t.cpp index 19c6c448..a811805f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/parse__string__parser_callback_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/parse__string__parser_callback_t.cpp @@ -1,13 +1,12 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // a JSON text - auto text = R"( +int main() { + // a JSON text + auto text = R"( { "Image": { "Width": 800, @@ -24,25 +23,22 @@ int main() } )"; - // parse and serialize JSON - json j_complete = json::parse(text); - std::cout << std::setw(4) << j_complete << "\n\n"; + // parse and serialize JSON + json j_complete = json::parse(text); + std::cout << std::setw(4) << j_complete << "\n\n"; - // define parser callback - json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed) - { - // skip object elements with key "Thumbnail" - if (event == json::parse_event_t::key and parsed == json("Thumbnail")) - { - return false; - } - else - { - return true; - } - }; + // define parser callback + json::parser_callback_t cb = [](int depth, json::parse_event_t event, + json &parsed) { + // skip object elements with key "Thumbnail" + if (event == json::parse_event_t::key and parsed == json("Thumbnail")) { + return false; + } else { + return true; + } + }; - // parse (with callback) and serialize JSON - json j_filtered = json::parse(text, cb); - std::cout << std::setw(4) << j_filtered << '\n'; + // parse (with callback) and serialize JSON + json j_filtered = json::parse(text, cb); + std::cout << std::setw(4) << j_filtered << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/parse_error.cpp b/nlohmann_json/docs/mkdocs/docs/examples/parse_error.cpp index ce15ebe2..3a9d832f 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/parse_error.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/parse_error.cpp @@ -3,18 +3,14 @@ using json = nlohmann::json; -int main() -{ - try - { - // parsing input with a syntax error - json::parse("[1,2,3,]"); - } - catch (const json::parse_error& e) - { - // output exception information - std::cout << "message: " << e.what() << '\n' - << "exception id: " << e.id << '\n' - << "byte position of error: " << e.byte << std::endl; - } +int main() { + try { + // parsing input with a syntax error + json::parse("[1,2,3,]"); + } catch (const json::parse_error &e) { + // output exception information + std::cout << "message: " << e.what() << '\n' + << "exception id: " << e.id << '\n' + << "byte position of error: " << e.byte << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/patch.cpp b/nlohmann_json/docs/mkdocs/docs/examples/patch.cpp index b7ecb8ee..1bf2c518 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/patch.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/patch.cpp @@ -1,22 +1,21 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // the original document - json doc = R"( +int main() { + // the original document + json doc = R"( { "baz": "qux", "foo": "bar" } )"_json; - // the patch - json patch = R"( + // the patch + json patch = R"( [ { "op": "replace", "path": "/baz", "value": "boo" }, { "op": "add", "path": "/hello", "value": ["world"] }, @@ -24,10 +23,10 @@ int main() ] )"_json; - // apply the patch - json patched_doc = doc.patch(patch); + // apply the patch + json patched_doc = doc.patch(patch); - // output original and patched document - std::cout << std::setw(4) << doc << "\n\n" - << std::setw(4) << patched_doc << std::endl; + // output original and patched document + std::cout << std::setw(4) << doc << "\n\n" + << std::setw(4) << patched_doc << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/patch_inplace.cpp b/nlohmann_json/docs/mkdocs/docs/examples/patch_inplace.cpp index 061708a2..09448f5a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/patch_inplace.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/patch_inplace.cpp @@ -1,22 +1,21 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // the original document - json doc = R"( +int main() { + // the original document + json doc = R"( { "baz": "qux", "foo": "bar" } )"_json; - // the patch - json patch = R"( + // the patch + json patch = R"( [ { "op": "replace", "path": "/baz", "value": "boo" }, { "op": "add", "path": "/hello", "value": ["world"] }, @@ -24,12 +23,12 @@ int main() ] )"_json; - // output original document - std::cout << "Before\n" << std::setw(4) << doc << std::endl; + // output original document + std::cout << "Before\n" << std::setw(4) << doc << std::endl; - // apply the patch - doc.patch_inplace(patch); + // apply the patch + doc.patch_inplace(patch); - // output patched document - std::cout << "\nAfter\n" << std::setw(4) << doc << std::endl; + // output patched document + std::cout << "\nAfter\n" << std::setw(4) << doc << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/push_back.cpp b/nlohmann_json/docs/mkdocs/docs/examples/push_back.cpp index bbddf4f5..73c3c186 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/push_back.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/push_back.cpp @@ -3,23 +3,22 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json array = {1, 2, 3, 4, 5}; - json null; +int main() { + // create JSON values + json array = {1, 2, 3, 4, 5}; + json null; - // print values - std::cout << array << '\n'; - std::cout << null << '\n'; + // print values + std::cout << array << '\n'; + std::cout << null << '\n'; - // add values - array.push_back(6); - array += 7; - null += "first"; - null += "second"; + // add values + array.push_back(6); + array += 7; + null += "first"; + null += "second"; - // print values - std::cout << array << '\n'; - std::cout << null << '\n'; + // print values + std::cout << array << '\n'; + std::cout << null << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/push_back__initializer_list.cpp b/nlohmann_json/docs/mkdocs/docs/examples/push_back__initializer_list.cpp index e96645f1..6d7256fb 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/push_back__initializer_list.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/push_back__initializer_list.cpp @@ -3,25 +3,24 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json object = {{"one", 1}, {"two", 2}}; - json null; +int main() { + // create JSON values + json object = {{"one", 1}, {"two", 2}}; + json null; - // print values - std::cout << object << '\n'; - std::cout << null << '\n'; + // print values + std::cout << object << '\n'; + std::cout << null << '\n'; - // add values: - object.push_back({"three", 3}); // object is extended - object += {"four", 4}; // object is extended - null.push_back({"five", 5}); // null is converted to array + // add values: + object.push_back({"three", 3}); // object is extended + object += {"four", 4}; // object is extended + null.push_back({"five", 5}); // null is converted to array - // print values - std::cout << object << '\n'; - std::cout << null << '\n'; + // print values + std::cout << object << '\n'; + std::cout << null << '\n'; - // would throw: - //object.push_back({1, 2, 3}); + // would throw: + // object.push_back({1, 2, 3}); } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/push_back__object_t__value.cpp b/nlohmann_json/docs/mkdocs/docs/examples/push_back__object_t__value.cpp index 5d694e93..de1ef385 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/push_back__object_t__value.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/push_back__object_t__value.cpp @@ -3,23 +3,22 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json object = {{"one", 1}, {"two", 2}}; - json null; +int main() { + // create JSON values + json object = {{"one", 1}, {"two", 2}}; + json null; - // print values - std::cout << object << '\n'; - std::cout << null << '\n'; + // print values + std::cout << object << '\n'; + std::cout << null << '\n'; - // add values - object.push_back(json::object_t::value_type("three", 3)); - object += json::object_t::value_type("four", 4); - null += json::object_t::value_type("A", "a"); - null += json::object_t::value_type("B", "b"); + // add values + object.push_back(json::object_t::value_type("three", 3)); + object += json::object_t::value_type("four", 4); + null += json::object_t::value_type("A", "a"); + null += json::object_t::value_type("B", "b"); - // print values - std::cout << object << '\n'; - std::cout << null << '\n'; + // print values + std::cout << object << '\n'; + std::cout << null << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/rbegin.cpp b/nlohmann_json/docs/mkdocs/docs/examples/rbegin.cpp index 239f7a68..6f596df0 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/rbegin.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/rbegin.cpp @@ -3,14 +3,13 @@ using json = nlohmann::json; -int main() -{ - // create an array value - json array = {1, 2, 3, 4, 5}; +int main() { + // create an array value + json array = {1, 2, 3, 4, 5}; - // get an iterator to the reverse-beginning - json::reverse_iterator it = array.rbegin(); + // get an iterator to the reverse-beginning + json::reverse_iterator it = array.rbegin(); - // serialize the element that the iterator points to - std::cout << *it << '\n'; + // serialize the element that the iterator points to + std::cout << *it << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/rend.cpp b/nlohmann_json/docs/mkdocs/docs/examples/rend.cpp index adadbbdc..d05f9d24 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/rend.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/rend.cpp @@ -3,17 +3,16 @@ using json = nlohmann::json; -int main() -{ - // create an array value - json array = {1, 2, 3, 4, 5}; +int main() { + // create an array value + json array = {1, 2, 3, 4, 5}; - // get an iterator to the reverse-end - json::reverse_iterator it = array.rend(); + // get an iterator to the reverse-end + json::reverse_iterator it = array.rend(); - // increment the iterator to point to the first element - --it; + // increment the iterator to point to the first element + --it; - // serialize the element that the iterator points to - std::cout << *it << '\n'; + // serialize the element that the iterator points to + std::cout << *it << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/sax_parse.cpp b/nlohmann_json/docs/mkdocs/docs/examples/sax_parse.cpp index 8602687e..9fd14c66 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/sax_parse.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/sax_parse.cpp @@ -1,101 +1,91 @@ -#include #include -#include +#include #include +#include using json = nlohmann::json; // a simple event consumer that collects string representations of the passed // values; note inheriting from json::json_sax_t is not required, but can // help not to forget a required function -class sax_event_consumer : public json::json_sax_t -{ - public: - std::vector events; - - bool null() override - { - events.push_back("null()"); - return true; - } - - bool boolean(bool val) override - { - events.push_back("boolean(val=" + std::string(val ? "true" : "false") + ")"); - return true; - } - - bool number_integer(number_integer_t val) override - { - events.push_back("number_integer(val=" + std::to_string(val) + ")"); - return true; - } - - bool number_unsigned(number_unsigned_t val) override - { - events.push_back("number_unsigned(val=" + std::to_string(val) + ")"); - return true; - } - - bool number_float(number_float_t val, const string_t& s) override - { - events.push_back("number_float(val=" + std::to_string(val) + ", s=" + s + ")"); - return true; - } - - bool string(string_t& val) override - { - events.push_back("string(val=" + val + ")"); - return true; - } - - bool start_object(std::size_t elements) override - { - events.push_back("start_object(elements=" + std::to_string(elements) + ")"); - return true; - } - - bool end_object() override - { - events.push_back("end_object()"); - return true; - } - - bool start_array(std::size_t elements) override - { - events.push_back("start_array(elements=" + std::to_string(elements) + ")"); - return true; - } - - bool end_array() override - { - events.push_back("end_array()"); - return true; - } - - bool key(string_t& val) override - { - events.push_back("key(val=" + val + ")"); - return true; - } - - bool binary(json::binary_t& val) override - { - events.push_back("binary(val=[...])"); - return true; - } - - bool parse_error(std::size_t position, const std::string& last_token, const json::exception& ex) override - { - events.push_back("parse_error(position=" + std::to_string(position) + ", last_token=" + last_token + ",\n ex=" + std::string(ex.what()) + ")"); - return false; - } +class sax_event_consumer : public json::json_sax_t { +public: + std::vector events; + + bool null() override { + events.push_back("null()"); + return true; + } + + bool boolean(bool val) override { + events.push_back("boolean(val=" + std::string(val ? "true" : "false") + + ")"); + return true; + } + + bool number_integer(number_integer_t val) override { + events.push_back("number_integer(val=" + std::to_string(val) + ")"); + return true; + } + + bool number_unsigned(number_unsigned_t val) override { + events.push_back("number_unsigned(val=" + std::to_string(val) + ")"); + return true; + } + + bool number_float(number_float_t val, const string_t &s) override { + events.push_back("number_float(val=" + std::to_string(val) + ", s=" + s + + ")"); + return true; + } + + bool string(string_t &val) override { + events.push_back("string(val=" + val + ")"); + return true; + } + + bool start_object(std::size_t elements) override { + events.push_back("start_object(elements=" + std::to_string(elements) + ")"); + return true; + } + + bool end_object() override { + events.push_back("end_object()"); + return true; + } + + bool start_array(std::size_t elements) override { + events.push_back("start_array(elements=" + std::to_string(elements) + ")"); + return true; + } + + bool end_array() override { + events.push_back("end_array()"); + return true; + } + + bool key(string_t &val) override { + events.push_back("key(val=" + val + ")"); + return true; + } + + bool binary(json::binary_t &val) override { + events.push_back("binary(val=[...])"); + return true; + } + + bool parse_error(std::size_t position, const std::string &last_token, + const json::exception &ex) override { + events.push_back("parse_error(position=" + std::to_string(position) + + ", last_token=" + last_token + + ",\n ex=" + std::string(ex.what()) + ")"); + return false; + } }; -int main() -{ - // a JSON text - auto text = R"( +int main() { + // a JSON text + auto text = R"( { "Image": { "Width": 800, @@ -114,18 +104,17 @@ int main() }] )"; - // create a SAX event consumer object - sax_event_consumer sec; + // create a SAX event consumer object + sax_event_consumer sec; - // parse JSON - bool result = json::sax_parse(text, &sec); + // parse JSON + bool result = json::sax_parse(text, &sec); - // output the recorded events - for (auto& event : sec.events) - { - std::cout << event << "\n"; - } + // output the recorded events + for (auto &event : sec.events) { + std::cout << event << "\n"; + } - // output the result of sax_parse - std::cout << "\nresult: " << std::boolalpha << result << std::endl; + // output the result of sax_parse + std::cout << "\nresult: " << std::boolalpha << result << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/sax_parse__binary.cpp b/nlohmann_json/docs/mkdocs/docs/examples/sax_parse__binary.cpp index 08bc85df..84db0c23 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/sax_parse__binary.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/sax_parse__binary.cpp @@ -1,114 +1,103 @@ -#include #include -#include +#include #include +#include using json = nlohmann::json; // a simple event consumer that collects string representations of the passed // values; note inheriting from json::json_sax_t is not required, but can // help not to forget a required function -class sax_event_consumer : public json::json_sax_t -{ - public: - std::vector events; - - bool null() override - { - events.push_back("null()"); - return true; - } - - bool boolean(bool val) override - { - events.push_back("boolean(val=" + std::string(val ? "true" : "false") + ")"); - return true; - } - - bool number_integer(number_integer_t val) override - { - events.push_back("number_integer(val=" + std::to_string(val) + ")"); - return true; - } - - bool number_unsigned(number_unsigned_t val) override - { - events.push_back("number_unsigned(val=" + std::to_string(val) + ")"); - return true; - } - - bool number_float(number_float_t val, const string_t& s) override - { - events.push_back("number_float(val=" + std::to_string(val) + ", s=" + s + ")"); - return true; - } - - bool string(string_t& val) override - { - events.push_back("string(val=" + val + ")"); - return true; - } - - bool start_object(std::size_t elements) override - { - events.push_back("start_object(elements=" + std::to_string(elements) + ")"); - return true; - } - - bool end_object() override - { - events.push_back("end_object()"); - return true; - } - - bool start_array(std::size_t elements) override - { - events.push_back("start_array(elements=" + std::to_string(elements) + ")"); - return true; - } - - bool end_array() override - { - events.push_back("end_array()"); - return true; - } - - bool key(string_t& val) override - { - events.push_back("key(val=" + val + ")"); - return true; - } - - bool binary(json::binary_t& val) override - { - events.push_back("binary(val=[...])"); - return true; - } - - bool parse_error(std::size_t position, const std::string& last_token, const json::exception& ex) override - { - events.push_back("parse_error(position=" + std::to_string(position) + ", last_token=" + last_token + ",\n ex=" + std::string(ex.what()) + ")"); - return false; - } +class sax_event_consumer : public json::json_sax_t { +public: + std::vector events; + + bool null() override { + events.push_back("null()"); + return true; + } + + bool boolean(bool val) override { + events.push_back("boolean(val=" + std::string(val ? "true" : "false") + + ")"); + return true; + } + + bool number_integer(number_integer_t val) override { + events.push_back("number_integer(val=" + std::to_string(val) + ")"); + return true; + } + + bool number_unsigned(number_unsigned_t val) override { + events.push_back("number_unsigned(val=" + std::to_string(val) + ")"); + return true; + } + + bool number_float(number_float_t val, const string_t &s) override { + events.push_back("number_float(val=" + std::to_string(val) + ", s=" + s + + ")"); + return true; + } + + bool string(string_t &val) override { + events.push_back("string(val=" + val + ")"); + return true; + } + + bool start_object(std::size_t elements) override { + events.push_back("start_object(elements=" + std::to_string(elements) + ")"); + return true; + } + + bool end_object() override { + events.push_back("end_object()"); + return true; + } + + bool start_array(std::size_t elements) override { + events.push_back("start_array(elements=" + std::to_string(elements) + ")"); + return true; + } + + bool end_array() override { + events.push_back("end_array()"); + return true; + } + + bool key(string_t &val) override { + events.push_back("key(val=" + val + ")"); + return true; + } + + bool binary(json::binary_t &val) override { + events.push_back("binary(val=[...])"); + return true; + } + + bool parse_error(std::size_t position, const std::string &last_token, + const json::exception &ex) override { + events.push_back("parse_error(position=" + std::to_string(position) + + ", last_token=" + last_token + + ",\n ex=" + std::string(ex.what()) + ")"); + return false; + } }; -int main() -{ - // CBOR byte string - std::vector vec = {{0x44, 0xcA, 0xfe, 0xba, 0xbe}}; +int main() { + // CBOR byte string + std::vector vec = {{0x44, 0xcA, 0xfe, 0xba, 0xbe}}; - // create a SAX event consumer object - sax_event_consumer sec; + // create a SAX event consumer object + sax_event_consumer sec; - // parse CBOR - bool result = json::sax_parse(vec, &sec, json::input_format_t::cbor); + // parse CBOR + bool result = json::sax_parse(vec, &sec, json::input_format_t::cbor); - // output the recorded events - for (auto& event : sec.events) - { - std::cout << event << "\n"; - } + // output the recorded events + for (auto &event : sec.events) { + std::cout << event << "\n"; + } - // output the result of sax_parse - std::cout << "\nresult: " << std::boolalpha << result << std::endl; + // output the result of sax_parse + std::cout << "\nresult: " << std::boolalpha << result << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/size.cpp b/nlohmann_json/docs/mkdocs/docs/examples/size.cpp index 23754837..aca4fe39 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/size.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/size.cpp @@ -3,27 +3,26 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = 17; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_object_empty(json::value_t::object); - json j_array = {1, 2, 4, 8, 16}; - json j_array_empty(json::value_t::array); - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_object_empty(json::value_t::object); + json j_array = {1, 2, 4, 8, 16}; + json j_array_empty(json::value_t::array); + json j_string = "Hello, world"; - // call size() - std::cout << j_null.size() << '\n'; - std::cout << j_boolean.size() << '\n'; - std::cout << j_number_integer.size() << '\n'; - std::cout << j_number_float.size() << '\n'; - std::cout << j_object.size() << '\n'; - std::cout << j_object_empty.size() << '\n'; - std::cout << j_array.size() << '\n'; - std::cout << j_array_empty.size() << '\n'; - std::cout << j_string.size() << '\n'; + // call size() + std::cout << j_null.size() << '\n'; + std::cout << j_boolean.size() << '\n'; + std::cout << j_number_integer.size() << '\n'; + std::cout << j_number_float.size() << '\n'; + std::cout << j_object.size() << '\n'; + std::cout << j_object_empty.size() << '\n'; + std::cout << j_array.size() << '\n'; + std::cout << j_array_empty.size() << '\n'; + std::cout << j_string.size() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/std_hash.cpp b/nlohmann_json/docs/mkdocs/docs/examples/std_hash.cpp index 9721910e..008ca4c9 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/std_hash.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/std_hash.cpp @@ -1,19 +1,18 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - std::cout << "hash(null) = " << std::hash {}(json(nullptr)) << '\n' - << "hash(false) = " << std::hash {}(json(false)) << '\n' - << "hash(0) = " << std::hash {}(json(0)) << '\n' - << "hash(0U) = " << std::hash {}(json(0U)) << '\n' - << "hash(\"\") = " << std::hash {}(json("")) << '\n' - << "hash({}) = " << std::hash {}(json::object()) << '\n' - << "hash([]) = " << std::hash {}(json::array()) << '\n' - << "hash({\"hello\": \"world\"}) = " << std::hash {}("{\"hello\": \"world\"}"_json) - << std::endl; +int main() { + std::cout << "hash(null) = " << std::hash{}(json(nullptr)) << '\n' + << "hash(false) = " << std::hash{}(json(false)) << '\n' + << "hash(0) = " << std::hash{}(json(0)) << '\n' + << "hash(0U) = " << std::hash{}(json(0U)) << '\n' + << "hash(\"\") = " << std::hash{}(json("")) << '\n' + << "hash({}) = " << std::hash{}(json::object()) << '\n' + << "hash([]) = " << std::hash{}(json::array()) << '\n' + << "hash({\"hello\": \"world\"}) = " + << std::hash{}("{\"hello\": \"world\"}"_json) << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/std_swap.cpp b/nlohmann_json/docs/mkdocs/docs/examples/std_swap.cpp index 36ab3ce6..481c3b76 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/std_swap.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/std_swap.cpp @@ -1,19 +1,18 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create JSON values - json j1 = {{"one", 1}, {"two", 2}}; - json j2 = {1, 2, 4, 8, 16}; +int main() { + // create JSON values + json j1 = {{"one", 1}, {"two", 2}}; + json j2 = {1, 2, 4, 8, 16}; - std::cout << "j1 = " << j1 << " | j2 = " << j2 << '\n'; + std::cout << "j1 = " << j1 << " | j2 = " << j2 << '\n'; - // swap values - std::swap(j1, j2); + // swap values + std::swap(j1, j2); - std::cout << "j1 = " << j1 << " | j2 = " << j2 << std::endl; + std::cout << "j1 = " << j1 << " | j2 = " << j2 << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/string_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/string_t.cpp index 77a9ea48..96f7c6ca 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/string_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/string_t.cpp @@ -1,10 +1,10 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - std::cout << std::boolalpha << std::is_same::value << std::endl; +int main() { + std::cout << std::boolalpha + << std::is_same::value << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/swap__array_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/swap__array_t.cpp index 2119dd55..4076fcd4 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/swap__array_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/swap__array_t.cpp @@ -3,18 +3,17 @@ using json = nlohmann::json; -int main() -{ - // create a JSON value - json value = {{"array", {1, 2, 3, 4}}}; +int main() { + // create a JSON value + json value = {{"array", {1, 2, 3, 4}}}; - // create an array_t - json::array_t array = {"Snap", "Crackle", "Pop"}; + // create an array_t + json::array_t array = {"Snap", "Crackle", "Pop"}; - // swap the array stored in the JSON value - value["array"].swap(array); + // swap the array stored in the JSON value + value["array"].swap(array); - // output the values - std::cout << "value = " << value << '\n'; - std::cout << "array = " << array << '\n'; + // output the values + std::cout << "value = " << value << '\n'; + std::cout << "array = " << array << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/swap__binary_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/swap__binary_t.cpp index 4b8fc3db..4dbea07d 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/swap__binary_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/swap__binary_t.cpp @@ -3,18 +3,17 @@ using json = nlohmann::json; -int main() -{ - // create a binary value - json value = json::binary({1, 2, 3}); +int main() { + // create a binary value + json value = json::binary({1, 2, 3}); - // create a binary_t - json::binary_t binary = {{4, 5, 6}}; + // create a binary_t + json::binary_t binary = {{4, 5, 6}}; - // swap the object stored in the JSON value - value.swap(binary); + // swap the object stored in the JSON value + value.swap(binary); - // output the values - std::cout << "value = " << value << '\n'; - std::cout << "binary = " << json(binary) << '\n'; + // output the values + std::cout << "value = " << value << '\n'; + std::cout << "binary = " << json(binary) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/swap__object_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/swap__object_t.cpp index 301b558d..71acb3ef 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/swap__object_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/swap__object_t.cpp @@ -3,18 +3,17 @@ using json = nlohmann::json; -int main() -{ - // create a JSON value - json value = { {"translation", {{"one", "eins"}, {"two", "zwei"}}} }; +int main() { + // create a JSON value + json value = {{"translation", {{"one", "eins"}, {"two", "zwei"}}}}; - // create an object_t - json::object_t object = {{"cow", "Kuh"}, {"dog", "Hund"}}; + // create an object_t + json::object_t object = {{"cow", "Kuh"}, {"dog", "Hund"}}; - // swap the object stored in the JSON value - value["translation"].swap(object); + // swap the object stored in the JSON value + value["translation"].swap(object); - // output the values - std::cout << "value = " << value << '\n'; - std::cout << "object = " << object << '\n'; + // output the values + std::cout << "value = " << value << '\n'; + std::cout << "object = " << object << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/swap__reference.cpp b/nlohmann_json/docs/mkdocs/docs/examples/swap__reference.cpp index 34182ad2..33bda301 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/swap__reference.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/swap__reference.cpp @@ -3,16 +3,15 @@ using json = nlohmann::json; -int main() -{ - // create two JSON values - json j1 = {1, 2, 3, 4, 5}; - json j2 = {{"pi", 3.141592653589793}, {"e", 2.718281828459045}}; +int main() { + // create two JSON values + json j1 = {1, 2, 3, 4, 5}; + json j2 = {{"pi", 3.141592653589793}, {"e", 2.718281828459045}}; - // swap the values - j1.swap(j2); + // swap the values + j1.swap(j2); - // output the values - std::cout << "j1 = " << j1 << '\n'; - std::cout << "j2 = " << j2 << '\n'; + // output the values + std::cout << "j1 = " << j1 << '\n'; + std::cout << "j2 = " << j2 << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/swap__string_t.cpp b/nlohmann_json/docs/mkdocs/docs/examples/swap__string_t.cpp index b5d58316..17ee59c0 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/swap__string_t.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/swap__string_t.cpp @@ -3,18 +3,17 @@ using json = nlohmann::json; -int main() -{ - // create a JSON value - json value = { "the good", "the bad", "the ugly" }; +int main() { + // create a JSON value + json value = {"the good", "the bad", "the ugly"}; - // create string_t - json::string_t string = "the fast"; + // create string_t + json::string_t string = "the fast"; - // swap the object stored in the JSON value - value[1].swap(string); + // swap the object stored in the JSON value + value[1].swap(string); - // output the values - std::cout << "value = " << value << '\n'; - std::cout << "string = " << string << '\n'; + // output the values + std::cout << "value = " << value << '\n'; + std::cout << "string = " << string << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/to_bjdata.cpp b/nlohmann_json/docs/mkdocs/docs/examples/to_bjdata.cpp index 9b7abac4..281e8e93 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/to_bjdata.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/to_bjdata.cpp @@ -1,64 +1,56 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; // function to print BJData's diagnostic format -void print_byte(uint8_t byte) -{ - if (32 < byte and byte < 128) - { - std::cout << (char)byte; - } - else - { - std::cout << (int)byte; - } +void print_byte(uint8_t byte) { + if (32 < byte and byte < 128) { + std::cout << (char)byte; + } else { + std::cout << (int)byte; + } } -int main() -{ - // create a JSON value - json j = R"({"compact": true, "schema": false})"_json; - - // serialize it to BJData - std::vector v = json::to_bjdata(j); - - // print the vector content - for (auto& byte : v) - { - print_byte(byte); - } - std::cout << std::endl; - - // create an array of numbers - json array = {1, 2, 3, 4, 5, 6, 7, 8}; - - // serialize it to BJData using default representation - std::vector v_array = json::to_bjdata(array); - // serialize it to BJData using size optimization - std::vector v_array_size = json::to_bjdata(array, true); - // serialize it to BJData using type optimization - std::vector v_array_size_and_type = json::to_bjdata(array, true, true); - - // print the vector contents - for (auto& byte : v_array) - { - print_byte(byte); - } - std::cout << std::endl; - - for (auto& byte : v_array_size) - { - print_byte(byte); - } - std::cout << std::endl; - - for (auto& byte : v_array_size_and_type) - { - print_byte(byte); - } - std::cout << std::endl; +int main() { + // create a JSON value + json j = R"({"compact": true, "schema": false})"_json; + + // serialize it to BJData + std::vector v = json::to_bjdata(j); + + // print the vector content + for (auto &byte : v) { + print_byte(byte); + } + std::cout << std::endl; + + // create an array of numbers + json array = {1, 2, 3, 4, 5, 6, 7, 8}; + + // serialize it to BJData using default representation + std::vector v_array = json::to_bjdata(array); + // serialize it to BJData using size optimization + std::vector v_array_size = json::to_bjdata(array, true); + // serialize it to BJData using type optimization + std::vector v_array_size_and_type = + json::to_bjdata(array, true, true); + + // print the vector contents + for (auto &byte : v_array) { + print_byte(byte); + } + std::cout << std::endl; + + for (auto &byte : v_array_size) { + print_byte(byte); + } + std::cout << std::endl; + + for (auto &byte : v_array_size_and_type) { + print_byte(byte); + } + std::cout << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/to_bson.cpp b/nlohmann_json/docs/mkdocs/docs/examples/to_bson.cpp index 3484b0b7..207734b4 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/to_bson.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/to_bson.cpp @@ -1,22 +1,21 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create a JSON value - json j = R"({"compact": true, "schema": 0})"_json; +int main() { + // create a JSON value + json j = R"({"compact": true, "schema": 0})"_json; - // serialize it to BSON - std::vector v = json::to_bson(j); + // serialize it to BSON + std::vector v = json::to_bson(j); - // print the vector content - for (auto& byte : v) - { - std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int)byte << " "; - } - std::cout << std::endl; + // print the vector content + for (auto &byte : v) { + std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') + << (int)byte << " "; + } + std::cout << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/to_cbor.cpp b/nlohmann_json/docs/mkdocs/docs/examples/to_cbor.cpp index 3d5e0415..0cc67c4c 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/to_cbor.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/to_cbor.cpp @@ -1,22 +1,21 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create a JSON value - json j = R"({"compact": true, "schema": 0})"_json; +int main() { + // create a JSON value + json j = R"({"compact": true, "schema": 0})"_json; - // serialize it to CBOR - std::vector v = json::to_cbor(j); + // serialize it to CBOR + std::vector v = json::to_cbor(j); - // print the vector content - for (auto& byte : v) - { - std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int)byte << " "; - } - std::cout << std::endl; + // print the vector content + for (auto &byte : v) { + std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') + << (int)byte << " "; + } + std::cout << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/to_json.cpp b/nlohmann_json/docs/mkdocs/docs/examples/to_json.cpp index 1f82a4de..2e594deb 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/to_json.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/to_json.cpp @@ -3,30 +3,25 @@ using json = nlohmann::json; -namespace ns -{ +namespace ns { // a simple struct to model a person -struct person -{ - std::string name; - std::string address; - int age; +struct person { + std::string name; + std::string address; + int age; }; } // namespace ns -namespace ns -{ -void to_json(json& j, const person& p) -{ - j = json{ {"name", p.name}, {"address", p.address}, {"age", p.age} }; +namespace ns { +void to_json(json &j, const person &p) { + j = json{{"name", p.name}, {"address", p.address}, {"age", p.age}}; } } // namespace ns -int main() -{ - ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; +int main() { + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; - json j = p; + json j = p; - std::cout << j << std::endl; + std::cout << j << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/to_msgpack.cpp b/nlohmann_json/docs/mkdocs/docs/examples/to_msgpack.cpp index b29ae8c7..2e005ac7 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/to_msgpack.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/to_msgpack.cpp @@ -1,22 +1,21 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create a JSON value - json j = R"({"compact": true, "schema": 0})"_json; +int main() { + // create a JSON value + json j = R"({"compact": true, "schema": 0})"_json; - // serialize it to MessagePack - std::vector v = json::to_msgpack(j); + // serialize it to MessagePack + std::vector v = json::to_msgpack(j); - // print the vector content - for (auto& byte : v) - { - std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int)byte << " "; - } - std::cout << std::endl; + // print the vector content + for (auto &byte : v) { + std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') + << (int)byte << " "; + } + std::cout << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/to_string.cpp b/nlohmann_json/docs/mkdocs/docs/examples/to_string.cpp index ee44283f..f7494317 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/to_string.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/to_string.cpp @@ -4,17 +4,15 @@ using json = nlohmann::json; using std::to_string; -int main() -{ - // create values - json j = {{"one", 1}, {"two", 2}}; - int i = 42; +int main() { + // create values + json j = {{"one", 1}, {"two", 2}}; + int i = 42; - // use ADL to select best to_string function - auto j_str = to_string(j); // calling nlohmann::to_string - auto i_str = to_string(i); // calling std::to_string + // use ADL to select best to_string function + auto j_str = to_string(j); // calling nlohmann::to_string + auto i_str = to_string(i); // calling std::to_string - // serialize without indentation - std::cout << j_str << "\n\n" - << i_str << std::endl; + // serialize without indentation + std::cout << j_str << "\n\n" << i_str << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/to_ubjson.cpp b/nlohmann_json/docs/mkdocs/docs/examples/to_ubjson.cpp index fd267a85..9fa0082b 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/to_ubjson.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/to_ubjson.cpp @@ -1,64 +1,56 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; // function to print UBJSON's diagnostic format -void print_byte(uint8_t byte) -{ - if (32 < byte and byte < 128) - { - std::cout << (char)byte; - } - else - { - std::cout << (int)byte; - } +void print_byte(uint8_t byte) { + if (32 < byte and byte < 128) { + std::cout << (char)byte; + } else { + std::cout << (int)byte; + } } -int main() -{ - // create a JSON value - json j = R"({"compact": true, "schema": false})"_json; - - // serialize it to UBJSON - std::vector v = json::to_ubjson(j); - - // print the vector content - for (auto& byte : v) - { - print_byte(byte); - } - std::cout << std::endl; - - // create an array of numbers - json array = {1, 2, 3, 4, 5, 6, 7, 8}; - - // serialize it to UBJSON using default representation - std::vector v_array = json::to_ubjson(array); - // serialize it to UBJSON using size optimization - std::vector v_array_size = json::to_ubjson(array, true); - // serialize it to UBJSON using type optimization - std::vector v_array_size_and_type = json::to_ubjson(array, true, true); - - // print the vector contents - for (auto& byte : v_array) - { - print_byte(byte); - } - std::cout << std::endl; - - for (auto& byte : v_array_size) - { - print_byte(byte); - } - std::cout << std::endl; - - for (auto& byte : v_array_size_and_type) - { - print_byte(byte); - } - std::cout << std::endl; +int main() { + // create a JSON value + json j = R"({"compact": true, "schema": false})"_json; + + // serialize it to UBJSON + std::vector v = json::to_ubjson(j); + + // print the vector content + for (auto &byte : v) { + print_byte(byte); + } + std::cout << std::endl; + + // create an array of numbers + json array = {1, 2, 3, 4, 5, 6, 7, 8}; + + // serialize it to UBJSON using default representation + std::vector v_array = json::to_ubjson(array); + // serialize it to UBJSON using size optimization + std::vector v_array_size = json::to_ubjson(array, true); + // serialize it to UBJSON using type optimization + std::vector v_array_size_and_type = + json::to_ubjson(array, true, true); + + // print the vector contents + for (auto &byte : v_array) { + print_byte(byte); + } + std::cout << std::endl; + + for (auto &byte : v_array_size) { + print_byte(byte); + } + std::cout << std::endl; + + for (auto &byte : v_array_size_and_type) { + print_byte(byte); + } + std::cout << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/trailing_commas.cpp b/nlohmann_json/docs/mkdocs/docs/examples/trailing_commas.cpp deleted file mode 100644 index 32bf6874..00000000 --- a/nlohmann_json/docs/mkdocs/docs/examples/trailing_commas.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include - -using json = nlohmann::json; - -int main() -{ - std::string s = R"( - { - "planets": [ - "Mercury", - "Venus", - "Earth", - "Mars", - "Jupiter", - "Uranus", - "Neptune", - ] - } - )"; - - try - { - json j = json::parse(s); - } - catch (json::exception& e) - { - std::cout << e.what() << std::endl; - } - - json j = json::parse(s, - /* callback */ nullptr, - /* allow exceptions */ true, - /* ignore_comments */ false, - /* ignore_trailing_commas */ true); - std::cout << j.dump(2) << '\n'; -} diff --git a/nlohmann_json/docs/mkdocs/docs/examples/trailing_commas.output b/nlohmann_json/docs/mkdocs/docs/examples/trailing_commas.output deleted file mode 100644 index 3b2c49eb..00000000 --- a/nlohmann_json/docs/mkdocs/docs/examples/trailing_commas.output +++ /dev/null @@ -1,12 +0,0 @@ -[json.exception.parse_error.101] parse error at line 11, column 9: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal -{ - "planets": [ - "Mercury", - "Venus", - "Earth", - "Mars", - "Jupiter", - "Uranus", - "Neptune" - ] -} diff --git a/nlohmann_json/docs/mkdocs/docs/examples/type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/type.cpp index 68fba3a9..73e88b13 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/type.cpp @@ -3,26 +3,27 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = -17; - json j_number_unsigned = 42u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = -17; + json j_number_unsigned = 42u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; - // call type() - std::cout << std::boolalpha; - std::cout << (j_null.type() == json::value_t::null) << '\n'; - std::cout << (j_boolean.type() == json::value_t::boolean) << '\n'; - std::cout << (j_number_integer.type() == json::value_t::number_integer) << '\n'; - std::cout << (j_number_unsigned.type() == json::value_t::number_unsigned) << '\n'; - std::cout << (j_number_float.type() == json::value_t::number_float) << '\n'; - std::cout << (j_object.type() == json::value_t::object) << '\n'; - std::cout << (j_array.type() == json::value_t::array) << '\n'; - std::cout << (j_string.type() == json::value_t::string) << '\n'; + // call type() + std::cout << std::boolalpha; + std::cout << (j_null.type() == json::value_t::null) << '\n'; + std::cout << (j_boolean.type() == json::value_t::boolean) << '\n'; + std::cout << (j_number_integer.type() == json::value_t::number_integer) + << '\n'; + std::cout << (j_number_unsigned.type() == json::value_t::number_unsigned) + << '\n'; + std::cout << (j_number_float.type() == json::value_t::number_float) << '\n'; + std::cout << (j_object.type() == json::value_t::object) << '\n'; + std::cout << (j_array.type() == json::value_t::array) << '\n'; + std::cout << (j_string.type() == json::value_t::string) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/type_error.cpp b/nlohmann_json/docs/mkdocs/docs/examples/type_error.cpp index f520f401..19825494 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/type_error.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/type_error.cpp @@ -3,18 +3,14 @@ using json = nlohmann::json; -int main() -{ - try - { - // calling push_back() on a string value - json j = "string"; - j.push_back("another string"); - } - catch (const json::type_error& e) - { - // output exception information - std::cout << "message: " << e.what() << '\n' - << "exception id: " << e.id << std::endl; - } +int main() { + try { + // calling push_back() on a string value + json j = "string"; + j.push_back("another string"); + } catch (const json::type_error &e) { + // output exception information + std::cout << "message: " << e.what() << '\n' + << "exception id: " << e.id << std::endl; + } } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/type_name.cpp b/nlohmann_json/docs/mkdocs/docs/examples/type_name.cpp index 32d3590c..0c592bcc 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/type_name.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/type_name.cpp @@ -3,25 +3,26 @@ using json = nlohmann::json; -int main() -{ - // create JSON values - json j_null; - json j_boolean = true; - json j_number_integer = -17; - json j_number_unsigned = 42u; - json j_number_float = 23.42; - json j_object = {{"one", 1}, {"two", 2}}; - json j_array = {1, 2, 4, 8, 16}; - json j_string = "Hello, world"; +int main() { + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = -17; + json j_number_unsigned = 42u; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; - // call type_name() - std::cout << j_null << " is a " << j_null.type_name() << '\n'; - std::cout << j_boolean << " is a " << j_boolean.type_name() << '\n'; - std::cout << j_number_integer << " is a " << j_number_integer.type_name() << '\n'; - std::cout << j_number_unsigned << " is a " << j_number_unsigned.type_name() << '\n'; - std::cout << j_number_float << " is a " << j_number_float.type_name() << '\n'; - std::cout << j_object << " is an " << j_object.type_name() << '\n'; - std::cout << j_array << " is an " << j_array.type_name() << '\n'; - std::cout << j_string << " is a " << j_string.type_name() << '\n'; + // call type_name() + std::cout << j_null << " is a " << j_null.type_name() << '\n'; + std::cout << j_boolean << " is a " << j_boolean.type_name() << '\n'; + std::cout << j_number_integer << " is a " << j_number_integer.type_name() + << '\n'; + std::cout << j_number_unsigned << " is a " << j_number_unsigned.type_name() + << '\n'; + std::cout << j_number_float << " is a " << j_number_float.type_name() << '\n'; + std::cout << j_object << " is an " << j_object.type_name() << '\n'; + std::cout << j_array << " is an " << j_array.type_name() << '\n'; + std::cout << j_string << " is a " << j_string.type_name() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/unflatten.cpp b/nlohmann_json/docs/mkdocs/docs/examples/unflatten.cpp index 75fb02d0..9548004a 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/unflatten.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/unflatten.cpp @@ -1,26 +1,22 @@ -#include #include +#include #include using json = nlohmann::json; -int main() -{ - // create JSON value - json j_flattened = - { - {"/answer/everything", 42}, - {"/happy", true}, - {"/list/0", 1}, - {"/list/1", 0}, - {"/list/2", 2}, - {"/name", "Niels"}, - {"/nothing", nullptr}, - {"/object/currency", "USD"}, - {"/object/value", 42.99}, - {"/pi", 3.141} - }; +int main() { + // create JSON value + json j_flattened = {{"/answer/everything", 42}, + {"/happy", true}, + {"/list/0", 1}, + {"/list/1", 0}, + {"/list/2", 2}, + {"/name", "Niels"}, + {"/nothing", nullptr}, + {"/object/currency", "USD"}, + {"/object/value", 42.99}, + {"/pi", 3.141}}; - // call unflatten() - std::cout << std::setw(4) << j_flattened.unflatten() << '\n'; + // call unflatten() + std::cout << std::setw(4) << j_flattened.unflatten() << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/update.cpp b/nlohmann_json/docs/mkdocs/docs/examples/update.cpp index ff94b67f..7a99abde 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/update.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/update.cpp @@ -1,24 +1,25 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create two JSON objects - json o1 = R"( {"color": "red", "price": 17.99, "names": {"de": "Flugzeug"}} )"_json; - json o2 = R"( {"color": "blue", "speed": 100, "names": {"en": "plane"}} )"_json; - json o3 = o1; +int main() { + // create two JSON objects + json o1 = + R"( {"color": "red", "price": 17.99, "names": {"de": "Flugzeug"}} )"_json; + json o2 = + R"( {"color": "blue", "speed": 100, "names": {"en": "plane"}} )"_json; + json o3 = o1; - // add all keys from o2 to o1 (updating "color", replacing "names") - o1.update(o2); + // add all keys from o2 to o1 (updating "color", replacing "names") + o1.update(o2); - // add all keys from o2 to o1 (updating "color", merging "names") - o3.update(o2, true); + // add all keys from o2 to o1 (updating "color", merging "names") + o3.update(o2, true); - // output updated object o1 and o3 - std::cout << std::setw(2) << o1 << '\n'; - std::cout << std::setw(2) << o3 << '\n'; + // output updated object o1 and o3 + std::cout << std::setw(2) << o1 << '\n'; + std::cout << std::setw(2) << o3 << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/update__range.cpp b/nlohmann_json/docs/mkdocs/docs/examples/update__range.cpp index 5b438504..557e1669 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/update__range.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/update__range.cpp @@ -1,24 +1,25 @@ -#include #include +#include #include using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create two JSON objects - json o1 = R"( {"color": "red", "price": 17.99, "names": {"de": "Flugzeug"}} )"_json; - json o2 = R"( {"color": "blue", "speed": 100, "names": {"en": "plane"}} )"_json; - json o3 = o1; +int main() { + // create two JSON objects + json o1 = + R"( {"color": "red", "price": 17.99, "names": {"de": "Flugzeug"}} )"_json; + json o2 = + R"( {"color": "blue", "speed": 100, "names": {"en": "plane"}} )"_json; + json o3 = o1; - // add all keys from o2 to o1 (updating "color", replacing "names") - o1.update(o2.begin(), o2.end()); + // add all keys from o2 to o1 (updating "color", replacing "names") + o1.update(o2.begin(), o2.end()); - // add all keys from o2 to o1 (updating "color", merging "names") - o3.update(o2.begin(), o2.end(), true); + // add all keys from o2 to o1 (updating "color", merging "names") + o3.update(o2.begin(), o2.end(), true); - // output updated object o1 and o3 - std::cout << std::setw(2) << o1 << '\n'; - std::cout << std::setw(2) << o3 << '\n'; + // output updated object o1 and o3 + std::cout << std::setw(2) << o1 << '\n'; + std::cout << std::setw(2) << o3 << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/value__json_ptr.cpp b/nlohmann_json/docs/mkdocs/docs/examples/value__json_ptr.cpp index d866ef07..3156b229 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/value__json_ptr.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/value__json_ptr.cpp @@ -4,28 +4,24 @@ using json = nlohmann::json; using namespace nlohmann::literals; -int main() -{ - // create a JSON object with different entry types - json j = - { - {"integer", 1}, - {"floating", 42.23}, - {"string", "hello world"}, - {"boolean", true}, - {"object", {{"key1", 1}, {"key2", 2}}}, - {"array", {1, 2, 3}} - }; +int main() { + // create a JSON object with different entry types + json j = {{"integer", 1}, + {"floating", 42.23}, + {"string", "hello world"}, + {"boolean", true}, + {"object", {{"key1", 1}, {"key2", 2}}}, + {"array", {1, 2, 3}}}; - // access existing values - int v_integer = j.value("/integer"_json_pointer, 0); - double v_floating = j.value("/floating"_json_pointer, 47.11); + // access existing values + int v_integer = j.value("/integer"_json_pointer, 0); + double v_floating = j.value("/floating"_json_pointer, 47.11); - // access nonexisting values and rely on default value - std::string v_string = j.value("/nonexisting"_json_pointer, "oops"); - bool v_boolean = j.value("/nonexisting"_json_pointer, false); + // access nonexisting values and rely on default value + std::string v_string = j.value("/nonexisting"_json_pointer, "oops"); + bool v_boolean = j.value("/nonexisting"_json_pointer, false); - // output values - std::cout << std::boolalpha << v_integer << " " << v_floating - << " " << v_string << " " << v_boolean << "\n"; + // output values + std::cout << std::boolalpha << v_integer << " " << v_floating << " " + << v_string << " " << v_boolean << "\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/value__keytype.c++17.cpp b/nlohmann_json/docs/mkdocs/docs/examples/value__keytype.c++17.cpp index 1f6ff5c3..8ef40aae 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/value__keytype.c++17.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/value__keytype.c++17.cpp @@ -1,32 +1,28 @@ #include -#include #include +#include using namespace std::string_view_literals; using json = nlohmann::json; -int main() -{ - // create a JSON object with different entry types - json j = - { - {"integer", 1}, - {"floating", 42.23}, - {"string", "hello world"}, - {"boolean", true}, - {"object", {{"key1", 1}, {"key2", 2}}}, - {"array", {1, 2, 3}} - }; +int main() { + // create a JSON object with different entry types + json j = {{"integer", 1}, + {"floating", 42.23}, + {"string", "hello world"}, + {"boolean", true}, + {"object", {{"key1", 1}, {"key2", 2}}}, + {"array", {1, 2, 3}}}; - // access existing values - int v_integer = j.value("integer"sv, 0); - double v_floating = j.value("floating"sv, 47.11); + // access existing values + int v_integer = j.value("integer"sv, 0); + double v_floating = j.value("floating"sv, 47.11); - // access nonexisting values and rely on default value - std::string v_string = j.value("nonexisting"sv, "oops"); - bool v_boolean = j.value("nonexisting"sv, false); + // access nonexisting values and rely on default value + std::string v_string = j.value("nonexisting"sv, "oops"); + bool v_boolean = j.value("nonexisting"sv, false); - // output values - std::cout << std::boolalpha << v_integer << " " << v_floating - << " " << v_string << " " << v_boolean << "\n"; + // output values + std::cout << std::boolalpha << v_integer << " " << v_floating << " " + << v_string << " " << v_boolean << "\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/value__object_t_key_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/value__object_t_key_type.cpp index 9488d30e..7a034e35 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/value__object_t_key_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/value__object_t_key_type.cpp @@ -3,28 +3,24 @@ using json = nlohmann::json; -int main() -{ - // create a JSON object with different entry types - json j = - { - {"integer", 1}, - {"floating", 42.23}, - {"string", "hello world"}, - {"boolean", true}, - {"object", {{"key1", 1}, {"key2", 2}}}, - {"array", {1, 2, 3}} - }; +int main() { + // create a JSON object with different entry types + json j = {{"integer", 1}, + {"floating", 42.23}, + {"string", "hello world"}, + {"boolean", true}, + {"object", {{"key1", 1}, {"key2", 2}}}, + {"array", {1, 2, 3}}}; - // access existing values - int v_integer = j.value("integer", 0); - double v_floating = j.value("floating", 47.11); + // access existing values + int v_integer = j.value("integer", 0); + double v_floating = j.value("floating", 47.11); - // access nonexisting values and rely on default value - std::string v_string = j.value("nonexisting", "oops"); - bool v_boolean = j.value("nonexisting", false); + // access nonexisting values and rely on default value + std::string v_string = j.value("nonexisting", "oops"); + bool v_boolean = j.value("nonexisting", false); - // output values - std::cout << std::boolalpha << v_integer << " " << v_floating - << " " << v_string << " " << v_boolean << "\n"; + // output values + std::cout << std::boolalpha << v_integer << " " << v_floating << " " + << v_string << " " << v_boolean << "\n"; } diff --git a/nlohmann_json/docs/mkdocs/docs/examples/value__return_type.cpp b/nlohmann_json/docs/mkdocs/docs/examples/value__return_type.cpp index 51ab7afa..2963038c 100644 --- a/nlohmann_json/docs/mkdocs/docs/examples/value__return_type.cpp +++ b/nlohmann_json/docs/mkdocs/docs/examples/value__return_type.cpp @@ -3,12 +3,13 @@ using json = nlohmann::json; -int main() -{ - json j = json::parse(R"({"uint64": 18446744073709551615})"); +int main() { + json j = json::parse(R"({"uint64": 18446744073709551615})"); - std::cout << "operator[]: " << j["uint64"] << '\n' - << "default value (int): " << j.value("uint64", 0) << '\n' - << "default value (uint64_t): " << j.value("uint64", std::uint64_t(0)) << '\n' - << "explict return value type: " << j.value("uint64", 0) << '\n'; + std::cout << "operator[]: " << j["uint64"] << '\n' + << "default value (int): " << j.value("uint64", 0) << '\n' + << "default value (uint64_t): " + << j.value("uint64", std::uint64_t(0)) << '\n' + << "explict return value type: " + << j.value("uint64", 0) << '\n'; } diff --git a/nlohmann_json/docs/mkdocs/docs/features/binary_formats/cbor.md b/nlohmann_json/docs/mkdocs/docs/features/binary_formats/cbor.md index a4240ffa..2d0a1dae 100644 --- a/nlohmann_json/docs/mkdocs/docs/features/binary_formats/cbor.md +++ b/nlohmann_json/docs/mkdocs/docs/features/binary_formats/cbor.md @@ -1,7 +1,7 @@ # CBOR -The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of -extremely small code sizes, fairly small message size, and extensibility without the need for version negotiation. +The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of extremely +small code size, fairly small message size, and extensibility without the need for version negotiation. !!! abstract "References" diff --git a/nlohmann_json/docs/mkdocs/docs/features/binary_values.md b/nlohmann_json/docs/mkdocs/docs/features/binary_values.md index 260d67b5..149eaaa5 100644 --- a/nlohmann_json/docs/mkdocs/docs/features/binary_values.md +++ b/nlohmann_json/docs/mkdocs/docs/features/binary_values.md @@ -1,7 +1,7 @@ # Binary Values The library implements several [binary formats](binary_formats/index.md) that encode JSON in an efficient way. Most of -these formats support binary values; that is, values that have semantics defined outside the library and only define a +these formats support binary values; that is, values that have semantics define outside the library and only define a sequence of bytes to be stored. JSON itself does not have a binary value. As such, binary values are an extension that this library implements to store @@ -189,7 +189,7 @@ as an array of uint8 values. The library implements this translation. ### BSON -[BSON](binary_formats/bson.md) supports binary values and subtypes. If a subtype is given, it is used and added as an +[BSON](binary_formats/bson.md) supports binary values and subtypes. If a subtype is given, it is used and added as unsigned 8-bit integer. If no subtype is given, the generic binary subtype 0x00 is used. ??? example @@ -274,7 +274,7 @@ byte array. [MessagePack](binary_formats/messagepack.md) supports binary values and subtypes. If a subtype is given, the ext family is used. The library will choose the smallest representation among fixext1, fixext2, fixext4, fixext8, ext8, ext16, and -ext32. The subtype is then added as a signed 8-bit integer. +ext32. The subtype is then added as signed 8-bit integer. If no subtype is given, the bin family (bin8, bin16, bin32) is used. diff --git a/nlohmann_json/docs/mkdocs/docs/features/comments.md b/nlohmann_json/docs/mkdocs/docs/features/comments.md index 6876cc50..fca53111 100644 --- a/nlohmann_json/docs/mkdocs/docs/features/comments.md +++ b/nlohmann_json/docs/mkdocs/docs/features/comments.md @@ -11,9 +11,7 @@ This library does not support comments *by default*. It does so for three reason 3. It is dangerous for interoperability if some libraries add comment support while others do not. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this. -However, you can set parameter `ignore_comments` to `#!cpp true` in the [`parse`](../api/basic_json/parse.md) function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace. - -For more information, see [JSON With Commas and Comments (JWCC)](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html). +However, you can pass set parameter `ignore_comments` to `#!c true` in the parse function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace. !!! example @@ -30,11 +28,56 @@ For more information, see [JSON With Commas and Comments (JWCC)](https://nigelta When calling `parse` without additional argument, a parse error exception is thrown. If `ignore_comments` is set to `#! true`, the comments are ignored during parsing: ```cpp - --8<-- "examples/comments.cpp" + #include + #include "json.hpp" + + using json = nlohmann::json; + + int main() + { + std::string s = R"( + { + // update in 2006: removed Pluto + "planets": ["Mercury", "Venus", "Earth", "Mars", + "Jupiter", "Uranus", "Neptune" /*, "Pluto" */] + } + )"; + + try + { + json j = json::parse(s); + } + catch (json::exception &e) + { + std::cout << e.what() << std::endl; + } + + json j = json::parse(s, + /* callback */ nullptr, + /* allow exceptions */ true, + /* ignore_comments */ true); + std::cout << j.dump(2) << '\n'; + } ``` Output: ``` - --8<-- "examples/comments.output" + [json.exception.parse_error.101] parse error at line 3, column 9: + syntax error while parsing object key - invalid literal; + last read: ' { /'; expected string literal + ``` + + ```json + { + "planets": [ + "Mercury", + "Venus", + "Earth", + "Mars", + "Jupiter", + "Uranus", + "Neptune" + ] + } ``` diff --git a/nlohmann_json/docs/mkdocs/docs/features/enum_conversion.md b/nlohmann_json/docs/mkdocs/docs/features/enum_conversion.md index 58d353a0..6bb3edbd 100644 --- a/nlohmann_json/docs/mkdocs/docs/features/enum_conversion.md +++ b/nlohmann_json/docs/mkdocs/docs/features/enum_conversion.md @@ -1,8 +1,8 @@ # Specializing enum conversion -By default, enum values are serialized to JSON as integers. In some cases, this could result in undesired behavior. If -the integer values of any enum values are changed after data using those enum values has been serialized to JSON, then -deserializing that JSON would result in a different enum value being restored, or the value not being found at all. +By default, enum values are serialized to JSON as integers. In some cases this could result in undesired behavior. If an +enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be +undefined or a different enum value than was originally intended. It is possible to more precisely specify how a given enum is mapped to and from JSON as shown below: diff --git a/nlohmann_json/docs/mkdocs/docs/features/iterators.md b/nlohmann_json/docs/mkdocs/docs/features/iterators.md index 6d8afc7f..ca303cb4 100644 --- a/nlohmann_json/docs/mkdocs/docs/features/iterators.md +++ b/nlohmann_json/docs/mkdocs/docs/features/iterators.md @@ -37,7 +37,7 @@ When iterating over objects, values are ordered with respect to the `object_comp The reason for the order is the lexicographic ordering of the object keys "one", "three", "two". -### Access object keys during iteration +### Access object key during iteration The JSON iterators have two member functions, `key()` and `value()` to access the object key and stored value, respectively. When calling `key()` on a non-object iterator, an [invalid_iterator.207](../home/exceptions.md#jsonexceptioninvalid_iterator207) exception is thrown. diff --git a/nlohmann_json/docs/mkdocs/docs/features/json_pointer.md b/nlohmann_json/docs/mkdocs/docs/features/json_pointer.md index a16e8df2..df66ebff 100644 --- a/nlohmann_json/docs/mkdocs/docs/features/json_pointer.md +++ b/nlohmann_json/docs/mkdocs/docs/features/json_pointer.md @@ -42,7 +42,7 @@ Note `/` does not identify the root (i.e., the whole document), but an object en JSON Pointers can be created from a string: ```cpp -json::json_pointer p("/nested/one"); +json::json_pointer p = "/nested/one"; ``` Furthermore, a user-defined string literal can be used to achieve the same result: diff --git a/nlohmann_json/docs/mkdocs/docs/features/namespace.md b/nlohmann_json/docs/mkdocs/docs/features/namespace.md index ca541809..460cb3be 100644 --- a/nlohmann_json/docs/mkdocs/docs/features/namespace.md +++ b/nlohmann_json/docs/mkdocs/docs/features/namespace.md @@ -64,7 +64,7 @@ configurations – to be used in cases where the linker would otherwise output u To do so, define [`NLOHMANN_JSON_NAMESPACE_NO_VERSION`](../api/macros/nlohmann_json_namespace_no_version.md) to `1`. -This applies to version 3.11.2 and above only; versions 3.11.0 and 3.11.1 can apply the technique described in the next +This applies to version 3.11.2 and above only, versions 3.11.0 and 3.11.1 can apply the technique described in the next section to emulate the effect of the `NLOHMANN_JSON_NAMESPACE_NO_VERSION` macro. !!! danger "Use at your own risk" diff --git a/nlohmann_json/docs/mkdocs/docs/features/trailing_commas.md b/nlohmann_json/docs/mkdocs/docs/features/trailing_commas.md deleted file mode 100644 index 583e7cbf..00000000 --- a/nlohmann_json/docs/mkdocs/docs/features/trailing_commas.md +++ /dev/null @@ -1,39 +0,0 @@ -# Trailing Commas - -Like [comments](comments.md), this library does not support trailing commas in arrays and objects *by default*. - -You can set parameter `ignore_trailing_commas` to `#!cpp true` in the [`parse`](../api/basic_json/parse.md) function to allow trailing commas in arrays and objects. Note that a single comma as the only content of the array or object (`[,]` or `{,}`) is not allowed, and multiple trailing commas (`[1,,]`) are not allowed either. - -This library does not add trailing commas when serializing JSON data. - -For more information, see [JSON With Commas and Comments (JWCC)](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html). - -!!! example - - Consider the following JSON with trailing commas. - - ```json - { - "planets": [ - "Mercury", - "Venus", - "Earth", - "Mars", - "Jupiter", - "Uranus", - "Neptune", - ] - } - ``` - - When calling `parse` without additional argument, a parse error exception is thrown. If `ignore_trailing_commas` is set to `#! true`, the trailing commas are ignored during parsing: - - ```cpp - --8<-- "examples/trailing_commas.cpp" - ``` - - Output: - - ``` - --8<-- "examples/trailing_commas.output" - ``` diff --git a/nlohmann_json/docs/mkdocs/docs/home/customers.md b/nlohmann_json/docs/mkdocs/docs/home/customers.md index 4bfef0c7..8e111652 100644 --- a/nlohmann_json/docs/mkdocs/docs/home/customers.md +++ b/nlohmann_json/docs/mkdocs/docs/home/customers.md @@ -13,7 +13,7 @@ the result of an internet search. If you know further customers of the library, - [**Alexa Auto SDK**](https://github.com/alexa/alexa-auto-sdk), a software development kit enabling the integration of Alexa into automotive systems - [**Apollo**](https://github.com/ApolloAuto/apollo), a framework for building autonomous driving systems -- [**Automotive Grade Linux (AGL)**](https://download.automotivelinux.org/AGL/release/jellyfish/latest/qemux86-64/deploy/licenses/nlohmann-json/), a collaborative open-source platform for automotive software development +- [**Automotive Grade Linux (AGL)**](https://download.automotivelinux.org/AGL/release/jellyfish/latest/qemux86-64/deploy/licenses/nlohmann-json/): a collaborative open-source platform for automotive software development - [**Genesis Motor** (infotainment)](http://webmanual.genesis.com/ccIC/AVNT/JW/KOR/English/reference010.html), a luxury automotive brand - [**Hyundai** (infotainment)](https://www.hyundai.com/wsvc/ww/download.file.do?id=/content/hyundai/ww/data/opensource/data/GN7-2022/licenseCode/info), a global automotive brand - [**Kia** (infotainment)](http://webmanual.kia.com/PREM_GEN6/AVNT/RJPE/KOR/Korean/reference010.html), a global automotive brand @@ -23,36 +23,30 @@ the result of an internet search. If you know further customers of the library, ## Gaming and Entertainment -- [**Assassin's Creed: Mirage**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/), a stealth-action game set in the Middle East, focusing on the journey of a young assassin with classic parkour and stealth mechanics -- [**Chasm: The Rift**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/), a first-person shooter blending horror and adventure, where players navigate dark realms and battle monsters -- [**College Football 25**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/), a college football simulation game featuring gameplay that mimics real-life college teams and competitions -- [**Concepts**](https://concepts.app/en/licenses), a digital sketching app designed for creative professionals, offering flexible drawing tools for illustration, design, and brainstorming -- [**Depthkit**](https://www.depthkit.tv/third-party-licenses), a tool for creating and capturing volumetric video, enabling immersive 3D experiences and interactive content -- [**IMG.LY**](https://img.ly/acknowledgements), a platform offering creative tools and SDKs for integrating advanced image and video editing in applications +- [**Assassin's Creed: Mirage**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/): a stealth-action game set in the Middle East, focusing on the journey of a young assassin with classic parkour and stealth mechanics +- [**Chasm: The Rift**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/): a first-person shooter blending horror and adventure, where players navigate dark realms and battle monsters +- [**College Football 25**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/): a college football simulation game featuring gameplay that mimics real-life college teams and competitions +- [**Concepts**](https://concepts.app/en/licenses): a digital sketching app designed for creative professionals, offering flexible drawing tools for illustration, design, and brainstorming +- [**Depthkit**](https://www.depthkit.tv/third-party-licenses): a tool for creating and capturing volumetric video, enabling immersive 3D experiences and interactive content +- [**immersivetech**](https://immersitech.io/open-source-third-party-software/): a technology company focused on immersive experiences, providing tools and solutions for virtual and augmented reality applications - [**LOOT**](https://loot.readthedocs.io/_/downloads/en/0.13.0/pdf/), a tool for optimizing the load order of game plugins, commonly used in The Elder Scrolls and Fallout series -- [**Madden NFL 25**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/), a sports simulation game capturing the excitement of American football with realistic gameplay and team management features +- [**Madden NFL 25**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/): a sports simulation game capturing the excitement of American football with realistic gameplay and team management features - [**Marne**](https://marne.io/licenses), an unofficial private server platform for hosting custom Battlefield 1 game experiences - [**Minecraft**](https://www.minecraft.net/zh-hant/attribution), a popular sandbox video game -- [**NHL 22**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/), a hockey simulation game offering realistic gameplay, team management, and various modes to enhance the hockey experience -- [**Pixelpart**](https://pixelpart.net/documentation/book/third-party.html), a 2D animation and video compositing software that allows users to create animated graphics and visual effects with a focus on simplicity and ease of use -- [**Razer Cortex**](https://mysupport.razer.com/app/answers/detail/a_id/14146/~/open-source-software-for-razer-software), a gaming performance optimizer and system booster designed to enhance the gaming experience -- [**Red Dead Redemption II**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/), an open-world action-adventure game following an outlaw's story in the late 1800s, emphasizing deep storytelling and immersive gameplay -- [**Snapchat**](https://www.snap.com/terms/license-android), a multimedia messaging and augmented reality app for communication and entertainment +- [**NHL 22**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/): a hockey simulation game offering realistic gameplay, team management, and various modes to enhance the hockey experience +- [**Pixelpart**](https://pixelpart.net/documentation/book/third-party.html): a 2D animation and video compositing software that allows users to create animated graphics and visual effects with a focus on simplicity and ease of use +- [**Red Dead Redemption II**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/): an open-world action-adventure game following an outlaw's story in the late 1800s, emphasizing deep storytelling and immersive gameplay - [**Tactics Ogre: Reborn**](https://www.square-enix-games.com/en_US/documents/tactics-ogre-reborn-pc-installer-software-and-associated-plug-ins-disclosure), a tactical role-playing game featuring strategic battles and deep storytelling elements - [**Throne and Liberty**](https://www.amazon.com/gp/help/customer/display.html?nodeId=T7fLNw5oAevCMtJFPj&pop-up=1), an MMORPG that offers an expansive fantasy world with dynamic gameplay and immersive storytelling - [**Unity Vivox**](https://docs.unity3d.com/Packages/com.unity.services.vivox@15.1/license/Third%20Party%20Notices.html), a communication service that enables voice and text chat functionality in multiplayer games developed with Unity -- [**Zool: Redimensioned**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/), a modern reimagining of the classic platformer featuring fast-paced gameplay and vibrant environments -- [**immersivetech**](https://immersitech.io/open-source-third-party-software/), a technology company focused on immersive experiences, providing tools and solutions for virtual and augmented reality applications +- [**Zool: Redimensioned**](https://www.mobygames.com/person/1195889/niels-lohmann/credits/): a modern reimagining of the classic platformer featuring fast-paced gameplay and vibrant environments ## Consumer Electronics -- [**Audinate**](https://www.audinate.com/legal/software-licensing/dante-av-h-open-source-licenses/), a provider of networked audio solutions specializing in Dante technology, which facilitates high-quality digital audio transport over IP networks -- [**Canon CanoScan LIDE**](https://carolburo.com/wp-content/uploads/2024/06/LiDE400_OnlineManual_Win_FR_V02.pdf), a series of flatbed scanners offering high-resolution image scanning for home and office use -- [**Canon PIXMA Printers**](https://www.mediaexpert.pl/products/files/73/7338196/Instrukcja-obslugi-CANON-Pixma-TS7450i.pdf), a line of all-in-one inkjet printers known for high-quality printing and wireless connectivity +- [**Audinate**](https://www.audinate.com/legal/software-licensing/dante-av-h-open-source-licenses/): a provider of networked audio solutions specializing in Dante technology, which facilitates high-quality digital audio transport over IP networks - [**Cisco Webex Desk Camera**](https://www.cisco.com/c/dam/en_us/about/doing_business/open_source/docs/CiscoWebexDeskCamera-23-1622100417.pdf), a video camera designed for professional-quality video conferencing and remote collaboration -- [**Philips Hue Personal Wireless Lighting**](http://2ak5ape.257.cz/), a smart lighting system for customizable and wireless home illumination +- [**Philips Hue Personal Wireless Lighting**](http://2ak5ape.257.cz/): a smart lighting system for customizable and wireless home illumination - [**Ray-Ban Meta Smart glasses**](https://www.meta.com/de/en/legal/smart-glasses/third-party-notices-android/03/), a pair of smart glasses designed for capturing photos and videos with integrated connectivity and social features -- [**Razer Synapse**](https://mysupport.razer.com/app/answers/detail/a_id/14146/~/open-source-software-for-razer-software), a unified configuration software enabling hardware customization for Razer devices - [**Siemens SINEMA Remote Connect**](https://cache.industry.siemens.com/dl/files/790/109793790/att_1054961/v2/OSS_SINEMA-RC_86.pdf), a remote connectivity solution for monitoring and managing industrial networks and devices securely - [**Sony PlayStation 4**](https://doc.dl.playstation.net/doc/ps4-oss/index.html), a gaming console developed by Sony that offers a wide range of games and multimedia entertainment features - [**Sony Virtual Webcam Driver for Remote Camera**](https://helpguide.sony.net/rc/vwd/v1/zh-cn/print.pdf), a software driver that enables the use of Sony cameras as virtual webcams for video conferencing and streaming @@ -62,7 +56,7 @@ the result of an internet search. If you know further customers of the library, - [**Apple iOS and macOS**](https://www.apple.com/macos), a family of operating systems developed by Apple, including iOS for mobile devices and macOS for desktop computers - [**Google Fuchsia**](https://fuchsia.googlesource.com/third_party/json/), an open-source operating system developed by Google, designed to be secure, updatable, and adaptable across various devices - [**SerenityOS**](https://github.com/SerenityOS/serenity), an open-source operating system that aims to provide a simple and beautiful user experience with a focus on simplicity and elegance -- [**Yocto**](http://ftp.emacinc.com/openembedded-sw/kirkstone-icop-5.15-kirkstone-6.0/archive-2024-10/pn8m-090t-ppc/licenses/nlohmann-json/), a Linux-based build system for creating custom operating systems and software distributions, tailored for embedded devices and IoT applications +- [**Yocto**](http://ftp.emacinc.com/openembedded-sw/kirkstone-icop-5.15-kirkstone-6.0/archive-2024-10/pn8m-090t-ppc/licenses/nlohmann-json/): a Linux-based build system for creating custom operating systems and software distributions, tailored for embedded devices and IoT applications ## Development Tools and IDEs @@ -72,72 +66,67 @@ the result of an internet search. If you know further customers of the library, - [**CoderPad**](https://coderpad.io), a collaborative coding platform that enables real-time code interviews and assessments for developers; the library is included in every CoderPad instance and can be accessed with a simple `#include "json.hpp"` - [**Compiler Explorer**](https://godbolt.org), a web-based tool that allows users to write, compile, and visualize the assembly output of code in various programming languages; the library is readily available and accessible with the directive `#include `. - [**GitHub CodeQL**](https://github.com/github/codeql), a code analysis tool used for identifying security vulnerabilities and bugs in software through semantic queries -- [**Hex-Rays**](https://docs.hex-rays.com/user-guide/user-interface/licenses), a reverse engineering toolset for analyzing and decompiling binaries, primarily used for security research and vulnerability analysis +- [**Hex-Rays**](https://docs.hex-rays.com/user-guide/user-interface/licenses): a reverse engineering toolset for analyzing and decompiling binaries, primarily used for security research and vulnerability analysis - [**ImHex**](https://github.com/WerWolv/ImHex), a hex editor designed for reverse engineering, providing advanced features for data analysis and manipulation - [**Intel GPA Framework**](https://intel.github.io/gpasdk-doc/src/licenses.html), a suite of cross-platform tools for capturing, analyzing, and optimizing graphics applications across different APIs -- [**Intopix**](https://www.intopix.com/software-licensing), a provider of advanced image processing and compression solutions used in software development and AV workflows -- [**MKVToolNix**](https://mkvtoolnix.download/doc/README.md), a set of tools for creating, editing, and inspecting MKV (Matroska) multimedia container files - [**Meta Yoga**](https://github.com/facebook/yoga), a layout engine that facilitates flexible and efficient user interface design across multiple platforms +- [**MKVToolNix**](https://mkvtoolnix.download/doc/README.md), a set of tools for creating, editing, and inspecting MKV (Matroska) multimedia container files - [**NVIDIA Nsight Compute**](https://docs.nvidia.com/nsight-compute/2022.2/pdf/CopyrightAndLicenses.pdf), a performance analysis tool for CUDA applications that provides detailed insights into GPU performance metrics - [**Notepad++**](https://github.com/notepad-plus-plus/notepad-plus-plus), a free source code editor that supports various programming languages - [**OpenRGB**](https://gitlab.com/CalcProgrammer1/OpenRGB), an open source RGB lighting control that doesn't depend on manufacturer software -- [**OpenTelemetry C++**](https://github.com/open-telemetry/opentelemetry-cpp), a library for collecting and exporting observability data in C++, enabling developers to implement distributed tracing and metrics in their application +- [**OpenTelemetry C++**](https://github.com/open-telemetry/opentelemetry-cpp): a library for collecting and exporting observability data in C++, enabling developers to implement distributed tracing and metrics in their application - [**Qt Creator**](https://doc.qt.io/qtcreator/qtcreator-attribution-json-nlohmann.html), an IDE for developing applications using the Qt application framework -- [**Scanbot SDK**](https://docs.scanbot.io/barcode-scanner-sdk/web/third-party-libraries/), a software development kit (SDK) that provides tools for integrating advanced document scanning and barcode scanning capabilities into applications +- [**Scanbot SDK**](https://docs.scanbot.io/barcode-scanner-sdk/web/third-party-libraries/): a software development kit (SDK) that provides tools for integrating advanced document scanning and barcode scanning capabilities into applications ## Machine Learning and AI - [**Apple Core ML Tools**](https://github.com/apple/coremltools), a set of tools for converting and configuring machine learning models for deployment in Apple's Core ML framework -- [**Avular Mobile Robotics**](https://www.avular.com/licenses/nlohmann-json-3.9.1.txt), a platform for developing and deploying mobile robotics solutions +- [**Avular Mobile Robotics**](https://www.avular.com/licenses/nlohmann-json-3.9.1.txt): a platform for developing and deploying mobile robotics solutions - [**Google gemma.cpp**](https://github.com/google/gemma.cpp), a lightweight C++ inference engine designed for running AI models from the Gemma family - [**llama.cpp**](https://github.com/ggerganov/llama.cpp), a C++ library designed for efficient inference of large language models (LLMs), enabling streamlined integration into applications - [**MLX**](https://github.com/ml-explore/mlx), an array framework for machine learning on Apple Silicon - [**Mozilla llamafile**](https://github.com/Mozilla-Ocho/llamafile), a tool designed for distributing and executing large language models (LLMs) efficiently using a single file format - [**NVIDIA ACE**](https://docs.nvidia.com/ace/latest/index.html), a suite of real-time AI solutions designed for the development of interactive avatars and digital human applications, enabling scalable and sophisticated user interactions -- [**Peer**](https://support.peer.inc/hc/en-us/articles/17261335054235-Licenses), a platform offering personalized AI assistants for interactive learning and creative collaboration -- [**stable-diffusion.cpp**](https://github.com/leejet/stable-diffusion.cpp), a C++ implementation of the Stable Diffusion image generation model -- [**TanvasTouch**](https://tanvas.co/tanvastouch-sdk-third-party-acknowledgments), a software development kit (SDK) that enables developers to create tactile experiences on touchscreens, allowing users to feel textures and physical sensations in a digital environment +- [**Peer**](https://support.peer.inc/hc/en-us/articles/17261335054235-Licenses): a platform offering personalized AI assistants for interactive learning and creative collaboration +- [**stable-diffusion.cpp**](https://github.com/leejet/stable-diffusion.cpp): a C++ implementation of the Stable Diffusion image generation model +- [**TanvasTouch**](https://tanvas.co/tanvastouch-sdk-third-party-acknowledgments): a software development kit (SDK) that enables developers to create tactile experiences on touchscreens, allowing users to feel textures and physical sensations in a digital environment - [**TensorFlow**](https://github.com/tensorflow/tensorflow), a machine learning framework that facilitates the development and training of models, supporting data serialization and efficient data exchange between components ## Scientific Research and Analysis - [**BLACK**](https://www.black-sat.org/en/stable/installation/linux.html), a bounded linear temporal logic (LTL) satisfiability checker - [**CERN Atlas Athena**](https://gitlab.cern.ch/atlas/athena/-/blob/main/Control/PerformanceMonitoring/PerfMonComps/src/PerfMonMTSvc.h), a software framework used in the ATLAS experiment at the Large Hadron Collider (LHC) for performance monitoring -- [**ICU**](https://github.com/unicode-org/icu), the International Components for Unicode, a mature library for software globalization and multilingual support -- [**KAMERA**](https://github.com/Kitware/kamera), a platform for synchronized data collection and real-time deep learning to map marine species like polar bears and seals, aiding Arctic ecosystem research -- [**KiCad**](https://gitlab.com/kicad/code/kicad/-/tree/master/thirdparty/nlohmann_json), a free and open-source software suite for electronic design automation -- [**Maple**](https://www.maplesoft.com/support/help/Maple/view.aspx?path=copyright), a symbolic and numeric computing environment for advanced mathematical modeling and analysis -- [**MeVisLab**](https://mevislabdownloads.mevis.de/docs/current/MeVis/ThirdParty/Documentation/Publish/ThirdPartyReference/index.html), a software framework for medical image processing and visualization. -- [**OpenPMD API**](https://openpmd-api.readthedocs.io/en/0.8.0-alpha/backends/json.html), a versatile programming interface for accessing and managing scientific data, designed to facilitate the efficient storage, retrieval, and sharing of simulation data across various applications and platforms -- [**ParaView**](https://github.com/Kitware/ParaView), an open-source tool for large-scale data visualization and analysis across various scientific domains -- [**QGIS**](https://gitlab.b-data.ch/qgis/qgis/-/blob/backport-57658-to-release-3_34/external/nlohmann/json.hpp), a free and open-source geographic information system (GIS) application that allows users to create, edit, visualize, and analyze geospatial data across a variety of formats -- [**VTK**](https://github.com/Kitware/VTK), a software library for 3D computer graphics, image processing, and visualization -- [**VolView**](https://github.com/Kitware/VolView), a lightweight application for interactive visualization and analysis of 3D medical imaging data. +- [**KAMERA**](https://github.com/Kitware/kamera): a platform for synchronized data collection and real-time deep learning to map marine species like polar bears and seals, aiding Arctic ecosystem research +- [**KiCad**](https://gitlab.com/kicad/code/kicad/-/tree/master/thirdparty/nlohmann_json): a free and open-source software suite for electronic design automation +- [**MeVisLab**](https://mevislabdownloads.mevis.de/docs/current/MeVis/ThirdParty/Documentation/Publish/ThirdPartyReference/index.html): a software framework for medical image processing and visualization. +- [**OpenPMD API**](https://openpmd-api.readthedocs.io/en/0.8.0-alpha/backends/json.html): a versatile programming interface for accessing and managing scientific data, designed to facilitate the efficient storage, retrieval, and sharing of simulation data across various applications and platforms +- [**ParaView**](https://github.com/Kitware/ParaView): an open-source tool for large-scale data visualization and analysis across various scientific domains +- [**QGIS**](https://gitlab.b-data.ch/qgis/qgis/-/blob/backport-57658-to-release-3_34/external/nlohmann/json.hpp): a free and open-source geographic information system (GIS) application that allows users to create, edit, visualize, and analyze geospatial data across a variety of formats +- [**VTK**](https://github.com/Kitware/VTK): a software library for 3D computer graphics, image processing, and visualization +- [**VolView**](https://github.com/Kitware/VolView): a lightweight application for interactive visualization and analysis of 3D medical imaging data. ## Business and Productivity Software - [**ArcGIS PRO**](https://www.esri.com/content/dam/esrisites/en-us/media/legal/open-source-acknowledgements/arcgis-pro-2-8-attribution-report.html), a desktop geographic information system (GIS) application developed by Esri for mapping and spatial analysis - [**Autodesk Desktop**](https://damassets.autodesk.net/content/dam/autodesk/www/Company/legal-notices-trademarks/autodesk-desktop-platform-components/internal-autodesk-components-web-page-2023.pdf), a software platform developed by Autodesk for creating and managing desktop applications and services -- [**Check Point**](https://www.checkpoint.com/about-us/copyright-and-trademarks/), a cybersecurity company specializing in threat prevention and network security solutions, offering a range of products designed to protect enterprises from cyber threats and ensure data integrity +- [**Check Point**](https://www.checkpoint.com/about-us/copyright-and-trademarks/): a cybersecurity company specializing in threat prevention and network security solutions, offering a range of products designed to protect enterprises from cyber threats and ensure data integrity - [**Microsoft Office for Mac**](https://officecdnmac.microsoft.com/pr/legal/mac/OfficeforMacAttributions.html), a suite of productivity applications developed by Microsoft for macOS, including tools for word processing, spreadsheets, and presentations - [**Microsoft Teams**](https://www.microsoft.com/microsoft-teams/), a team collaboration application offering workspace chat and video conferencing, file storage, and integration of proprietary and third-party applications and services -- [**Nexthink Infinity**](https://docs.nexthink.com/legal/services-terms/experience-open-source-software-licenses/infinity-2022.8-software-licenses), a digital employee experience management platform for monitoring and improving IT performance -- [**Sophos Connect Client**](https://docs.sophos.com/nsg/licenses/SophosConnect/SophosConnectAttribution.html), a secure VPN client from Sophos that allows remote users to connect to their corporate network, ensuring secure access to resources and data -- [**Stonebranch**](https://stonebranchdocs.atlassian.net/wiki/spaces/UA77/pages/799545647/Licenses+for+Third-Party+Libraries), a cloud-based cybersecurity solution that integrates backup, disaster recovery, and cybersecurity features to protect data and ensure business continuity for organizations -- [**Tablecruncher**](https://tablecruncher.com/), a data analysis tool that allows users to import, analyze, and visualize spreadsheet data, offering interactive features for better insights and decision-making +- [**Nexthink Infinity**](https://docs.nexthink.com/legal/services-terms/experience-open-source-software-licenses/infinity-2022.8-software-licenses): a digital employee experience management platform for monitoring and improving IT performance +- [**Sophos Connect Client**](https://docs.sophos.com/nsg/licenses/SophosConnect/SophosConnectAttribution.html): a secure VPN client from Sophos that allows remote users to connect to their corporate network, ensuring secure access to resources and data +- [**Stonebranch**](https://stonebranchdocs.atlassian.net/wiki/spaces/UA77/pages/799545647/Licenses+for+Third-Party+Libraries): a cloud-based cybersecurity solution that integrates backup, disaster recovery, and cybersecurity features to protect data and ensure business continuity for organizations +- [**Tablecruncher**](https://tablecruncher.com/): a data analysis tool that allows users to import, analyze, and visualize spreadsheet data, offering interactive features for better insights and decision-making - [**magicplan**](https://help.magicplan.app/acknowledgments), a mobile application for creating floor plans and interior designs using augmented reality ## Databases and Big Data -- [**ADIOS2**](https://code.ornl.gov/ecpcitest/adios2/-/tree/pr4285_FFSUpstream/thirdparty/nlohmann_json?ref_type=heads), a data management framework designed for high-performance input and output operations -- [**Cribl Stream**](https://docs.cribl.io/stream/third-party-current-list/), a real-time data processing platform that enables organizations to collect, route, and transform observability data, enhancing visibility and insights into their systems +- [**ADIOS2**](https://code.ornl.gov/ecpcitest/adios2/-/tree/pr4285_FFSUpstream/thirdparty/nlohmann_json?ref_type=heads): a data management framework designed for high-performance input and output operations +- [**Cribl Stream**](https://docs.cribl.io/stream/third-party-current-list/): a real-time data processing platform that enables organizations to collect, route, and transform observability data, enhancing visibility and insights into their systems - [**DB Browser for SQLite**](https://github.com/sqlitebrowser/sqlitebrowser), a visual open-source tool for creating, designing, and editing SQLite database files - [**MySQL Connector/C++**](https://docs.oracle.com/cd/E17952_01/connector-cpp-9.1-license-com-en/license-opentelemetry-cpp-com.html), a C++ library for connecting and interacting with MySQL databases - [**MySQL NDB Cluster**](https://downloads.mysql.com/docs/licenses/cluster-9.0-com-en.pdf), a distributed database system that provides high availability and scalability for MySQL databases -- [**MySQL Shell**](https://downloads.mysql.com/docs/licenses/mysql-shell-8.0-gpl-en.pdf), an advanced client and code editor for interacting with MySQL servers, supporting SQL, Python, and JavaScript - [**PrestoDB**](https://github.com/prestodb/presto), a distributed SQL query engine designed for large-scale data analytics, originally developed by Facebook - [**ROOT Data Analysis Framework**](https://root.cern/doc/v614/classnlohmann_1_1basic__json.html), an open-source data analysis framework widely used in high-energy physics and other fields for data processing and visualization -- [**WiredTiger**](https://github.com/wiredtiger/wiredtiger), a high-performance storage engine for databases, offering support for compression, concurrency, and checkpointing ## Simulation and Modeling @@ -145,33 +134,30 @@ the result of an internet search. If you know further customers of the library, - [**azul**](https://pure.tudelft.nl/ws/files/85338589/tgis.12673.pdf), a fast and efficient 3D city model viewer designed for visualizing urban environments and spatial data - [**Blender**](https://projects.blender.org/blender/blender/search?q=nlohmann), a free and open-source 3D creation suite for modeling, animation, rendering, and more - [**cpplot**](https://cpplot.readthedocs.io/en/latest/library_api/function_eigen_8h_1ac080eac0541014c5892a55e41bf785e6.html), a library for creating interactive graphs and charts in C++, which can be viewed in web browsers -- [**Foundry Nuke**](https://learn.foundry.com/nuke/content/misc/studio_third_party_libraries.html), a powerful node-based digital compositing and visual effects application used in film and television post-production -- [**GAMS**](https://www.gams.com/47/docs/THIRDPARTY.html), a high-performance mathematical modeling system for optimization and decision support -- [**Kitware SMTK**](https://github.com/Kitware/SMTK), a software toolkit for managing simulation models and workflows in scientific and engineering applications -- [**M-Star**](https://docs.mstarcfd.com/3_Licensing/thirdparty-licenses.html), a computational fluid dynamics software for simulating and analyzing fluid flow -- [**MapleSim CAD Toolbox**](https://www.maplesoft.com/support/help/MapleSim/view.aspx?path=CADToolbox/copyright), a software extension for MapleSim that integrates CAD models, allowing users to import, manipulate, and analyze 3D CAD data within the MapleSim environment for enhanced modeling and simulation - [**NVIDIA Omniverse**](https://docs.omniverse.nvidia.com/composer/latest/common/product-licenses/usd-explorer/usd-explorer-2023.2.0-licenses-manifest.html), a platform for 3D content creation and collaboration that enables real-time simulations and interactive experiences across various industries - [**Pixar Renderman**](https://rmanwiki-26.pixar.com/space/REN26/19662083/Legal+Notice), a photorealistic 3D rendering software developed by Pixar, widely used in the film industry for creating high-quality visual effects and animations - [**ROS - Robot Operating System**](http://docs.ros.org/en/noetic/api/behaviortree_cpp/html/json_8hpp_source.html), a set of software libraries and tools that assist in developing robot applications - [**UBS**](https://www.ubs.com/), a multinational financial services and banking company +- [**GAMS**](https://www.gams.com/47/docs/THIRDPARTY.html): a high-performance mathematical modeling system for optimization and decision support +- [**M-Star**](https://docs.mstarcfd.com/3_Licensing/thirdparty-licenses.html): a computational fluid dynamics software for simulating and analyzing fluid flow +- [**MapleSim CAD Toolbox**](https://www.maplesoft.com/support/help/MapleSim/view.aspx?path=CADToolbox/copyright): a software extension for MapleSim that integrates CAD models, allowing users to import, manipulate, and analyze 3D CAD data within the MapleSim environment for enhanced modeling and simulation +- [**Kitware SMTK**](https://github.com/Kitware/SMTK): a software toolkit for managing simulation models and workflows in scientific and engineering applications ## Enterprise and Cloud Applications -- [**Acronis Cyber Protect Cloud**](https://care.acronis.com/s/article/59533-Third-party-software-used-in-Acronis-Cyber-Protect-Cloud?language=en_US), an all-in-one data protection solution that combines backup, disaster recovery, and cybersecurity to safeguard business data from threats like ransomware -- [**Baereos**](https://gitlab.tiger-computing.co.uk/packages/bareos/-/blob/tiger/bullseye/third-party/CLI11/examples/json.cpp), a backup solution that provides data protection and recovery options for various environments, including physical and virtual systems +- [**Acronis Cyber Protect Cloud**](https://care.acronis.com/s/article/59533-Third-party-software-used-in-Acronis-Cyber-Protect-Cloud?language=en_US): an all-in-one data protection solution that combines backup, disaster recovery, and cybersecurity to safeguard business data from threats like ransomware +- [**Baereos**](https://gitlab.tiger-computing.co.uk/packages/bareos/-/blob/tiger/bullseye/third-party/CLI11/examples/json.cpp): a backup solution that provides data protection and recovery options for various environments, including physical and virtual systems - [**Bitdefender Home Scanner**](https://www.bitdefender.de/site/Main/view/home-scanner-open-source.html), a tool from Bitdefender that scans devices for malware and security threats, providing a safeguard against potential online dangers -- [**Citrix Provisioning**](https://docs.citrix.com/en-us/provisioning/2203-ltsr/downloads/pvs-third-party-notices-2203.pdf), a solution that streamlines the delivery of virtual desktops and applications by allowing administrators to manage and provision resources efficiently across multiple environments +- [**Citrix Provisioning**](https://docs.citrix.com/en-us/provisioning/2203-ltsr/downloads/pvs-third-party-notices-2203.pdf): a solution that streamlines the delivery of virtual desktops and applications by allowing administrators to manage and provision resources efficiently across multiple environments - [**Citrix Virtual Apps and Desktops**](https://docs.citrix.com/en-us/citrix-virtual-apps-desktops/2305/downloads/third-party-notices-apps-and-desktops.pdf), a solution from Citrix that delivers virtual apps and desktops -- [**Cyberarc**](https://docs.cyberark.com/Downloads/Legal/Privileged%20Session%20Manager%20for%20SSH%20Third-Party%20Notices.pdf), a security solution that specializes in privileged access management, enabling organizations to control and monitor access to critical systems and data, thereby enhancing overall cybersecurity posture -- [**Egnyte Desktop**](https://helpdesk.egnyte.com/hc/en-us/articles/360007071732-Third-Party-Software-Acknowledgements), a secure cloud storage solution designed for businesses, enabling file sharing, collaboration, and data management across teams while ensuring compliance and data protection -- [**Elster**](https://www.secunet.com/en/about-us/press/article/elstersecure-bietet-komfortablen-login-ohne-passwort-dank-secunet-protect4use), a digital platform developed by German tax authorities for secure and efficient electronic tax filing and management using secunet protect4use +- [**Cyberarc**](https://docs.cyberark.com/Downloads/Legal/Privileged%20Session%20Manager%20for%20SSH%20Third-Party%20Notices.pdf): a security solution that specializes in privileged access management, enabling organizations to control and monitor access to critical systems and data, thereby enhancing overall cybersecurity posture +- [**Elster**](https://www.secunet.com/en/about-us/press/article/elstersecure-bietet-komfortablen-login-ohne-passwort-dank-secunet-protect4use): a digital platform developed by German tax authorities for secure and efficient electronic tax filing and management using secunet protect4use +- [**Egnyte Desktop**](https://helpdesk.egnyte.com/hc/en-us/articles/360007071732-Third-Party-Software-Acknowledgements): a secure cloud storage solution designed for businesses, enabling file sharing, collaboration, and data management across teams while ensuring compliance and data protection - [**Ethereum Solidity**](https://github.com/ethereum/solidity), a high-level, object-oriented programming language designed for implementing smart contracts on the Ethereum platform -- [**Inciga**](https://fossies.org/linux/icinga2/third-party/nlohmann_json/json.hpp), a monitoring tool for IT infrastructure, designed to provide insights into system performance and availability through customizable dashboards and alerts -- [**Intel Accelerator Management Daemon for VMware ESXi**](https://downloadmirror.intel.com/772507/THIRD-PARTY.txt), a management tool designed for monitoring and controlling Intel hardware accelerators within VMware ESXi environments, optimizing performance and resource allocation +- [**Inciga**](https://fossies.org/linux/icinga2/third-party/nlohmann_json/json.hpp): a monitoring tool for IT infrastructure, designed to provide insights into system performance and availability through customizable dashboards and alerts +- [**Intel Accelerator Management Daemon for VMware ESXi**](https://downloadmirror.intel.com/772507/THIRD-PARTY.txt): a management tool designed for monitoring and controlling Intel hardware accelerators within VMware ESXi environments, optimizing performance and resource allocation - [**Juniper Identity Management Service**](https://www.juniper.net/documentation/us/en/software/jims/jims-guide/jims-guide.pdf) - [**Microsoft Azure IoT SDK**](https://library.e.abb.com/public/2779c5f85f30484192eb3cb3f666a201/IP%20Gateway%20Open%20License%20Declaration_9AKK108467A4095_Rev_C.pdf), a collection of tools and libraries to help developers connect, build, and deploy Internet of Things (IoT) solutions on the Azure cloud platform - [**Microsoft WinGet**](https://github.com/microsoft/winget-cli), a command-line utility included in the Windows Package Manager -- [**plexusAV**](https://www.sisme.com/media/10994/manual_plexusav-p-avn-4-form8244-c.pdf), a high-performance AV-over-IP transceiver device capable of video encoding and decoding using the IPMX standard -- [**Pointr**](https://docs-dev.pointr.tech/docs/8.x/Developer%20Portal/Open%20Source%20Licenses/), a platform for indoor positioning and navigation solutions, offering tools and SDKs for developers to create location-based applications -- [**secunet protect4use**](https://www.secunet.com/en/about-us/press/article/elstersecure-bietet-komfortablen-login-ohne-passwort-dank-secunet-protect4use), a secure, passwordless multifactor authentication solution that transforms smartphones into digital keyrings, ensuring high security for online services and digital identities -- [**Sencore MRD 7000**](https://www.foccusdigital.com/wp-content/uploads/2025/03/MRD-7000-Manual-8175V.pdf), a professional multi-channel receiver and decoder supporting UHD and HD stream decoding +- [**Pointr**](https://docs-dev.pointr.tech/docs/8.x/Developer%20Portal/Open%20Source%20Licenses/): a platform for indoor positioning and navigation solutions, offering tools and SDKs for developers to create location-based applications +- [**secunet protect4use**](https://www.secunet.com/en/about-us/press/article/elstersecure-bietet-komfortablen-login-ohne-passwort-dank-secunet-protect4use): a secure, passwordless multifactor authentication solution that transforms smartphones into digital keyrings, ensuring high security for online services and digital identities diff --git a/nlohmann_json/docs/mkdocs/docs/home/exceptions.md b/nlohmann_json/docs/mkdocs/docs/home/exceptions.md index cfa4f57a..ea43e597 100644 --- a/nlohmann_json/docs/mkdocs/docs/home/exceptions.md +++ b/nlohmann_json/docs/mkdocs/docs/home/exceptions.md @@ -520,7 +520,7 @@ The order of object iterators cannot be compared, because JSON objects are unord ### json.exception.invalid_iterator.214 -Cannot retrieve value from iterator: The iterator either refers to a null value, or it refers to a primitive type (number, boolean, or string), but does not match the iterator returned by `begin()`. +Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to `begin()`. !!! failure "Example message" diff --git a/nlohmann_json/docs/mkdocs/docs/home/faq.md b/nlohmann_json/docs/mkdocs/docs/home/faq.md index 74709bac..6a5ca396 100644 --- a/nlohmann_json/docs/mkdocs/docs/home/faq.md +++ b/nlohmann_json/docs/mkdocs/docs/home/faq.md @@ -67,7 +67,7 @@ The library supports **Unicode input** as follows: - The strings stored in the library are UTF-8 encoded. When using the default string type (`std::string`), note that its length/size functions return the number of stored bytes rather than the number of characters or glyphs. - When you store strings with different encodings in the library, calling [`dump()`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a50ec80b02d0f3f51130d4abb5d1cfdc5.html#a50ec80b02d0f3f51130d4abb5d1cfdc5) may throw an exception unless `json::error_handler_t::replace` or `json::error_handler_t::ignore` are used as error handlers. -In most cases, the parser is right to complain, because the input is not UTF-8 encoded. This is especially true for Microsoft Windows, where Latin-1 or ISO 8859-1 is often the standard encoding. +In most cases, the parser is right to complain, because the input is not UTF-8 encoded. This is especially true for Microsoft Windows where Latin-1 or ISO 8859-1 is often the standard encoding. ### Wide string handling diff --git a/nlohmann_json/docs/mkdocs/docs/home/releases.md b/nlohmann_json/docs/mkdocs/docs/home/releases.md index c7b343ca..af4f3e61 100644 --- a/nlohmann_json/docs/mkdocs/docs/home/releases.md +++ b/nlohmann_json/docs/mkdocs/docs/home/releases.md @@ -1071,7 +1071,7 @@ This release combines a lot of small fixes and improvements. The release is back - Improved the performance of the serialization by avoiding the re-creation of a locale object. - Fixed two MSVC warnings. Compiling the test suite with `/Wall` now only warns about non-inlined functions (C4710) and the deprecation of the constructor from input-stream (C4996). - Some project internals: - - The project has qualified for the [Core Infrastructure Initiative Best Practices Badge](https://bestpractices.coreinfrastructure.org/projects/289). While most requirements where already satisfied, some led to more explicit documentation of quality-ensuring procedures. For instance, static analysis is now executed with every commit on the build server. Furthermore, the [contribution guidelines document](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md) how to communicate security issues privately. + - The project has qualified for the [Core Infrastructure Initiative Best Practices Badge](https://bestpractices.coreinfrastructure.org/projects/289). While most requirements where already satisfied, some led to a more explicit documentation of quality-ensuring procedures. For instance, static analysis is now executed with every commit on the build server. Furthermore, the [contribution guidelines document](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md) how to communicate security issues privately. - The test suite has been overworked and split into several files to allow for faster compilation and analysis. The execute the test suite, simply execute `make check`. - The continuous integration with [Travis](https://travis-ci.org/nlohmann/json) was extended with Clang versions 3.6.0 to 3.8.1 and now includes 18 different compiler/OS combinations. - An 11-day run of [American fuzzy lop](http://lcamtuf.coredump.cx/afl/) checked 962 million inputs on the parser and found no issue. diff --git a/nlohmann_json/docs/mkdocs/docs/images/customers.png b/nlohmann_json/docs/mkdocs/docs/images/customers.png index 0334c4f3..acba0349 100644 Binary files a/nlohmann_json/docs/mkdocs/docs/images/customers.png and b/nlohmann_json/docs/mkdocs/docs/images/customers.png differ diff --git a/nlohmann_json/docs/mkdocs/docs/integration/bazel/BUILD b/nlohmann_json/docs/mkdocs/docs/integration/bazel/BUILD index 675a95ee..ec223f14 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/bazel/BUILD +++ b/nlohmann_json/docs/mkdocs/docs/integration/bazel/BUILD @@ -1,5 +1,5 @@ cc_binary( name = "main", srcs = ["example.cpp"], - deps = ["//nlohmann_json/single_include/nlohmann:nlohmann_json"], + deps = ["@nlohmann_json//:json"], ) diff --git a/nlohmann_json/docs/mkdocs/docs/integration/bazel/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/bazel/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/bazel/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/bazel/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/cget/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/cget/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/cget/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/cget/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/conan/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/conan/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/conan/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/conan/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/conda/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/conda/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/conda/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/conda/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/cpm/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/cpm/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/cpm/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/cpm/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/homebrew/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/homebrew/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/homebrew/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/homebrew/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/hunter/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/hunter/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/hunter/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/hunter/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/macports/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/macports/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/macports/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/macports/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/meson/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/meson/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/meson/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/meson/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/spack/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/spack/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/spack/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/spack/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/vcpkg/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/vcpkg/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/vcpkg/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/vcpkg/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/docs/integration/xmake/example.cpp b/nlohmann_json/docs/mkdocs/docs/integration/xmake/example.cpp index 1a7ac4de..5b67c11a 100644 --- a/nlohmann_json/docs/mkdocs/docs/integration/xmake/example.cpp +++ b/nlohmann_json/docs/mkdocs/docs/integration/xmake/example.cpp @@ -1,10 +1,7 @@ -#include -#include #include +#include +#include using json = nlohmann::json; -int main() -{ - std::cout << std::setw(4) << json::meta() << std::endl; -} +int main() { std::cout << std::setw(4) << json::meta() << std::endl; } diff --git a/nlohmann_json/docs/mkdocs/mkdocs.yml b/nlohmann_json/docs/mkdocs/mkdocs.yml index ad936bef..7a89219f 100644 --- a/nlohmann_json/docs/mkdocs/mkdocs.yml +++ b/nlohmann_json/docs/mkdocs/mkdocs.yml @@ -16,14 +16,14 @@ theme: name: material language: en palette: - - media: "(prefers-color-scheme: light)" + - media: '(prefers-color-scheme: light)' scheme: default primary: indigo accent: indigo toggle: icon: material/brightness-7 name: Switch to dark mode - - media: "(prefers-color-scheme: dark)" + - media: '(prefers-color-scheme: dark)' scheme: slate primary: indigo accent: indigo @@ -67,7 +67,6 @@ nav: - features/binary_formats/ubjson.md - features/binary_values.md - features/comments.md - - features/trailing_commas.md - Element Access: - features/element_access/index.md - features/element_access/unchecked_access.md @@ -77,7 +76,7 @@ nav: - features/json_pointer.md - features/json_patch.md - features/merge_patch.md - - "nlohmann Namespace": features/namespace.md + - 'nlohmann Namespace': features/namespace.md - features/object_order.md - Parsing: - features/parsing/index.md @@ -99,197 +98,197 @@ nav: - integration/pkg-config.md - API Documentation: - basic_json: - - "Overview": api/basic_json/index.md - - "(Constructor)": api/basic_json/basic_json.md - - "(Destructor)": api/basic_json/~basic_json.md - - "accept": api/basic_json/accept.md - - "array": api/basic_json/array.md - - "array_t": api/basic_json/array_t.md - - "at": api/basic_json/at.md - - "back": api/basic_json/back.md - - "begin": api/basic_json/begin.md - - "binary": api/basic_json/binary.md - - "binary_t": api/basic_json/binary_t.md - - "boolean_t": api/basic_json/boolean_t.md - - "cbegin": api/basic_json/cbegin.md - - "cbor_tag_handler_t": api/basic_json/cbor_tag_handler_t.md - - "cend": api/basic_json/cend.md - - "clear": api/basic_json/clear.md - - "contains": api/basic_json/contains.md - - "count": api/basic_json/count.md - - "crbegin": api/basic_json/crbegin.md - - "crend": api/basic_json/crend.md - - "default_object_comparator_t": api/basic_json/default_object_comparator_t.md - - "diff": api/basic_json/diff.md - - "dump": api/basic_json/dump.md - - "emplace": api/basic_json/emplace.md - - "emplace_back": api/basic_json/emplace_back.md - - "empty": api/basic_json/empty.md - - "end": api/basic_json/end.md - - "end_pos": api/basic_json/end_pos.md - - "erase": api/basic_json/erase.md - - "error_handler_t": api/basic_json/error_handler_t.md - - "exception": api/basic_json/exception.md - - "find": api/basic_json/find.md - - "flatten": api/basic_json/flatten.md - - "from_bjdata": api/basic_json/from_bjdata.md - - "from_bson": api/basic_json/from_bson.md - - "from_cbor": api/basic_json/from_cbor.md - - "from_msgpack": api/basic_json/from_msgpack.md - - "from_ubjson": api/basic_json/from_ubjson.md - - "front": api/basic_json/front.md - - "get": api/basic_json/get.md - - "get_allocator": api/basic_json/get_allocator.md - - "get_binary": api/basic_json/get_binary.md - - "get_ptr": api/basic_json/get_ptr.md - - "get_ref": api/basic_json/get_ref.md - - "get_to": api/basic_json/get_to.md - - "std::hash<basic_json>": api/basic_json/std_hash.md - - "input_format_t": api/basic_json/input_format_t.md - - "insert": api/basic_json/insert.md - - "invalid_iterator": api/basic_json/invalid_iterator.md - - "is_array": api/basic_json/is_array.md - - "is_binary": api/basic_json/is_binary.md - - "is_boolean": api/basic_json/is_boolean.md - - "is_discarded": api/basic_json/is_discarded.md - - "is_null": api/basic_json/is_null.md - - "is_number": api/basic_json/is_number.md - - "is_number_float": api/basic_json/is_number_float.md - - "is_number_integer": api/basic_json/is_number_integer.md - - "is_number_unsigned": api/basic_json/is_number_unsigned.md - - "is_object": api/basic_json/is_object.md - - "is_primitive": api/basic_json/is_primitive.md - - "is_string": api/basic_json/is_string.md - - "is_structured": api/basic_json/is_structured.md - - "items": api/basic_json/items.md - - "json_base_class_t": api/basic_json/json_base_class_t.md - - "json_serializer": api/basic_json/json_serializer.md - - "max_size": api/basic_json/max_size.md - - "meta": api/basic_json/meta.md - - "merge_patch": api/basic_json/merge_patch.md - - "number_float_t": api/basic_json/number_float_t.md - - "number_integer_t": api/basic_json/number_integer_t.md - - "number_unsigned_t": api/basic_json/number_unsigned_t.md - - "object": api/basic_json/object.md - - "object_comparator_t": api/basic_json/object_comparator_t.md - - "object_t": api/basic_json/object_t.md - - "operator ValueType": api/basic_json/operator_ValueType.md - - "operator value_t": api/basic_json/operator_value_t.md - - "operator[]": api/basic_json/operator[].md - - "operator=": api/basic_json/operator=.md - - "operator+=": api/basic_json/operator+=.md - - "operator==": api/basic_json/operator_eq.md - - "operator!=": api/basic_json/operator_ne.md - - "operator<": api/basic_json/operator_lt.md - - "operator>": api/basic_json/operator_gt.md - - "operator<=": api/basic_json/operator_le.md - - "operator>=": api/basic_json/operator_ge.md - - "operator<=>": api/basic_json/operator_spaceship.md - - "out_of_range": api/basic_json/out_of_range.md - - "other_error": api/basic_json/other_error.md - - "parse": api/basic_json/parse.md - - "parse_error": api/basic_json/parse_error.md - - "parse_event_t": api/basic_json/parse_event_t.md - - "parser_callback_t": api/basic_json/parser_callback_t.md - - "patch": api/basic_json/patch.md - - "patch_inplace": api/basic_json/patch_inplace.md - - "push_back": api/basic_json/push_back.md - - "rbegin": api/basic_json/rbegin.md - - "rend": api/basic_json/rend.md - - "sax_parse": api/basic_json/sax_parse.md - - "size": api/basic_json/size.md - - "start_pos": api/basic_json/start_pos.md - - "string_t": api/basic_json/string_t.md - - "swap": api/basic_json/swap.md - - "std::swap<basic_json>": api/basic_json/std_swap.md - - "to_bjdata": api/basic_json/to_bjdata.md - - "to_bson": api/basic_json/to_bson.md - - "to_cbor": api/basic_json/to_cbor.md - - "to_msgpack": api/basic_json/to_msgpack.md - - "to_string": api/basic_json/to_string.md - - "to_ubjson": api/basic_json/to_ubjson.md - - "type": api/basic_json/type.md - - "type_error": api/basic_json/type_error.md - - "type_name": api/basic_json/type_name.md - - "unflatten": api/basic_json/unflatten.md - - "update": api/basic_json/update.md - - "value": api/basic_json/value.md - - "value_t": api/basic_json/value_t.md + - 'Overview': api/basic_json/index.md + - '(Constructor)': api/basic_json/basic_json.md + - '(Destructor)': api/basic_json/~basic_json.md + - 'accept': api/basic_json/accept.md + - 'array': api/basic_json/array.md + - 'array_t': api/basic_json/array_t.md + - 'at': api/basic_json/at.md + - 'back': api/basic_json/back.md + - 'begin': api/basic_json/begin.md + - 'binary': api/basic_json/binary.md + - 'binary_t': api/basic_json/binary_t.md + - 'boolean_t': api/basic_json/boolean_t.md + - 'cbegin': api/basic_json/cbegin.md + - 'cbor_tag_handler_t': api/basic_json/cbor_tag_handler_t.md + - 'cend': api/basic_json/cend.md + - 'clear': api/basic_json/clear.md + - 'contains': api/basic_json/contains.md + - 'count': api/basic_json/count.md + - 'crbegin': api/basic_json/crbegin.md + - 'crend': api/basic_json/crend.md + - 'default_object_comparator_t': api/basic_json/default_object_comparator_t.md + - 'diff': api/basic_json/diff.md + - 'dump': api/basic_json/dump.md + - 'emplace': api/basic_json/emplace.md + - 'emplace_back': api/basic_json/emplace_back.md + - 'empty': api/basic_json/empty.md + - 'end': api/basic_json/end.md + - 'end_pos': api/basic_json/end_pos.md + - 'erase': api/basic_json/erase.md + - 'error_handler_t': api/basic_json/error_handler_t.md + - 'exception': api/basic_json/exception.md + - 'find': api/basic_json/find.md + - 'flatten': api/basic_json/flatten.md + - 'from_bjdata': api/basic_json/from_bjdata.md + - 'from_bson': api/basic_json/from_bson.md + - 'from_cbor': api/basic_json/from_cbor.md + - 'from_msgpack': api/basic_json/from_msgpack.md + - 'from_ubjson': api/basic_json/from_ubjson.md + - 'front': api/basic_json/front.md + - 'get': api/basic_json/get.md + - 'get_allocator': api/basic_json/get_allocator.md + - 'get_binary': api/basic_json/get_binary.md + - 'get_ptr': api/basic_json/get_ptr.md + - 'get_ref': api/basic_json/get_ref.md + - 'get_to': api/basic_json/get_to.md + - 'std::hash<basic_json>': api/basic_json/std_hash.md + - 'input_format_t': api/basic_json/input_format_t.md + - 'insert': api/basic_json/insert.md + - 'invalid_iterator': api/basic_json/invalid_iterator.md + - 'is_array': api/basic_json/is_array.md + - 'is_binary': api/basic_json/is_binary.md + - 'is_boolean': api/basic_json/is_boolean.md + - 'is_discarded': api/basic_json/is_discarded.md + - 'is_null': api/basic_json/is_null.md + - 'is_number': api/basic_json/is_number.md + - 'is_number_float': api/basic_json/is_number_float.md + - 'is_number_integer': api/basic_json/is_number_integer.md + - 'is_number_unsigned': api/basic_json/is_number_unsigned.md + - 'is_object': api/basic_json/is_object.md + - 'is_primitive': api/basic_json/is_primitive.md + - 'is_string': api/basic_json/is_string.md + - 'is_structured': api/basic_json/is_structured.md + - 'items': api/basic_json/items.md + - 'json_base_class_t': api/basic_json/json_base_class_t.md + - 'json_serializer': api/basic_json/json_serializer.md + - 'max_size': api/basic_json/max_size.md + - 'meta': api/basic_json/meta.md + - 'merge_patch': api/basic_json/merge_patch.md + - 'number_float_t': api/basic_json/number_float_t.md + - 'number_integer_t': api/basic_json/number_integer_t.md + - 'number_unsigned_t': api/basic_json/number_unsigned_t.md + - 'object': api/basic_json/object.md + - 'object_comparator_t': api/basic_json/object_comparator_t.md + - 'object_t': api/basic_json/object_t.md + - 'operator ValueType': api/basic_json/operator_ValueType.md + - 'operator value_t': api/basic_json/operator_value_t.md + - 'operator[]': api/basic_json/operator[].md + - 'operator=': api/basic_json/operator=.md + - 'operator+=': api/basic_json/operator+=.md + - 'operator==': api/basic_json/operator_eq.md + - 'operator!=': api/basic_json/operator_ne.md + - 'operator<': api/basic_json/operator_lt.md + - 'operator>': api/basic_json/operator_gt.md + - 'operator<=': api/basic_json/operator_le.md + - 'operator>=': api/basic_json/operator_ge.md + - 'operator<=>': api/basic_json/operator_spaceship.md + - 'out_of_range': api/basic_json/out_of_range.md + - 'other_error': api/basic_json/other_error.md + - 'parse': api/basic_json/parse.md + - 'parse_error': api/basic_json/parse_error.md + - 'parse_event_t': api/basic_json/parse_event_t.md + - 'parser_callback_t': api/basic_json/parser_callback_t.md + - 'patch': api/basic_json/patch.md + - 'patch_inplace': api/basic_json/patch_inplace.md + - 'push_back': api/basic_json/push_back.md + - 'rbegin': api/basic_json/rbegin.md + - 'rend': api/basic_json/rend.md + - 'sax_parse': api/basic_json/sax_parse.md + - 'size': api/basic_json/size.md + - 'start_pos': api/basic_json/start_pos.md + - 'string_t': api/basic_json/string_t.md + - 'swap': api/basic_json/swap.md + - 'std::swap<basic_json>': api/basic_json/std_swap.md + - 'to_bjdata': api/basic_json/to_bjdata.md + - 'to_bson': api/basic_json/to_bson.md + - 'to_cbor': api/basic_json/to_cbor.md + - 'to_msgpack': api/basic_json/to_msgpack.md + - 'to_string': api/basic_json/to_string.md + - 'to_ubjson': api/basic_json/to_ubjson.md + - 'type': api/basic_json/type.md + - 'type_error': api/basic_json/type_error.md + - 'type_name': api/basic_json/type_name.md + - 'unflatten': api/basic_json/unflatten.md + - 'update': api/basic_json/update.md + - 'value': api/basic_json/value.md + - 'value_t': api/basic_json/value_t.md - byte_container_with_subtype: - - "Overview": api/byte_container_with_subtype/index.md - - "(constructor)": api/byte_container_with_subtype/byte_container_with_subtype.md - - "clear_subtype": api/byte_container_with_subtype/clear_subtype.md - - "has_subtype": api/byte_container_with_subtype/has_subtype.md - - "set_subtype": api/byte_container_with_subtype/set_subtype.md - - "subtype": api/byte_container_with_subtype/subtype.md + - 'Overview': api/byte_container_with_subtype/index.md + - '(constructor)': api/byte_container_with_subtype/byte_container_with_subtype.md + - 'clear_subtype': api/byte_container_with_subtype/clear_subtype.md + - 'has_subtype': api/byte_container_with_subtype/has_subtype.md + - 'set_subtype': api/byte_container_with_subtype/set_subtype.md + - 'subtype': api/byte_container_with_subtype/subtype.md - adl_serializer: - - "Overview": api/adl_serializer/index.md - - "from_json": api/adl_serializer/from_json.md - - "to_json": api/adl_serializer/to_json.md - - "json": api/json.md + - 'Overview': api/adl_serializer/index.md + - 'from_json': api/adl_serializer/from_json.md + - 'to_json': api/adl_serializer/to_json.md + - 'json': api/json.md - json_pointer: - - "Overview": api/json_pointer/index.md - - "(Constructor)": api/json_pointer/json_pointer.md - - "back": api/json_pointer/back.md - - "empty": api/json_pointer/empty.md - - "operator string_t": api/json_pointer/operator_string_t.md - - "operator==": api/json_pointer/operator_eq.md - - "operator!=": api/json_pointer/operator_ne.md - - "operator/": api/json_pointer/operator_slash.md - - "operator/=": api/json_pointer/operator_slasheq.md - - "parent_pointer": api/json_pointer/parent_pointer.md - - "pop_back": api/json_pointer/pop_back.md - - "push_back": api/json_pointer/push_back.md - - "string_t": api/json_pointer/string_t.md - - "to_string": api/json_pointer/to_string.md + - 'Overview': api/json_pointer/index.md + - '(Constructor)': api/json_pointer/json_pointer.md + - 'back': api/json_pointer/back.md + - 'empty': api/json_pointer/empty.md + - 'operator string_t': api/json_pointer/operator_string_t.md + - 'operator==': api/json_pointer/operator_eq.md + - 'operator!=': api/json_pointer/operator_ne.md + - 'operator/': api/json_pointer/operator_slash.md + - 'operator/=': api/json_pointer/operator_slasheq.md + - 'parent_pointer': api/json_pointer/parent_pointer.md + - 'pop_back': api/json_pointer/pop_back.md + - 'push_back': api/json_pointer/push_back.md + - 'string_t': api/json_pointer/string_t.md + - 'to_string': api/json_pointer/to_string.md - json_sax: - - "Overview": api/json_sax/index.md - - "binary": api/json_sax/binary.md - - "boolean": api/json_sax/boolean.md - - "end_array": api/json_sax/end_array.md - - "end_object": api/json_sax/end_object.md - - "key": api/json_sax/key.md - - "null": api/json_sax/null.md - - "number_float": api/json_sax/number_float.md - - "number_integer": api/json_sax/number_integer.md - - "number_unsigned": api/json_sax/number_unsigned.md - - "parse_error": api/json_sax/parse_error.md - - "start_array": api/json_sax/start_array.md - - "start_object": api/json_sax/start_object.md - - "string": api/json_sax/string.md - - "operator<<(basic_json), operator<<(json_pointer)": api/operator_ltlt.md - - "operator>>(basic_json)": api/operator_gtgt.md + - 'Overview': api/json_sax/index.md + - 'binary': api/json_sax/binary.md + - 'boolean': api/json_sax/boolean.md + - 'end_array': api/json_sax/end_array.md + - 'end_object': api/json_sax/end_object.md + - 'key': api/json_sax/key.md + - 'null': api/json_sax/null.md + - 'number_float': api/json_sax/number_float.md + - 'number_integer': api/json_sax/number_integer.md + - 'number_unsigned': api/json_sax/number_unsigned.md + - 'parse_error': api/json_sax/parse_error.md + - 'start_array': api/json_sax/start_array.md + - 'start_object': api/json_sax/start_object.md + - 'string': api/json_sax/string.md + - 'operator<<(basic_json), operator<<(json_pointer)': api/operator_ltlt.md + - 'operator>>(basic_json)': api/operator_gtgt.md - 'operator""_json': api/operator_literal_json.md - 'operator""_json_pointer': api/operator_literal_json_pointer.md - - "ordered_json": api/ordered_json.md - - "ordered_map": api/ordered_map.md + - 'ordered_json': api/ordered_json.md + - 'ordered_map': api/ordered_map.md - macros: - - "Overview": api/macros/index.md - - "JSON_ASSERT": api/macros/json_assert.md - - "JSON_CATCH_USER, JSON_THROW_USER, JSON_TRY_USER": api/macros/json_throw_user.md - - "JSON_DIAGNOSTICS": api/macros/json_diagnostics.md - - "JSON_DIAGNOSTIC_POSITIONS": api/macros/json_diagnostic_positions.md - - "JSON_DISABLE_ENUM_SERIALIZATION": api/macros/json_disable_enum_serialization.md - - "JSON_HAS_CPP_11, JSON_HAS_CPP_14, JSON_HAS_CPP_17, JSON_HAS_CPP_20": api/macros/json_has_cpp_11.md - - "JSON_HAS_EXPERIMENTAL_FILESYSTEM, JSON_HAS_FILESYSTEM": api/macros/json_has_filesystem.md - - "JSON_HAS_RANGES": api/macros/json_has_ranges.md - - "JSON_HAS_STATIC_RTTI": api/macros/json_has_static_rtti.md - - "JSON_HAS_THREE_WAY_COMPARISON": api/macros/json_has_three_way_comparison.md - - "JSON_NOEXCEPTION": api/macros/json_noexception.md - - "JSON_NO_IO": api/macros/json_no_io.md - - "JSON_SKIP_LIBRARY_VERSION_CHECK": api/macros/json_skip_library_version_check.md - - "JSON_SKIP_UNSUPPORTED_COMPILER_CHECK": api/macros/json_skip_unsupported_compiler_check.md - - "JSON_USE_GLOBAL_UDLS": api/macros/json_use_global_udls.md - - "JSON_USE_IMPLICIT_CONVERSIONS": api/macros/json_use_implicit_conversions.md - - "JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON": api/macros/json_use_legacy_discarded_value_comparison.md - - "NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE": api/macros/nlohmann_define_derived_type.md - - "NLOHMANN_DEFINE_TYPE_INTRUSIVE, NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE": api/macros/nlohmann_define_type_intrusive.md - - "NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE, NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE": api/macros/nlohmann_define_type_non_intrusive.md - - "NLOHMANN_JSON_NAMESPACE": api/macros/nlohmann_json_namespace.md - - "NLOHMANN_JSON_NAMESPACE_BEGIN, NLOHMANN_JSON_NAMESPACE_END": api/macros/nlohmann_json_namespace_begin.md - - "NLOHMANN_JSON_NAMESPACE_NO_VERSION": api/macros/nlohmann_json_namespace_no_version.md - - "NLOHMANN_JSON_SERIALIZE_ENUM": api/macros/nlohmann_json_serialize_enum.md - - "NLOHMANN_JSON_VERSION_MAJOR, NLOHMANN_JSON_VERSION_MINOR, NLOHMANN_JSON_VERSION_PATCH": api/macros/nlohmann_json_version_major.md + - 'Overview': api/macros/index.md + - 'JSON_ASSERT': api/macros/json_assert.md + - 'JSON_CATCH_USER, JSON_THROW_USER, JSON_TRY_USER': api/macros/json_throw_user.md + - 'JSON_DIAGNOSTICS': api/macros/json_diagnostics.md + - 'JSON_DIAGNOSTIC_POSITIONS': api/macros/json_diagnostic_positions.md + - 'JSON_DISABLE_ENUM_SERIALIZATION': api/macros/json_disable_enum_serialization.md + - 'JSON_HAS_CPP_11, JSON_HAS_CPP_14, JSON_HAS_CPP_17, JSON_HAS_CPP_20': api/macros/json_has_cpp_11.md + - 'JSON_HAS_EXPERIMENTAL_FILESYSTEM, JSON_HAS_FILESYSTEM': api/macros/json_has_filesystem.md + - 'JSON_HAS_RANGES': api/macros/json_has_ranges.md + - 'JSON_HAS_STATIC_RTTI': api/macros/json_has_static_rtti.md + - 'JSON_HAS_THREE_WAY_COMPARISON': api/macros/json_has_three_way_comparison.md + - 'JSON_NOEXCEPTION': api/macros/json_noexception.md + - 'JSON_NO_IO': api/macros/json_no_io.md + - 'JSON_SKIP_LIBRARY_VERSION_CHECK': api/macros/json_skip_library_version_check.md + - 'JSON_SKIP_UNSUPPORTED_COMPILER_CHECK': api/macros/json_skip_unsupported_compiler_check.md + - 'JSON_USE_GLOBAL_UDLS': api/macros/json_use_global_udls.md + - 'JSON_USE_IMPLICIT_CONVERSIONS': api/macros/json_use_implicit_conversions.md + - 'JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON': api/macros/json_use_legacy_discarded_value_comparison.md + - 'NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE': api/macros/nlohmann_define_derived_type.md + - 'NLOHMANN_DEFINE_TYPE_INTRUSIVE, NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE': api/macros/nlohmann_define_type_intrusive.md + - 'NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE, NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE': api/macros/nlohmann_define_type_non_intrusive.md + - 'NLOHMANN_JSON_NAMESPACE': api/macros/nlohmann_json_namespace.md + - 'NLOHMANN_JSON_NAMESPACE_BEGIN, NLOHMANN_JSON_NAMESPACE_END': api/macros/nlohmann_json_namespace_begin.md + - 'NLOHMANN_JSON_NAMESPACE_NO_VERSION': api/macros/nlohmann_json_namespace_no_version.md + - 'NLOHMANN_JSON_SERIALIZE_ENUM': api/macros/nlohmann_json_serialize_enum.md + - 'NLOHMANN_JSON_VERSION_MAJOR, NLOHMANN_JSON_VERSION_MINOR, NLOHMANN_JSON_VERSION_PATCH': api/macros/nlohmann_json_version_major.md - Community: - community/index.md - "Code of Conduct": community/code_of_conduct.md @@ -347,7 +346,7 @@ markdown_extensions: - pymdownx.snippets: base_path: docs check_paths: true - restrict_base_path: false # needed to allow including files from the .github folder + restrict_base_path: false # needed to allow including files from the .github folder auto_append: - ../includes/glossary.md @@ -360,12 +359,12 @@ plugins: - git-revision-date-localized - redirects: redirect_maps: - "api/basic_json/operator_gtgt.md": api/operator_gtgt.md - "api/basic_json/operator_ltlt.md": api/operator_ltlt.md - "api/basic_json/operator_literal_json.md": api/operator_literal_json.md - "api/basic_json/operator_literal_json_pointer.md": api/operator_literal_json_pointer.md - "api/json_pointer/operator_string.md": api/json_pointer/operator_string_t.md - "home/code_of_conduct.md": community/code_of_conduct.md + 'api/basic_json/operator_gtgt.md': api/operator_gtgt.md + 'api/basic_json/operator_ltlt.md': api/operator_ltlt.md + 'api/basic_json/operator_literal_json.md': api/operator_literal_json.md + 'api/basic_json/operator_literal_json_pointer.md': api/operator_literal_json_pointer.md + 'api/json_pointer/operator_string.md': api/json_pointer/operator_string_t.md + 'home/code_of_conduct.md': community/code_of_conduct.md - htmlproofer: # see https://github.com/manuzhang/mkdocs-htmlproofer-plugin enabled: !ENV [ENABLED_HTMLPROOFER, False] ignore_urls: diff --git a/nlohmann_json/docs/mkdocs/requirements.txt b/nlohmann_json/docs/mkdocs/requirements.txt index 8d03eb59..4e23e1ca 100644 --- a/nlohmann_json/docs/mkdocs/requirements.txt +++ b/nlohmann_json/docs/mkdocs/requirements.txt @@ -1,8 +1,8 @@ wheel==0.45.1 mkdocs==1.6.1 # documentation framework -mkdocs-git-revision-date-localized-plugin==1.4.7 # plugin "git-revision-date-localized" -mkdocs-material==9.6.14 # theme for mkdocs +mkdocs-git-revision-date-localized-plugin==1.4.5 # plugin "git-revision-date-localized" +mkdocs-material==9.6.11 # theme for mkdocs mkdocs-material-extensions==1.3.1 # extensions mkdocs-minify-plugin==0.8.0 # plugin "minify" mkdocs-redirects==1.2.2 # plugin "redirects" diff --git a/nlohmann_json/docs/mkdocs/scripts/check_structure.py b/nlohmann_json/docs/mkdocs/scripts/check_structure.py old mode 100644 new mode 100755 diff --git a/nlohmann_json/include/nlohmann/detail/conversions/from_json.hpp b/nlohmann_json/include/nlohmann/detail/conversions/from_json.hpp index ebd4d393..88569af1 100644 --- a/nlohmann_json/include/nlohmann/detail/conversions/from_json.hpp +++ b/nlohmann_json/include/nlohmann/detail/conversions/from_json.hpp @@ -8,17 +8,20 @@ #pragma once -#include // transform -#include // array +#include // transform +#include // array #include // forward_list -#include // inserter, front_inserter, end -#include // map +#include // inserter, front_inserter, end +#include // map +#ifdef JSON_HAS_CPP_17 +#include // optional +#endif #include // string -#include // tuple, make_tuple +#include // tuple, make_tuple #include // is_arithmetic, is_same, is_enum, underlying_type, is_convertible #include // unordered_map -#include // pair, declval -#include // valarray +#include // pair, declval +#include // valarray #include #include @@ -29,543 +32,555 @@ #include #include -// include after macro_scope.hpp -#ifdef JSON_HAS_CPP_17 - #include // optional -#endif - -#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM - #include // u8string_view -#endif - NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ +namespace detail { -template -inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_null())) - { - JSON_THROW(type_error::create(302, concat("type must be null, but is ", j.type_name()), &j)); - } - n = nullptr; +template +inline void from_json(const BasicJsonType &j, typename std::nullptr_t &n) { + if (JSON_HEDLEY_UNLIKELY(!j.is_null())) { + JSON_THROW(type_error::create( + 302, concat("type must be null, but is ", j.type_name()), &j)); + } + n = nullptr; } #ifdef JSON_HAS_CPP_17 -template -void from_json(const BasicJsonType& j, std::optional& opt) -{ - if (j.is_null()) - { - opt = std::nullopt; - } - else - { - opt.emplace(j.template get()); - } +#ifndef JSON_USE_IMPLICIT_CONVERSIONS +template +void from_json(const BasicJsonType &j, std::optional &opt) { + if (j.is_null()) { + opt = std::nullopt; + } else { + opt.emplace(j.template get()); + } } + +#endif // JSON_USE_IMPLICIT_CONVERSIONS #endif // JSON_HAS_CPP_17 // overloads for basic_json template parameters -template < typename BasicJsonType, typename ArithmeticType, - enable_if_t < std::is_arithmetic::value&& - !std::is_same::value, - int > = 0 > -void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) -{ - switch (static_cast(j)) - { - case value_t::number_unsigned: - { - val = static_cast(*j.template get_ptr()); - break; - } - case value_t::number_integer: - { - val = static_cast(*j.template get_ptr()); - break; - } - case value_t::number_float: - { - val = static_cast(*j.template get_ptr()); - break; - } - - case value_t::null: - case value_t::object: - case value_t::array: - case value_t::string: - case value_t::boolean: - case value_t::binary: - case value_t::discarded: - default: - JSON_THROW(type_error::create(302, concat("type must be number, but is ", j.type_name()), &j)); - } -} - -template -inline void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_boolean())) - { - JSON_THROW(type_error::create(302, concat("type must be boolean, but is ", j.type_name()), &j)); - } - b = *j.template get_ptr(); -} - -template -inline void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_string())) - { - JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j)); - } - s = *j.template get_ptr(); +template < + typename BasicJsonType, typename ArithmeticType, + enable_if_t::value && + !std::is_same::value, + int> = 0> +void get_arithmetic_value(const BasicJsonType &j, ArithmeticType &val) { + switch (static_cast(j)) { + case value_t::number_unsigned: { + val = static_cast( + *j.template get_ptr< + const typename BasicJsonType::number_unsigned_t *>()); + break; + } + case value_t::number_integer: { + val = static_cast( + *j.template get_ptr< + const typename BasicJsonType::number_integer_t *>()); + break; + } + case value_t::number_float: { + val = static_cast( + *j.template get_ptr()); + break; + } + + case value_t::null: + case value_t::object: + case value_t::array: + case value_t::string: + case value_t::boolean: + case value_t::binary: + case value_t::discarded: + default: + JSON_THROW(type_error::create( + 302, concat("type must be number, but is ", j.type_name()), &j)); + } +} + +template +inline void from_json(const BasicJsonType &j, + typename BasicJsonType::boolean_t &b) { + if (JSON_HEDLEY_UNLIKELY(!j.is_boolean())) { + JSON_THROW(type_error::create( + 302, concat("type must be boolean, but is ", j.type_name()), &j)); + } + b = *j.template get_ptr(); +} + +template +inline void from_json(const BasicJsonType &j, + typename BasicJsonType::string_t &s) { + if (JSON_HEDLEY_UNLIKELY(!j.is_string())) { + JSON_THROW(type_error::create( + 302, concat("type must be string, but is ", j.type_name()), &j)); + } + s = *j.template get_ptr(); } template < typename BasicJsonType, typename StringType, - enable_if_t < - std::is_assignable::value - && is_detected_exact::value - && !std::is_same::value - && !is_json_ref::value, int > = 0 > -inline void from_json(const BasicJsonType& j, StringType& s) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_string())) - { - JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j)); - } + enable_if_t< + std::is_assignable::value && + is_detected_exact::value && + !std::is_same::value && + !is_json_ref::value, + int> = 0> +inline void from_json(const BasicJsonType &j, StringType &s) { + if (JSON_HEDLEY_UNLIKELY(!j.is_string())) { + JSON_THROW(type_error::create( + 302, concat("type must be string, but is ", j.type_name()), &j)); + } - s = *j.template get_ptr(); + s = *j.template get_ptr(); } -template -inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val) -{ - get_arithmetic_value(j, val); +template +inline void from_json(const BasicJsonType &j, + typename BasicJsonType::number_float_t &val) { + get_arithmetic_value(j, val); } -template -inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_unsigned_t& val) -{ - get_arithmetic_value(j, val); +template +inline void from_json(const BasicJsonType &j, + typename BasicJsonType::number_unsigned_t &val) { + get_arithmetic_value(j, val); } -template -inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& val) -{ - get_arithmetic_value(j, val); +template +inline void from_json(const BasicJsonType &j, + typename BasicJsonType::number_integer_t &val) { + get_arithmetic_value(j, val); } #if !JSON_DISABLE_ENUM_SERIALIZATION -template::value, int> = 0> -inline void from_json(const BasicJsonType& j, EnumType& e) -{ - typename std::underlying_type::type val; - get_arithmetic_value(j, val); - e = static_cast(val); +template ::value, int> = 0> +inline void from_json(const BasicJsonType &j, EnumType &e) { + typename std::underlying_type::type val; + get_arithmetic_value(j, val); + e = static_cast(val); } -#endif // JSON_DISABLE_ENUM_SERIALIZATION +#endif // JSON_DISABLE_ENUM_SERIALIZATION // forward_list doesn't have an insert method -template::value, int> = 0> -inline void from_json(const BasicJsonType& j, std::forward_list& l) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_array())) - { - JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); - } - l.clear(); - std::transform(j.rbegin(), j.rend(), - std::front_inserter(l), [](const BasicJsonType & i) - { - return i.template get(); - }); +template ::value, int> = 0> +inline void from_json(const BasicJsonType &j, + std::forward_list &l) { + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { + JSON_THROW(type_error::create( + 302, concat("type must be array, but is ", j.type_name()), &j)); + } + l.clear(); + std::transform(j.rbegin(), j.rend(), std::front_inserter(l), + [](const BasicJsonType &i) { return i.template get(); }); } // valarray doesn't have an insert method -template::value, int> = 0> -inline void from_json(const BasicJsonType& j, std::valarray& l) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_array())) - { - JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); +template ::value, int> = 0> +inline void from_json(const BasicJsonType &j, std::valarray &l) { + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { + JSON_THROW(type_error::create( + 302, concat("type must be array, but is ", j.type_name()), &j)); + } + l.resize(j.size()); + std::transform( + j.begin(), j.end(), std::begin(l), + [](const BasicJsonType &elem) { return elem.template get(); }); +} + +template +auto from_json( + const BasicJsonType &j, + T (&arr) + [N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + -> decltype(j.template get(), void()) { + for (std::size_t i = 0; i < N; ++i) { + arr[i] = j.at(i).template get(); + } +} + +template +auto from_json( + const BasicJsonType &j, + T (&arr) + [N1] + [N2]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + -> decltype(j.template get(), void()) { + for (std::size_t i1 = 0; i1 < N1; ++i1) { + for (std::size_t i2 = 0; i2 < N2; ++i2) { + arr[i1][i2] = j.at(i1).at(i2).template get(); } - l.resize(j.size()); - std::transform(j.begin(), j.end(), std::begin(l), - [](const BasicJsonType & elem) - { - return elem.template get(); - }); -} - -template -auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) --> decltype(j.template get(), void()) -{ - for (std::size_t i = 0; i < N; ++i) - { - arr[i] = j.at(i).template get(); + } +} + +template +auto from_json( + const BasicJsonType &j, + T (&arr) + [N1][N2] + [N3]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + -> decltype(j.template get(), void()) { + for (std::size_t i1 = 0; i1 < N1; ++i1) { + for (std::size_t i2 = 0; i2 < N2; ++i2) { + for (std::size_t i3 = 0; i3 < N3; ++i3) { + arr[i1][i2][i3] = j.at(i1).at(i2).at(i3).template get(); + } } -} - -template -auto from_json(const BasicJsonType& j, T (&arr)[N1][N2]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) --> decltype(j.template get(), void()) -{ - for (std::size_t i1 = 0; i1 < N1; ++i1) - { - for (std::size_t i2 = 0; i2 < N2; ++i2) - { - arr[i1][i2] = j.at(i1).at(i2).template get(); + } +} + +template +auto from_json( + const BasicJsonType &j, + T (&arr) + [N1][N2][N3] + [N4]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + -> decltype(j.template get(), void()) { + for (std::size_t i1 = 0; i1 < N1; ++i1) { + for (std::size_t i2 = 0; i2 < N2; ++i2) { + for (std::size_t i3 = 0; i3 < N3; ++i3) { + for (std::size_t i4 = 0; i4 < N4; ++i4) { + arr[i1][i2][i3][i4] = j.at(i1).at(i2).at(i3).at(i4).template get(); } + } } + } } -template -auto from_json(const BasicJsonType& j, T (&arr)[N1][N2][N3]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) --> decltype(j.template get(), void()) -{ - for (std::size_t i1 = 0; i1 < N1; ++i1) - { - for (std::size_t i2 = 0; i2 < N2; ++i2) - { - for (std::size_t i3 = 0; i3 < N3; ++i3) - { - arr[i1][i2][i3] = j.at(i1).at(i2).at(i3).template get(); - } - } - } +template +inline void from_json_array_impl(const BasicJsonType &j, + typename BasicJsonType::array_t &arr, + priority_tag<3> /*unused*/) { + arr = *j.template get_ptr(); } -template -auto from_json(const BasicJsonType& j, T (&arr)[N1][N2][N3][N4]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) --> decltype(j.template get(), void()) -{ - for (std::size_t i1 = 0; i1 < N1; ++i1) - { - for (std::size_t i2 = 0; i2 < N2; ++i2) - { - for (std::size_t i3 = 0; i3 < N3; ++i3) - { - for (std::size_t i4 = 0; i4 < N4; ++i4) - { - arr[i1][i2][i3][i4] = j.at(i1).at(i2).at(i3).at(i4).template get(); - } - } - } - } -} - -template -inline void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/) -{ - arr = *j.template get_ptr(); -} - -template -auto from_json_array_impl(const BasicJsonType& j, std::array& arr, +template +auto from_json_array_impl(const BasicJsonType &j, std::array &arr, priority_tag<2> /*unused*/) --> decltype(j.template get(), void()) -{ - for (std::size_t i = 0; i < N; ++i) - { - arr[i] = j.at(i).template get(); - } -} - -template::value, - int> = 0> -auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/) --> decltype( - arr.reserve(std::declval()), - j.template get(), - void()) -{ - using std::end; - - ConstructibleArrayType ret; - ret.reserve(j.size()); - std::transform(j.begin(), j.end(), - std::inserter(ret, end(ret)), [](const BasicJsonType & i) - { + -> decltype(j.template get(), void()) { + for (std::size_t i = 0; i < N; ++i) { + arr[i] = j.at(i).template get(); + } +} + +template ::value, + int> = 0> +auto from_json_array_impl(const BasicJsonType &j, ConstructibleArrayType &arr, + priority_tag<1> /*unused*/) + -> decltype(arr.reserve( + std::declval()), + j.template get(), + void()) { + using std::end; + + ConstructibleArrayType ret; + ret.reserve(j.size()); + std::transform( + j.begin(), j.end(), std::inserter(ret, end(ret)), + [](const BasicJsonType &i) { // get() returns *this, this won't call a from_json // method when value_type is BasicJsonType return i.template get(); - }); - arr = std::move(ret); -} - -template::value, - int> = 0> -inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, - priority_tag<0> /*unused*/) -{ - using std::end; - - ConstructibleArrayType ret; - std::transform( - j.begin(), j.end(), std::inserter(ret, end(ret)), - [](const BasicJsonType & i) - { + }); + arr = std::move(ret); +} + +template ::value, + int> = 0> +inline void from_json_array_impl(const BasicJsonType &j, + ConstructibleArrayType &arr, + priority_tag<0> /*unused*/) { + using std::end; + + ConstructibleArrayType ret; + std::transform( + j.begin(), j.end(), std::inserter(ret, end(ret)), + [](const BasicJsonType &i) { // get() returns *this, this won't call a from_json // method when value_type is BasicJsonType return i.template get(); - }); - arr = std::move(ret); -} - -template < typename BasicJsonType, typename ConstructibleArrayType, - enable_if_t < - is_constructible_array_type::value&& - !is_constructible_object_type::value&& - !is_constructible_string_type::value&& - !std::is_same::value&& - !is_basic_json::value, - int > = 0 > -auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr) --> decltype(from_json_array_impl(j, arr, priority_tag<3> {}), -j.template get(), -void()) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_array())) - { - JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); - } - - from_json_array_impl(j, arr, priority_tag<3> {}); + }); + arr = std::move(ret); } -template < typename BasicJsonType, typename T, std::size_t... Idx > -std::array from_json_inplace_array_impl(BasicJsonType&& j, - identity_tag> /*unused*/, index_sequence /*unused*/) -{ - return { { std::forward(j).at(Idx).template get()... } }; -} - -template < typename BasicJsonType, typename T, std::size_t N > -auto from_json(BasicJsonType&& j, identity_tag> tag) --> decltype(from_json_inplace_array_impl(std::forward(j), tag, make_index_sequence {})) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_array())) - { - JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); - } - - return from_json_inplace_array_impl(std::forward(j), tag, make_index_sequence {}); -} - -template -inline void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_binary())) - { - JSON_THROW(type_error::create(302, concat("type must be binary, but is ", j.type_name()), &j)); - } - - bin = *j.template get_ptr(); -} - -template::value, int> = 0> -inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_object())) - { - JSON_THROW(type_error::create(302, concat("type must be object, but is ", j.type_name()), &j)); - } - - ConstructibleObjectType ret; - const auto* inner_object = j.template get_ptr(); - using value_type = typename ConstructibleObjectType::value_type; - std::transform( - inner_object->begin(), inner_object->end(), - std::inserter(ret, ret.begin()), - [](typename BasicJsonType::object_t::value_type const & p) - { - return value_type(p.first, p.second.template get()); - }); - obj = std::move(ret); +template < + typename BasicJsonType, typename ConstructibleArrayType, + enable_if_t::value && + !is_constructible_object_type< + BasicJsonType, ConstructibleArrayType>::value && + !is_constructible_string_type< + BasicJsonType, ConstructibleArrayType>::value && + !std::is_same::value && + !is_basic_json::value, + int> = 0> +auto from_json(const BasicJsonType &j, ConstructibleArrayType &arr) + -> decltype(from_json_array_impl(j, arr, priority_tag<3>{}), + j.template get(), + void()) { + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { + JSON_THROW(type_error::create( + 302, concat("type must be array, but is ", j.type_name()), &j)); + } + + from_json_array_impl(j, arr, priority_tag<3>{}); +} + +template +std::array from_json_inplace_array_impl( + BasicJsonType &&j, identity_tag> /*unused*/, + index_sequence /*unused*/) { + return {{std::forward(j).at(Idx).template get()...}}; +} + +template +auto from_json(BasicJsonType &&j, identity_tag> tag) + -> decltype(from_json_inplace_array_impl(std::forward(j), + tag, make_index_sequence{})) { + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { + JSON_THROW(type_error::create( + 302, concat("type must be array, but is ", j.type_name()), &j)); + } + + return from_json_inplace_array_impl(std::forward(j), tag, + make_index_sequence{}); +} + +template +inline void from_json(const BasicJsonType &j, + typename BasicJsonType::binary_t &bin) { + if (JSON_HEDLEY_UNLIKELY(!j.is_binary())) { + JSON_THROW(type_error::create( + 302, concat("type must be binary, but is ", j.type_name()), &j)); + } + + bin = *j.template get_ptr(); +} + +template ::value, + int> = 0> +inline void from_json(const BasicJsonType &j, ConstructibleObjectType &obj) { + if (JSON_HEDLEY_UNLIKELY(!j.is_object())) { + JSON_THROW(type_error::create( + 302, concat("type must be object, but is ", j.type_name()), &j)); + } + + ConstructibleObjectType ret; + const auto *inner_object = + j.template get_ptr(); + using value_type = typename ConstructibleObjectType::value_type; + std::transform( + inner_object->begin(), inner_object->end(), + std::inserter(ret, ret.begin()), + [](typename BasicJsonType::object_t::value_type const &p) { + return value_type( + p.first, + p.second + .template get()); + }); + obj = std::move(ret); } // overload for arithmetic types, not chosen for basic_json template arguments -// (BooleanType, etc.); note: Is it really necessary to provide explicit +// (BooleanType, etc..); note: Is it really necessary to provide explicit // overloads for boolean_t etc. in case of a custom BooleanType which is not // an arithmetic type? -template < typename BasicJsonType, typename ArithmeticType, - enable_if_t < - std::is_arithmetic::value&& - !std::is_same::value&& - !std::is_same::value&& - !std::is_same::value&& - !std::is_same::value, - int > = 0 > -inline void from_json(const BasicJsonType& j, ArithmeticType& val) -{ - switch (static_cast(j)) - { - case value_t::number_unsigned: - { - val = static_cast(*j.template get_ptr()); - break; - } - case value_t::number_integer: - { - val = static_cast(*j.template get_ptr()); - break; - } - case value_t::number_float: - { - val = static_cast(*j.template get_ptr()); - break; - } - case value_t::boolean: - { - val = static_cast(*j.template get_ptr()); - break; - } - - case value_t::null: - case value_t::object: - case value_t::array: - case value_t::string: - case value_t::binary: - case value_t::discarded: - default: - JSON_THROW(type_error::create(302, concat("type must be number, but is ", j.type_name()), &j)); - } -} - -template -std::tuple from_json_tuple_impl_base(BasicJsonType&& j, index_sequence /*unused*/) -{ - return std::make_tuple(std::forward(j).at(Idx).template get()...); -} - -template -std::tuple<> from_json_tuple_impl_base(BasicJsonType& /*unused*/, index_sequence<> /*unused*/) -{ - return {}; -} - -template < typename BasicJsonType, class A1, class A2 > -std::pair from_json_tuple_impl(BasicJsonType&& j, identity_tag> /*unused*/, priority_tag<0> /*unused*/) -{ - return {std::forward(j).at(0).template get(), - std::forward(j).at(1).template get()}; -} - -template -inline void from_json_tuple_impl(BasicJsonType&& j, std::pair& p, priority_tag<1> /*unused*/) -{ - p = from_json_tuple_impl(std::forward(j), identity_tag> {}, priority_tag<0> {}); -} - -template -std::tuple from_json_tuple_impl(BasicJsonType&& j, identity_tag> /*unused*/, priority_tag<2> /*unused*/) -{ - return from_json_tuple_impl_base(std::forward(j), index_sequence_for {}); -} - -template -inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple& t, priority_tag<3> /*unused*/) -{ - t = from_json_tuple_impl_base(std::forward(j), index_sequence_for {}); -} - -template -auto from_json(BasicJsonType&& j, TupleRelated&& t) --> decltype(from_json_tuple_impl(std::forward(j), std::forward(t), priority_tag<3> {})) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_array())) - { - JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); - } - - return from_json_tuple_impl(std::forward(j), std::forward(t), priority_tag<3> {}); -} - -template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator, - typename = enable_if_t < !std::is_constructible < - typename BasicJsonType::string_t, Key >::value >> -inline void from_json(const BasicJsonType& j, std::map& m) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_array())) - { - JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); - } - m.clear(); - for (const auto& p : j) - { - if (JSON_HEDLEY_UNLIKELY(!p.is_array())) - { - JSON_THROW(type_error::create(302, concat("type must be array, but is ", p.type_name()), &j)); - } - m.emplace(p.at(0).template get(), p.at(1).template get()); - } -} - -template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator, - typename = enable_if_t < !std::is_constructible < - typename BasicJsonType::string_t, Key >::value >> -inline void from_json(const BasicJsonType& j, std::unordered_map& m) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_array())) - { - JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); +template < + typename BasicJsonType, typename ArithmeticType, + enable_if_t< + std::is_arithmetic::value && + !std::is_same::value && + !std::is_same::value && + !std::is_same::value && + !std::is_same::value, + int> = 0> +inline void from_json(const BasicJsonType &j, ArithmeticType &val) { + switch (static_cast(j)) { + case value_t::number_unsigned: { + val = static_cast( + *j.template get_ptr< + const typename BasicJsonType::number_unsigned_t *>()); + break; + } + case value_t::number_integer: { + val = static_cast( + *j.template get_ptr< + const typename BasicJsonType::number_integer_t *>()); + break; + } + case value_t::number_float: { + val = static_cast( + *j.template get_ptr()); + break; + } + case value_t::boolean: { + val = static_cast( + *j.template get_ptr()); + break; + } + + case value_t::null: + case value_t::object: + case value_t::array: + case value_t::string: + case value_t::binary: + case value_t::discarded: + default: + JSON_THROW(type_error::create( + 302, concat("type must be number, but is ", j.type_name()), &j)); + } +} + +template +std::tuple +from_json_tuple_impl_base(BasicJsonType &&j, + index_sequence /*unused*/) { + return std::make_tuple( + std::forward(j).at(Idx).template get()...); +} + +template +std::tuple<> from_json_tuple_impl_base(BasicJsonType & /*unused*/, + index_sequence<> /*unused*/) { + return {}; +} + +template +std::pair +from_json_tuple_impl(BasicJsonType &&j, + identity_tag> /*unused*/, + priority_tag<0> /*unused*/) { + return {std::forward(j).at(0).template get(), + std::forward(j).at(1).template get()}; +} + +template +inline void from_json_tuple_impl(BasicJsonType &&j, std::pair &p, + priority_tag<1> /*unused*/) { + p = from_json_tuple_impl(std::forward(j), + identity_tag>{}, + priority_tag<0>{}); +} + +template +std::tuple +from_json_tuple_impl(BasicJsonType &&j, + identity_tag> /*unused*/, + priority_tag<2> /*unused*/) { + return from_json_tuple_impl_base( + std::forward(j), index_sequence_for{}); +} + +template +inline void from_json_tuple_impl(BasicJsonType &&j, std::tuple &t, + priority_tag<3> /*unused*/) { + t = from_json_tuple_impl_base( + std::forward(j), index_sequence_for{}); +} + +template +auto from_json(BasicJsonType &&j, TupleRelated &&t) + -> decltype(from_json_tuple_impl(std::forward(j), + std::forward(t), + priority_tag<3>{})) { + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { + JSON_THROW(type_error::create( + 302, concat("type must be array, but is ", j.type_name()), &j)); + } + + return from_json_tuple_impl(std::forward(j), + std::forward(t), priority_tag<3>{}); +} + +template ::value>> +inline void from_json(const BasicJsonType &j, + std::map &m) { + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { + JSON_THROW(type_error::create( + 302, concat("type must be array, but is ", j.type_name()), &j)); + } + m.clear(); + for (const auto &p : j) { + if (JSON_HEDLEY_UNLIKELY(!p.is_array())) { + JSON_THROW(type_error::create( + 302, concat("type must be array, but is ", p.type_name()), &j)); } - m.clear(); - for (const auto& p : j) - { - if (JSON_HEDLEY_UNLIKELY(!p.is_array())) - { - JSON_THROW(type_error::create(302, concat("type must be array, but is ", p.type_name()), &j)); - } - m.emplace(p.at(0).template get(), p.at(1).template get()); + m.emplace(p.at(0).template get(), p.at(1).template get()); + } +} + +template ::value>> +inline void +from_json(const BasicJsonType &j, + std::unordered_map &m) { + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) { + JSON_THROW(type_error::create( + 302, concat("type must be array, but is ", j.type_name()), &j)); + } + m.clear(); + for (const auto &p : j) { + if (JSON_HEDLEY_UNLIKELY(!p.is_array())) { + JSON_THROW(type_error::create( + 302, concat("type must be array, but is ", p.type_name()), &j)); } + m.emplace(p.at(0).template get(), p.at(1).template get()); + } } #if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM -template -inline void from_json(const BasicJsonType& j, std_fs::path& p) -{ - if (JSON_HEDLEY_UNLIKELY(!j.is_string())) - { - JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j)); - } - const auto& s = *j.template get_ptr(); - // Checking for C++20 standard or later can be insufficient in case the - // library support for char8_t is either incomplete or was disabled - // altogether. Use the __cpp_lib_char8_t feature test instead. -#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L) - p = std_fs::path(std::u8string_view(reinterpret_cast(s.data()), s.size())); +template +inline void from_json(const BasicJsonType &j, std_fs::path &p) { + if (JSON_HEDLEY_UNLIKELY(!j.is_string())) { + JSON_THROW(type_error::create( + 302, concat("type must be string, but is ", j.type_name()), &j)); + } + const auto &s = + *j.template get_ptr(); +#ifdef JSON_HAS_CPP_20 + p = std_fs::path(std::u8string_view( + reinterpret_cast(s.data()), s.size())); #else - p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20 + p = std_fs::u8path( + s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20 #endif } #endif -struct from_json_fn -{ - template - auto operator()(const BasicJsonType& j, T&& val) const - noexcept(noexcept(from_json(j, std::forward(val)))) - -> decltype(from_json(j, std::forward(val))) - { - return from_json(j, std::forward(val)); - } +struct from_json_fn { + template + auto operator()(const BasicJsonType &j, T &&val) const + noexcept(noexcept(from_json(j, std::forward(val)))) + -> decltype(from_json(j, std::forward(val))) { + return from_json(j, std::forward(val)); + } }; -} // namespace detail +} // namespace detail #ifndef JSON_HAS_CPP_17 /// namespace to hold default `from_json` function @@ -574,10 +589,11 @@ struct from_json_fn namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) { #endif -JSON_INLINE_VARIABLE constexpr const auto& from_json = // NOLINT(misc-definitions-in-headers) +JSON_INLINE_VARIABLE constexpr const auto + &from_json = // NOLINT(misc-definitions-in-headers) detail::static_const::value; #ifndef JSON_HAS_CPP_17 -} // namespace +} // namespace #endif NLOHMANN_JSON_NAMESPACE_END diff --git a/nlohmann_json/include/nlohmann/detail/conversions/to_chars.hpp b/nlohmann_json/include/nlohmann/detail/conversions/to_chars.hpp index 3c663cf6..74310417 100644 --- a/nlohmann_json/include/nlohmann/detail/conversions/to_chars.hpp +++ b/nlohmann_json/include/nlohmann/detail/conversions/to_chars.hpp @@ -130,7 +130,7 @@ struct diyfp // f * 2^e // p_lo = p0_lo + (Q << 32) // // But in this particular case here, the full p_lo is not required. - // Effectively, we only need to add the highest bit in p_lo to p_hi (and + // Effectively we only need to add the highest bit in p_lo to p_hi (and // Q_hi + 1 does not overflow). Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up @@ -220,7 +220,7 @@ boundaries compute_boundaries(FloatType value) // Compute the boundaries m- and m+ of the floating-point value // v = f * 2^e. // - // Determine v- and v+, the floating-point predecessor and successor of v, + // Determine v- and v+, the floating-point predecessor and successor if v, // respectively. // // v- = v - 2^e if f != 2^(p-1) or e == e_min (A) @@ -375,7 +375,7 @@ inline cached_power get_cached_power_for_binary_exponent(int e) // (A smaller distance gamma-alpha would require a larger table.) // NB: - // Actually, this function returns c, such that -60 <= e_c + e + 64 <= -34. + // Actually this function returns c, such that -60 <= e_c + e + 64 <= -34. constexpr int kCachedPowersMinDecExp = -300; constexpr int kCachedPowersDecStep = 8; @@ -687,8 +687,8 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, decimal_exponent += n; - // We may now just stop. But instead, it looks as if the buffer - // could be decremented to bring V closer to w. + // We may now just stop. But instead look if the buffer could be + // decremented to bring V closer to w. // // pow10 = 10^n is now 1 ulp in the decimal representation V. // The rounding procedure works with diyfp's with an implicit @@ -1095,7 +1095,7 @@ char* to_chars(char* first, const char* last, FloatType value) // Compute v = buffer * 10^decimal_exponent. // The decimal digits are stored in the buffer, which needs to be interpreted // as an unsigned decimal integer. - // len is the length of the buffer, i.e., the number of decimal digits. + // len is the length of the buffer, i.e. the number of decimal digits. int len = 0; int decimal_exponent = 0; dtoa_impl::grisu2(first, len, decimal_exponent, value); diff --git a/nlohmann_json/include/nlohmann/detail/conversions/to_json.hpp b/nlohmann_json/include/nlohmann/detail/conversions/to_json.hpp index 8b910dd1..ead45665 100644 --- a/nlohmann_json/include/nlohmann/detail/conversions/to_json.hpp +++ b/nlohmann_json/include/nlohmann/detail/conversions/to_json.hpp @@ -15,8 +15,7 @@ #include // copy #include // begin, end -#include // allocator_traits -#include // basic_string, char_traits +#include // string #include // tuple, get #include // is_same, is_constructible, is_floating_point, is_enum, underlying_type #include // move, forward, declval, pair @@ -268,7 +267,7 @@ struct external_constructor #ifdef JSON_HAS_CPP_17 template::value, int> = 0> -void to_json(BasicJsonType& j, const std::optional& opt) noexcept +void to_json(BasicJsonType& j, const std::optional& opt) { if (opt.has_value()) { @@ -441,21 +440,15 @@ inline void to_json(BasicJsonType& j, const T& t) } #if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM -#if defined(__cpp_lib_char8_t) -template -inline void to_json(BasicJsonType& j, const std::basic_string& s) -{ - using OtherAllocator = typename std::allocator_traits::template rebind_alloc; - j = std::basic_string, OtherAllocator>(s.begin(), s.end(), s.get_allocator()); -} -#endif - template inline void to_json(BasicJsonType& j, const std_fs::path& p) { - // Returns either a std::string or a std::u8string depending whether library - // support for char8_t is enabled. - j = p.u8string(); +#ifdef JSON_HAS_CPP_20 + const std::u8string s = p.u8string(); + j = std::string(s.begin(), s.end()); +#else + j = p.u8string(); // returns std::string in C++17 +#endif } #endif diff --git a/nlohmann_json/include/nlohmann/detail/exceptions.hpp b/nlohmann_json/include/nlohmann/detail/exceptions.hpp index 2740e4c2..5ebfb657 100644 --- a/nlohmann_json/include/nlohmann/detail/exceptions.hpp +++ b/nlohmann_json/include/nlohmann/detail/exceptions.hpp @@ -30,7 +30,7 @@ // emitted in every translation unit. This issue cannot be fixed with a // header-only library as there is no implementation file to move these // functions to. As a result, we suppress this warning here to avoid client -// code stumbling over this. See https://github.com/nlohmann/json/issues/4087 +// code to stumble over this. See https://github.com/nlohmann/json/issues/4087 // for a discussion. #if defined(__clang__) #pragma clang diagnostic push diff --git a/nlohmann_json/include/nlohmann/detail/input/binary_reader.hpp b/nlohmann_json/include/nlohmann/detail/input/binary_reader.hpp index 1678c13f..2120cf9a 100644 --- a/nlohmann_json/include/nlohmann/detail/input/binary_reader.hpp +++ b/nlohmann_json/include/nlohmann/detail/input/binary_reader.hpp @@ -53,7 +53,7 @@ enum class cbor_tag_handler_t @note from https://stackoverflow.com/a/1001328/266378 */ -inline bool little_endianness(int num = 1) noexcept +static inline bool little_endianness(int num = 1) noexcept { return *reinterpret_cast(&num) == 1; } @@ -334,7 +334,7 @@ class binary_reader return get_number(input_format_t::bson, value) && sax->number_unsigned(value); } - default: // anything else is not supported (yet) + default: // anything else not supported (yet) { std::array cr{{}}; static_cast((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) @@ -731,7 +731,7 @@ class binary_reader case 0xD2: case 0xD3: case 0xD4: - case 0xD8: // tagged item (1 byte follows) + case 0xD8: // tagged item (1 bytes follow) case 0xD9: // tagged item (2 bytes follow) case 0xDA: // tagged item (4 bytes follow) case 0xDB: // tagged item (8 bytes follow) @@ -783,7 +783,7 @@ class binary_reader case cbor_tag_handler_t::store: { binary_t b; - // use binary subtype and store in a binary container + // use binary subtype and store in binary container switch (current) { case 0xD8: @@ -852,7 +852,7 @@ class binary_reader const auto byte1 = static_cast(byte1_raw); const auto byte2 = static_cast(byte2_raw); - // Code from RFC 7049, Appendix D, Figure 3: + // code from RFC 7049, Appendix D, Figure 3: // As half-precision floating-point numbers were only added // to IEEE 754 in 2008, today's programming platforms often // still only have limited support for them. It is very @@ -2159,7 +2159,7 @@ class binary_reader { break; } - if (is_ndarray) // ndarray dimensional vector can only contain integers and cannot embed another array + if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array { return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr)); } @@ -2192,16 +2192,8 @@ class binary_reader result = 1; for (auto i : dim) { - // Pre-multiplication overflow check: if i > 0 and result > SIZE_MAX/i, then result*i would overflow. - // This check must happen before multiplication since overflow detection after the fact is unreliable - // as modular arithmetic can produce any value, not just 0 or SIZE_MAX. - if (JSON_HEDLEY_UNLIKELY(i > 0 && result > (std::numeric_limits::max)() / i)) - { - return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr)); - } result *= i; - // Additional post-multiplication check to catch any edge cases the pre-check might miss - if (result == 0 || result == npos) + if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type() { return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr)); } @@ -2417,7 +2409,7 @@ class binary_reader const auto byte1 = static_cast(byte1_raw); const auto byte2 = static_cast(byte2_raw); - // Code from RFC 7049, Appendix D, Figure 3: + // code from RFC 7049, Appendix D, Figure 3: // As half-precision floating-point numbers were only added // to IEEE 754 in 2008, today's programming platforms often // still only have limited support for them. It is very @@ -2705,7 +2697,7 @@ class binary_reader bool get_ubjson_high_precision_number() { - // get the size of the following number string + // get size of following number string std::size_t size{}; bool no_ndarray = true; auto res = get_ubjson_size_value(size, no_ndarray); @@ -2803,7 +2795,7 @@ class binary_reader chars_read += new_chars_read; if (JSON_HEDLEY_UNLIKELY(new_chars_read < sizeof(T))) { - // in case of failure, advance position by 1 to report the failing location + // in case of failure, advance position by 1 to report failing location ++chars_read; sax->parse_error(chars_read, "", parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr)); return false; @@ -2834,22 +2826,17 @@ class binary_reader { return; } - else if constexpr(std::is_integral_v) + if constexpr(std::is_integral_v) { number = std::byteswap(number); return; } - else - { #endif - auto* ptr = reinterpret_cast(&number); - for (std::size_t i = 0; i < sz / 2; ++i) - { - std::swap(ptr[i], ptr[sz - i - 1]); - } -#ifdef __cpp_lib_byteswap + auto* ptr = reinterpret_cast(&number); + for (std::size_t i = 0; i < sz / 2; ++i) + { + std::swap(ptr[i], ptr[sz - i - 1]); } -#endif } /* @@ -2944,7 +2931,7 @@ class binary_reader success = false; break; } - result.push_back(static_cast(current)); + result.push_back(static_cast(current)); } return success; } diff --git a/nlohmann_json/include/nlohmann/detail/input/input_adapters.hpp b/nlohmann_json/include/nlohmann/detail/input/input_adapters.hpp index 2c23a8e5..1affd619 100644 --- a/nlohmann_json/include/nlohmann/detail/input/input_adapters.hpp +++ b/nlohmann_json/include/nlohmann/detail/input/input_adapters.hpp @@ -108,7 +108,7 @@ class input_stream_adapter : is(&i), sb(i.rdbuf()) {} - // deleted because of pointer members + // delete because of pointer members input_stream_adapter(const input_stream_adapter&) = delete; input_stream_adapter& operator=(input_stream_adapter&) = delete; input_stream_adapter& operator=(input_stream_adapter&&) = delete; @@ -122,7 +122,7 @@ class input_stream_adapter // std::istream/std::streambuf use std::char_traits::to_int_type, to // ensure that std::char_traits::eof() and the character 0xFF do not - // end up as the same value, e.g., 0xFFFFFFFF. + // end up as the same value, e.g. 0xFFFFFFFF. std::char_traits::int_type get_character() { auto res = sb->sbumpc(); @@ -344,7 +344,7 @@ class wide_string_input_adapter typename std::char_traits::int_type get_character() noexcept { - // check if the buffer needs to be filled + // check if buffer needs to be filled if (utf8_bytes_index == utf8_bytes_filled) { fill_buffer(); diff --git a/nlohmann_json/include/nlohmann/detail/input/json_sax.hpp b/nlohmann_json/include/nlohmann/detail/input/json_sax.hpp index 0b06ad5a..0ff87789 100644 --- a/nlohmann_json/include/nlohmann/detail/input/json_sax.hpp +++ b/nlohmann_json/include/nlohmann/detail/input/json_sax.hpp @@ -260,7 +260,7 @@ class json_sax_dom_parser JSON_ASSERT(!ref_stack.empty()); JSON_ASSERT(ref_stack.back()->is_object()); - // add null at the given key and store the reference for later + // add null at given key and store the reference for later object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val)); return true; } @@ -576,11 +576,11 @@ class json_sax_dom_callback_parser { BasicJsonType k = BasicJsonType(val); - // check callback for the key + // check callback for key const bool keep = callback(static_cast(ref_stack.size()), parse_event_t::key, k); key_keep_stack.push_back(keep); - // add discarded value at the given key and store the reference for later + // add discarded value at given key and store the reference for later if (keep && ref_stack.back()) { object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) = discarded); diff --git a/nlohmann_json/include/nlohmann/detail/input/lexer.hpp b/nlohmann_json/include/nlohmann/detail/input/lexer.hpp index a40790e7..2b4e80a4 100644 --- a/nlohmann_json/include/nlohmann/detail/input/lexer.hpp +++ b/nlohmann_json/include/nlohmann/detail/input/lexer.hpp @@ -127,7 +127,7 @@ class lexer : public lexer_base , decimal_point_char(static_cast(get_decimal_point())) {} - // deleted because of pointer members + // delete because of pointer members lexer(const lexer&) = delete; lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) lexer& operator=(lexer&) = delete; @@ -262,10 +262,10 @@ class lexer : public lexer_base while (true) { - // get the next character + // get next character switch (get()) { - // end of file while parsing the string + // end of file while parsing string case char_traits::eof(): { error_message = "invalid string: missing closing quote"; @@ -351,7 +351,7 @@ class lexer : public lexer_base (static_cast(codepoint1) << 10u) // low surrogate occupies the least significant 15 bits + static_cast(codepoint2) - // there is still the 0xD800, 0xDC00, and 0x10000 noise + // there is still the 0xD800, 0xDC00 and 0x10000 noise // in the result, so we have to subtract with: // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 - 0x35FDC00u); @@ -377,7 +377,7 @@ class lexer : public lexer_base } } - // the result of the above calculation yields a proper codepoint + // result of the above calculation yields a proper codepoint JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF); // translate codepoint into bytes @@ -828,7 +828,7 @@ class lexer : public lexer_base break; } - // the remaining bytes (80..C1 and F5..FF) are ill-formed + // remaining bytes (80..C1 and F5..FF) are ill-formed default: { error_message = "invalid string: ill-formed UTF-8 byte"; @@ -973,7 +973,7 @@ class lexer : public lexer_base reset(); // the type of the parsed number; initially set to unsigned; will be - // changed if minus sign, decimal point, or exponent is read + // changed if minus sign, decimal point or exponent is read token_type number_type = token_type::value_unsigned; // state (init): we just found out we need to scan a number @@ -1345,7 +1345,7 @@ class lexer : public lexer_base if (next_unget) { - // only reset the next_unget variable and work with current + // just reset the next_unget variable and work with current next_unget = false; } else @@ -1524,7 +1524,7 @@ class lexer : public lexer_base return token_type::parse_error; } - // read the next character and ignore whitespace + // read next character and ignore whitespace skip_whitespace(); // ignore comments diff --git a/nlohmann_json/include/nlohmann/detail/input/parser.hpp b/nlohmann_json/include/nlohmann/detail/input/parser.hpp index 2f5cde24..b5a5a525 100644 --- a/nlohmann_json/include/nlohmann/detail/input/parser.hpp +++ b/nlohmann_json/include/nlohmann/detail/input/parser.hpp @@ -71,12 +71,10 @@ class parser explicit parser(InputAdapterType&& adapter, parser_callback_t cb = nullptr, const bool allow_exceptions_ = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas_ = false) + const bool skip_comments = false) : callback(std::move(cb)) - , m_lexer(std::move(adapter), ignore_comments) + , m_lexer(std::move(adapter), skip_comments) , allow_exceptions(allow_exceptions_) - , ignore_trailing_commas(ignore_trailing_commas_) { // read first token get_token(); @@ -108,7 +106,7 @@ class parser exception_message(token_type::end_of_input, "value"), nullptr)); } - // in case of an error, return a discarded value + // in case of an error, return discarded value if (sdp.is_errored()) { result = value_t::discarded; @@ -135,7 +133,7 @@ class parser parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr)); } - // in case of an error, return a discarded value + // in case of an error, return discarded value if (sdp.is_errored()) { result = value_t::discarded; @@ -338,7 +336,7 @@ class parser case token_type::parse_error: { - // using "uninitialized" to avoid an "expected" message + // using "uninitialized" to avoid "expected" message return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), nullptr)); @@ -386,17 +384,11 @@ class parser if (states.back()) // array { // comma -> next value - // or end of array (ignore_trailing_commas = true) if (get_token() == token_type::value_separator) { // parse a new value get_token(); - - // if ignore_trailing_commas and last_token is ], we can continue to "closing ]" - if (!(ignore_trailing_commas && last_token == token_type::end_array)) - { - continue; - } + continue; } // closing ] @@ -425,39 +417,32 @@ class parser // states.back() is false -> object // comma -> next value - // or end of object (ignore_trailing_commas = true) if (get_token() == token_type::value_separator) { - get_token(); - - // if ignore_trailing_commas and last_token is }, we can continue to "closing }" - if (!(ignore_trailing_commas && last_token == token_type::end_object)) + // parse key + if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string)) { - // parse key - if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string)) - { - return sax->parse_error(m_lexer.get_position(), - m_lexer.get_token_string(), - parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr)); - } - - if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) - { - return false; - } + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr)); + } - // parse separator (:) - if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) - { - return sax->parse_error(m_lexer.get_position(), - m_lexer.get_token_string(), - parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr)); - } + if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) + { + return false; + } - // parse values - get_token(); - continue; + // parse separator (:) + if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) + { + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr)); } + + // parse values + get_token(); + continue; } // closing } @@ -528,8 +513,6 @@ class parser lexer_t m_lexer; /// whether to throw exceptions in case of errors const bool allow_exceptions = true; - /// whether trailing commas in objects and arrays should be ignored (true) or signaled as errors (false) - const bool ignore_trailing_commas = false; }; } // namespace detail diff --git a/nlohmann_json/include/nlohmann/detail/iterators/iter_impl.hpp b/nlohmann_json/include/nlohmann/detail/iterators/iter_impl.hpp index c2fbbfa7..45864e8c 100644 --- a/nlohmann_json/include/nlohmann/detail/iterators/iter_impl.hpp +++ b/nlohmann_json/include/nlohmann/detail/iterators/iter_impl.hpp @@ -23,7 +23,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { -// forward declare to be able to friend it later on +// forward declare, to be able to friend it later on template class iteration_proxy; template class iteration_proxy_value; diff --git a/nlohmann_json/include/nlohmann/detail/iterators/primitive_iterator.hpp b/nlohmann_json/include/nlohmann/detail/iterators/primitive_iterator.hpp index f1a73566..3a238349 100644 --- a/nlohmann_json/include/nlohmann/detail/iterators/primitive_iterator.hpp +++ b/nlohmann_json/include/nlohmann/detail/iterators/primitive_iterator.hpp @@ -21,9 +21,9 @@ namespace detail @brief an iterator for primitive JSON types This class models an iterator for primitive JSON types (boolean, number, -string). Its only purpose is to allow the iterator/const_iterator classes +string). It's only purpose is to allow the iterator/const_iterator classes to "iterate" over primitive values. Internally, the iterator is modeled by -a `difference_type` variable. Value begin_value (`0`) models the begin and +a `difference_type` variable. Value begin_value (`0`) models the begin, end_value (`1`) models past the end. */ class primitive_iterator_t diff --git a/nlohmann_json/include/nlohmann/detail/json_pointer.hpp b/nlohmann_json/include/nlohmann/detail/json_pointer.hpp index e1b3947e..1f764979 100644 --- a/nlohmann_json/include/nlohmann/detail/json_pointer.hpp +++ b/nlohmann_json/include/nlohmann/detail/json_pointer.hpp @@ -285,7 +285,7 @@ class json_pointer { if (reference_token == "0") { - // start a new array if the reference token is 0 + // start a new array if reference token is 0 result = &result->operator[](0); } else @@ -314,7 +314,7 @@ class json_pointer The following code is only reached if there exists a reference token _and_ the current value is primitive. In this case, we have an error situation, because primitive values may only occur as - a single value; that is, with an empty list of reference tokens. + single value; that is, with an empty list of reference tokens. */ case detail::value_t::string: case detail::value_t::boolean: @@ -358,7 +358,7 @@ class json_pointer // convert null values to arrays or objects before continuing if (ptr->is_null()) { - // check if the reference token is a number + // check if reference token is a number const bool nums = std::all_of(reference_token.begin(), reference_token.end(), [](const unsigned char x) @@ -366,7 +366,7 @@ class json_pointer return std::isdigit(x); }); - // change value to an array for numbers or "-" or to object otherwise + // change value to array for numbers or "-" or to object otherwise *ptr = (nums || reference_token == "-") ? detail::value_t::array : detail::value_t::object; @@ -609,7 +609,7 @@ class json_pointer { if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9'))) { - // the first char should be between '1' and '9' + // first char should be between '1' and '9' return false; } for (std::size_t i = 1; i < reference_token.size(); i++) @@ -673,7 +673,7 @@ class json_pointer return result; } - // check if a nonempty reference string begins with slash + // check if nonempty reference string begins with slash if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/')) { JSON_THROW(detail::parse_error::create(107, 1, detail::concat("JSON pointer must be empty or begin with '/' - was: '", reference_string, "'"), nullptr)); @@ -747,7 +747,7 @@ class json_pointer } else { - // iterate array and use index as a reference string + // iterate array and use index as reference string for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i) { flatten(detail::concat(reference_string, '/', std::to_string(i)), @@ -785,7 +785,7 @@ class json_pointer case detail::value_t::discarded: default: { - // add a primitive value with its reference string + // add primitive value with its reference string result[reference_string] = value; break; } @@ -821,17 +821,17 @@ class json_pointer JSON_THROW(detail::type_error::create(315, "values in object must be primitive", &element.second)); } - // Assign the value to the reference pointed to by JSON pointer. Note - // that if the JSON pointer is "" (i.e., points to the whole value), - // function get_and_create returns a reference to the result itself. - // An assignment will then create a primitive value. + // assign value to reference pointed to by JSON pointer; Note that if + // the JSON pointer is "" (i.e., points to the whole value), function + // get_and_create returns a reference to result itself. An assignment + // will then create a primitive value. json_pointer(element.first).get_and_create(result) = element.second; } return result; } - // can't use the conversion operator because of ambiguity + // can't use conversion operator because of ambiguity json_pointer convert() const& { json_pointer result; @@ -926,7 +926,7 @@ class json_pointer }; #if !JSON_HAS_THREE_WAY_COMPARISON -// functions cannot be defined inside the class due to ODR violations +// functions cannot be defined inside class due to ODR violations template inline bool operator==(const json_pointer& lhs, const json_pointer& rhs) noexcept diff --git a/nlohmann_json/include/nlohmann/detail/macro_scope.hpp b/nlohmann_json/include/nlohmann/detail/macro_scope.hpp index 9117c7df..d1c6b1be 100644 --- a/nlohmann_json/include/nlohmann/detail/macro_scope.hpp +++ b/nlohmann_json/include/nlohmann/detail/macro_scope.hpp @@ -31,15 +31,9 @@ #endif // C++ language standard detection -// if the user manually specified the used C++ version, this is skipped -#if !defined(JSON_HAS_CPP_26) && !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) - #if (defined(__cplusplus) && __cplusplus > 202302L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202302L) - #define JSON_HAS_CPP_26 - #define JSON_HAS_CPP_23 - #define JSON_HAS_CPP_20 - #define JSON_HAS_CPP_17 - #define JSON_HAS_CPP_14 - #elif (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L) +// if the user manually specified the used c++ version this is skipped +#if !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) + #if (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L) #define JSON_HAS_CPP_23 #define JSON_HAS_CPP_20 #define JSON_HAS_CPP_17 @@ -134,7 +128,7 @@ #endif #ifndef JSON_HAS_RANGES - // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error + // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 #define JSON_HAS_RANGES 0 #elif defined(__cpp_lib_ranges) @@ -211,7 +205,7 @@ #define JSON_ASSERT(x) assert(x) #endif -// allow accessing some private functions (needed by the test suite) +// allow to access some private functions (needed by the test suite) #if defined(JSON_TESTS_PRIVATE) #define JSON_PRIVATE_UNLESS_TESTED public #else diff --git a/nlohmann_json/include/nlohmann/detail/macro_unscope.hpp b/nlohmann_json/include/nlohmann/detail/macro_unscope.hpp index 89005485..6a9244af 100644 --- a/nlohmann_json/include/nlohmann/detail/macro_unscope.hpp +++ b/nlohmann_json/include/nlohmann/detail/macro_unscope.hpp @@ -10,7 +10,7 @@ // restore clang diagnostic settings #if defined(__clang__) -// NOLINTNEXTLINE(clang-diagnostic-unknown-pragmas) + // NOLINTNEXTLINE(clang-diagnostic-unknown-pragmas) #pragma clang diagnostic pop #endif @@ -36,7 +36,6 @@ #undef JSON_HAS_CPP_17 #undef JSON_HAS_CPP_20 #undef JSON_HAS_CPP_23 - #undef JSON_HAS_CPP_26 #undef JSON_HAS_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #undef JSON_HAS_THREE_WAY_COMPARISON diff --git a/nlohmann_json/include/nlohmann/detail/meta/type_traits.hpp b/nlohmann_json/include/nlohmann/detail/meta/type_traits.hpp index 21b0664e..d834a0d5 100644 --- a/nlohmann_json/include/nlohmann/detail/meta/type_traits.hpp +++ b/nlohmann_json/include/nlohmann/detail/meta/type_traits.hpp @@ -13,9 +13,7 @@ #include // tuple #include // false_type, is_constructible, is_integral, is_same, true_type #include // declval -#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L - #include // byte -#endif + #include #include #include @@ -42,12 +40,12 @@ namespace detail // Note to maintainers: // -// Every trait in this file expects a non-CV-qualified type. +// Every trait in this file expects a non CV-qualified type. // The only exceptions are in the 'aliases for detected' section -// (i.e., those of the form: decltype(T::member_function(std::declval()))) +// (i.e. those of the form: decltype(T::member_function(std::declval()))) // // In this case, T has to be properly CV-qualified to constraint the function arguments -// (e.g., to_json(BasicJsonType&, const T&)) +// (e.g. to_json(BasicJsonType&, const T&)) template struct is_basic_json : std::false_type {}; @@ -55,7 +53,7 @@ NLOHMANN_BASIC_JSON_TPL_DECLARATION struct is_basic_json : std::true_type {}; // used by exceptions create() member functions -// true_type for the pointer to possibly cv-qualified basic_json or std::nullptr_t +// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t // false_type otherwise template struct is_basic_json_context : @@ -241,30 +239,6 @@ struct char_traits : std::char_traits } }; -#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L -template<> -struct char_traits : std::char_traits -{ - using char_type = std::byte; - using int_type = uint64_t; - - static int_type to_int_type(char_type c) noexcept - { - return static_cast(std::to_integer(c)); - } - - static char_type to_char_type(int_type i) noexcept - { - return static_cast(static_cast(i)); - } - - static constexpr int_type eof() noexcept - { - return static_cast(std::char_traits::eof()); - } -}; -#endif - /////////////////// // is_ functions // /////////////////// @@ -281,7 +255,7 @@ template struct negation : std::integral_constant < bool, !B::value > { // Reimplementation of is_constructible and is_default_constructible, due to them being broken for // std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367). -// This causes compile errors in e.g., Clang 3.5 or GCC 4.9. +// This causes compile errors in e.g. clang 3.5 or gcc 4.9. template struct is_default_constructible : std::is_default_constructible {}; @@ -361,7 +335,7 @@ using range_value_t = value_type_t>>; // The following implementation of is_complete_type is taken from // https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ -// and is written by Xiang Fan who agreed to use it in this library. +// and is written by Xiang Fan who agreed to using it in this library. template struct is_complete_type : std::false_type {}; @@ -598,7 +572,7 @@ decltype(std::declval()(std::declval(), std::declval())) template using detect_is_transparent = typename T::is_transparent; -// type trait to check if KeyType can be used as an object key (without a BasicJsonType) +// type trait to check if KeyType can be used as object key (without a BasicJsonType) // see is_usable_as_basic_json_key_type below template> @@ -612,7 +586,7 @@ using is_usable_as_key_type = typename std::conditional < std::true_type, std::false_type >::type; -// type trait to check if KeyType can be used as an object key +// type trait to check if KeyType can be used as object key // true if: // - KeyType is comparable with BasicJsonType::object_t::key_type // - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type diff --git a/nlohmann_json/include/nlohmann/detail/output/binary_writer.hpp b/nlohmann_json/include/nlohmann/detail/output/binary_writer.hpp index b466ded7..f81fa54c 100644 --- a/nlohmann_json/include/nlohmann/detail/output/binary_writer.hpp +++ b/nlohmann_json/include/nlohmann/detail/output/binary_writer.hpp @@ -973,9 +973,9 @@ class binary_writer if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos)) { JSON_THROW(out_of_range::create(409, concat("BSON key cannot contain code point U+0000 (at byte ", std::to_string(it), ")"), &j)); + static_cast(j); } - static_cast(j); return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; } @@ -1552,7 +1552,7 @@ class binary_writer { return 'L'; } - // anything else is treated as a high-precision number + // anything else is treated as high-precision number return 'H'; // LCOV_EXCL_LINE } @@ -1590,7 +1590,7 @@ class binary_writer { return 'M'; } - // anything else is treated as a high-precision number + // anything else is treated as high-precision number return 'H'; // LCOV_EXCL_LINE } @@ -1756,11 +1756,11 @@ class binary_writer template void write_number(const NumberType n, const bool OutputIsLittleEndian = false) { - // step 1: write the number to an array of length NumberType + // step 1: write number to array of length NumberType std::array vec{}; std::memcpy(vec.data(), &n, sizeof(NumberType)); - // step 2: write the array to output (with possible reordering) + // step 2: write array to output (with possible reordering) if (is_little_endian != OutputIsLittleEndian) { // reverse byte order prior to conversion if necessary @@ -1776,9 +1776,9 @@ class binary_writer #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wfloat-equal" #endif - if (!std::isfinite(n) || ((static_cast(n) >= static_cast(std::numeric_limits::lowest()) && - static_cast(n) <= static_cast((std::numeric_limits::max)()) && - static_cast(static_cast(n)) == static_cast(n)))) + if (static_cast(n) >= static_cast(std::numeric_limits::lowest()) && + static_cast(n) <= static_cast((std::numeric_limits::max)()) && + static_cast(static_cast(n)) == static_cast(n)) { oa->write_character(format == detail::input_format_t::cbor ? get_cbor_float_prefix(static_cast(n)) @@ -1813,21 +1813,8 @@ class binary_writer enable_if_t < std::is_signed::value && std::is_unsigned::value > * = nullptr > static CharType to_char_type(std::uint8_t x) noexcept { - // The std::is_trivial trait is deprecated in C++26. The replacement is to use - // std::is_trivially_copyable and std::is_trivially_default_constructible. - // However, some older library implementations support std::is_trivial - // but not all the std::is_trivially_* traits. - // Since detecting full support across all libraries is difficult, - // we use std::is_trivial unless we are using a standard where it has been deprecated. - // For more details, see: https://github.com/nlohmann/json/pull/4775#issuecomment-2884361627 -#ifdef JSON_HAS_CPP_26 - static_assert(std::is_trivially_copyable::value, "CharType must be trivially copyable"); - static_assert(std::is_trivially_default_constructible::value, "CharType must be trivially default constructible"); -#else - static_assert(std::is_trivial::value, "CharType must be trivial"); -#endif - static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t"); + static_assert(std::is_trivial::value, "CharType must be trivial"); CharType result; std::memcpy(&result, &x, sizeof(x)); return result; diff --git a/nlohmann_json/include/nlohmann/detail/output/serializer.hpp b/nlohmann_json/include/nlohmann/detail/output/serializer.hpp index 28ff20f5..3137f3c3 100644 --- a/nlohmann_json/include/nlohmann/detail/output/serializer.hpp +++ b/nlohmann_json/include/nlohmann/detail/output/serializer.hpp @@ -75,7 +75,7 @@ class serializer , error_handler(error_handler_) {} - // deleted because of pointer members + // delete because of pointer members serializer(const serializer&) = delete; serializer& operator=(const serializer&) = delete; serializer(serializer&&) = delete; @@ -573,7 +573,7 @@ class serializer break; } - default: // decode found yet incomplete multibyte code point + default: // decode found yet incomplete multi-byte code point { if (!ensure_ascii) { @@ -762,7 +762,7 @@ class serializer // jump to the end to generate the string from backward, // so we later avoid reversing the result - buffer_ptr += static_cast(n_chars); + buffer_ptr += n_chars; // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu // See: https://www.youtube.com/watch?v=o4-CwDo2zpg @@ -827,7 +827,7 @@ class serializer void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/) { - // get the number of digits for a float -> text -> float round-trip + // get number of digits for a float -> text -> float round-trip static constexpr auto d = std::numeric_limits::max_digits10; // the actual conversion @@ -836,10 +836,10 @@ class serializer // negative value indicates an error JSON_ASSERT(len > 0); - // check if the buffer was large enough + // check if buffer was large enough JSON_ASSERT(static_cast(len) < number_buffer.size()); - // erase thousands separators + // erase thousands separator if (thousands_sep != '\0') { // NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::remove returns an iterator, see https://github.com/nlohmann/json/issues/3081 @@ -947,8 +947,8 @@ class serializer * Helper function for dump_integer * * This function takes a negative signed integer and returns its absolute - * value as an unsigned integer. The plus/minus shuffling is necessary as we - * cannot directly remove the sign of an arbitrary signed integer as the + * value as unsigned integer. The plus/minus shuffling is necessary as we can + * not directly remove the sign of an arbitrary signed integer as the * absolute values of INT_MIN and INT_MAX are usually not the same. See * #1708 for details. */ diff --git a/nlohmann_json/include/nlohmann/detail/string_escape.hpp b/nlohmann_json/include/nlohmann/detail/string_escape.hpp index 63715cde..7f023181 100644 --- a/nlohmann_json/include/nlohmann/detail/string_escape.hpp +++ b/nlohmann_json/include/nlohmann/detail/string_escape.hpp @@ -32,10 +32,10 @@ inline void replace_substring(StringType& s, const StringType& f, const StringType& t) { JSON_ASSERT(!f.empty()); - for (auto pos = s.find(f); // find the first occurrence of f + for (auto pos = s.find(f); // find first occurrence of f pos != StringType::npos; // make sure f was found s.replace(pos, f.size(), t), // replace with t, and - pos = s.find(f, pos + t.size())) // find the next occurrence of f + pos = s.find(f, pos + t.size())) // find next occurrence of f {} } @@ -62,7 +62,7 @@ inline StringType escape(StringType s) * Note the order of escaping "~1" to "/" and "~0" to "~" is important. */ template -inline void unescape(StringType& s) +static void unescape(StringType& s) { replace_substring(s, StringType{"~1"}, StringType{"/"}); replace_substring(s, StringType{"~0"}, StringType{"~"}); diff --git a/nlohmann_json/include/nlohmann/json.hpp b/nlohmann_json/include/nlohmann/json.hpp index 55ec39d2..ed51cd54 100644 --- a/nlohmann_json/include/nlohmann/json.hpp +++ b/nlohmann_json/include/nlohmann/json.hpp @@ -134,12 +134,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec InputAdapterType adapter, detail::parser_callback_tcb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false + const bool ignore_comments = false ) { return ::nlohmann::detail::parser(std::move(adapter), - std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas); + std::move(cb), allow_exceptions, ignore_comments); } private: @@ -564,7 +563,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec (t == value_t::binary && binary == nullptr) ) { - // not initialized (e.g., due to exception in the ctor) + //not initialized (e.g. due to exception in the ctor) return; } if (t == value_t::array || t == value_t::object) @@ -589,7 +588,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec while (!stack.empty()) { - // move the last item to a local variable to be processed + // move the last item to local variable to be processed basic_json current_item(std::move(stack.back())); stack.pop_back(); @@ -611,7 +610,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec current_item.m_data.m_value.object->clear(); } - // it's now safe that current_item gets destructed + // it's now safe that current_item get destructed // since it doesn't have any children } } @@ -919,20 +918,20 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { // The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int; // (many string types can be constructed from 0 via its null-pointer guise, so we get a - // broken call to op[key_type], the wrong semantics, and a 4804 warning on Windows) + // broken call to op[key_type], the wrong semantics and a 4804 warning on Windows) return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast(0)].is_string(); }); // adjust type if type deduction is not wanted if (!type_deduction) { - // if an array is wanted, do not create an object though possible + // if array is wanted, do not create an object though possible if (manual_type == value_t::array) { is_an_object = false; } - // if an object is wanted but impossible, throw an exception + // if object is wanted but impossible, throw an exception if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object)) { JSON_THROW(type_error::create(301, "cannot create object from initializer list", nullptr)); @@ -941,7 +940,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (is_an_object) { - // the initializer list is a list of pairs -> create an object + // the initializer list is a list of pairs -> create object m_data.m_type = value_t::object; m_data.m_value = value_t::object; @@ -955,7 +954,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } else { - // the initializer list describes an array -> create an array + // the initializer list describes an array -> create array m_data.m_type = value_t::array; m_data.m_value.array = create(init.begin(), init.end()); } @@ -1043,16 +1042,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_ASSERT(first.m_object != nullptr); JSON_ASSERT(last.m_object != nullptr); - // make sure the iterator fits the current value + // make sure iterator fits the current value if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) { JSON_THROW(invalid_iterator::create(201, "iterators are not compatible", nullptr)); } - // copy type from the first iterator + // copy type from first iterator m_data.m_type = first.m_object->m_data.m_type; - // check if the iterator range is complete for primitive values + // check if iterator range is complete for primitive values switch (m_data.m_type) { case value_t::boolean: @@ -1232,7 +1231,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec , end_position(other.end_position) // cppcheck-suppress[accessForwarded] TODO check #endif { - // check that the passed value is valid + // check that passed value is valid other.assert_invariant(false); // cppcheck-suppress[accessForwarded] // invalidate payload @@ -1258,7 +1257,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec std::is_nothrow_move_assignable::value ) { - // check that the passed value is valid + // check that passed value is valid other.assert_invariant(); using std::swap; @@ -1974,7 +1973,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } JSON_CATCH (std::out_of_range&) { - // create a better exception explanation + // create better exception explanation JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); } // cppcheck-suppress[missingReturn] } @@ -1997,7 +1996,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } JSON_CATCH (std::out_of_range&) { - // create a better exception explanation + // create better exception explanation JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); } // cppcheck-suppress[missingReturn] } @@ -2087,7 +2086,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ reference operator[](size_type idx) { - // implicitly convert a null value to an empty array + // implicitly convert null value to an empty array if (is_null()) { m_data.m_type = value_t::array; @@ -2098,7 +2097,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // operator[] only works for arrays if (JSON_HEDLEY_LIKELY(is_array())) { - // fill up the array with null values if given idx is outside the range + // fill up array with null values if given idx is outside range if (idx >= m_data.m_value.array->size()) { #if JSON_DIAGNOSTICS @@ -2146,7 +2145,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ reference operator[](typename object_t::key_type key) // NOLINT(performance-unnecessary-value-param) { - // implicitly convert a null value to an empty object + // implicitly convert null value to an empty object if (is_null()) { m_data.m_type = value_t::object; @@ -2199,7 +2198,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::is_usable_as_basic_json_key_type::value, int > = 0 > reference operator[](KeyType && key) { - // implicitly convert a null value to an empty object + // implicitly convert null value to an empty object if (is_null()) { m_data.m_type = value_t::object; @@ -2256,7 +2255,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If 'key' is found, return its value. Otherwise, return `default_value'. + // if key is found, return value and given default value otherwise const auto it = find(key); if (it != end()) { @@ -2281,7 +2280,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If 'key' is found, return its value. Otherwise, return `default_value'. + // if key is found, return value and given default value otherwise const auto it = find(key); if (it != end()) { @@ -2307,7 +2306,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If 'key' is found, return its value. Otherwise, return `default_value'. + // if key is found, return value and given default value otherwise const auto it = find(std::forward(key)); if (it != end()) { @@ -2334,7 +2333,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If 'key' is found, return its value. Otherwise, return `default_value'. + // if key is found, return value and given default value otherwise const auto it = find(std::forward(key)); if (it != end()) { @@ -2357,8 +2356,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If the pointer resolves to a value, return it. Otherwise, return - // 'default_value'. + // if pointer resolves a value, return it or use default value JSON_TRY { return ptr.get_checked(this).template get(); @@ -2383,8 +2381,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If the pointer resolves to a value, return it. Otherwise, return - // 'default_value'. + // if pointer resolves a value, return it or use default value JSON_TRY { return ptr.get_checked(this).template get(); @@ -2458,7 +2455,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec std::is_same::value, int > = 0 > IteratorType erase(IteratorType pos) // NOLINT(performance-unnecessary-value-param) { - // make sure the iterator fits the current value + // make sure iterator fits the current value if (JSON_HEDLEY_UNLIKELY(this != pos.m_object)) { JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", this)); @@ -2528,7 +2525,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec std::is_same::value, int > = 0 > IteratorType erase(IteratorType first, IteratorType last) // NOLINT(performance-unnecessary-value-param) { - // make sure the iterator fits the current value + // make sure iterator fits the current value if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object)) { JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value", this)); @@ -3123,7 +3120,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this)); } - // transform a null object into an array + // transform null object into an array if (is_null()) { m_data.m_type = value_t::array; @@ -3131,7 +3128,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - // add the element to the array (move semantics) + // add element to array (move semantics) const auto old_capacity = m_data.m_value.array->capacity(); m_data.m_value.array->push_back(std::move(val)); set_parent(m_data.m_value.array->back(), old_capacity); @@ -3156,7 +3153,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this)); } - // transform a null object into an array + // transform null object into an array if (is_null()) { m_data.m_type = value_t::array; @@ -3164,7 +3161,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - // add the element to the array + // add element to array const auto old_capacity = m_data.m_value.array->capacity(); m_data.m_value.array->push_back(val); set_parent(m_data.m_value.array->back(), old_capacity); @@ -3188,7 +3185,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this)); } - // transform a null object into an object + // transform null object into an object if (is_null()) { m_data.m_type = value_t::object; @@ -3196,7 +3193,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - // add the element to the object + // add element to object auto res = m_data.m_value.object->insert(val); set_parent(res.first->second); } @@ -3244,7 +3241,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(311, detail::concat("cannot use emplace_back() with ", type_name()), this)); } - // transform a null object into an array + // transform null object into an array if (is_null()) { m_data.m_type = value_t::array; @@ -3252,7 +3249,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - // add the element to the array (perfect forwarding) + // add element to array (perfect forwarding) const auto old_capacity = m_data.m_value.array->capacity(); m_data.m_value.array->emplace_back(std::forward(args)...); return set_parent(m_data.m_value.array->back(), old_capacity); @@ -3269,7 +3266,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(311, detail::concat("cannot use emplace() with ", type_name()), this)); } - // transform a null object into an object + // transform null object into an object if (is_null()) { m_data.m_type = value_t::object; @@ -3277,11 +3274,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - // add the element to the array (perfect forwarding) + // add element to array (perfect forwarding) auto res = m_data.m_value.object->emplace(std::forward(args)...); set_parent(res.first->second); - // create a result iterator and set iterator to the result of emplace + // create result iterator and set iterator to the result of emplace auto it = begin(); it.m_it.object_iterator = res.first; @@ -3445,7 +3442,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/update/ void update(const_iterator first, const_iterator last, bool merge_objects = false) // NOLINT(performance-unnecessary-value-param) { - // implicitly convert a null value to an empty object + // implicitly convert null value to an empty object if (is_null()) { m_data.m_type = value_t::object; @@ -4005,7 +4002,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/ friend std::ostream& operator<<(std::ostream& o, const basic_json& j) { - // read width member and use it as the indentation parameter if nonzero + // read width member and use it as indentation parameter if nonzero const bool pretty_print = o.width() > 0; const auto indentation = pretty_print ? o.width() : 0; @@ -4046,11 +4043,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec static basic_json parse(InputType&& i, parser_callback_t cb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { basic_json result; - parser(detail::input_adapter(std::forward(i)), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(true, result); // cppcheck-suppress[accessMoved,accessForwarded] + parser(detail::input_adapter(std::forward(i)), std::move(cb), allow_exceptions, ignore_comments).parse(true, result); // cppcheck-suppress[accessMoved,accessForwarded] return result; } @@ -4062,11 +4058,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec IteratorType last, parser_callback_t cb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { basic_json result; - parser(detail::input_adapter(std::move(first), std::move(last)), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(true, result); // cppcheck-suppress[accessMoved] + parser(detail::input_adapter(std::move(first), std::move(last)), std::move(cb), allow_exceptions, ignore_comments).parse(true, result); // cppcheck-suppress[accessMoved] return result; } @@ -4075,11 +4070,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec static basic_json parse(detail::span_input_adapter&& i, parser_callback_t cb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { basic_json result; - parser(i.get(), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(true, result); // cppcheck-suppress[accessMoved] + parser(i.get(), std::move(cb), allow_exceptions, ignore_comments).parse(true, result); // cppcheck-suppress[accessMoved] return result; } @@ -4087,29 +4081,26 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/accept/ template static bool accept(InputType&& i, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { - return parser(detail::input_adapter(std::forward(i)), nullptr, false, ignore_comments, ignore_trailing_commas).accept(true); + return parser(detail::input_adapter(std::forward(i)), nullptr, false, ignore_comments).accept(true); } /// @brief check if the input is valid JSON /// @sa https://json.nlohmann.me/api/basic_json/accept/ template static bool accept(IteratorType first, IteratorType last, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { - return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments, ignore_trailing_commas).accept(true); + return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true); } JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len)) static bool accept(detail::span_input_adapter&& i, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { - return parser(i.get(), nullptr, false, ignore_comments, ignore_trailing_commas).accept(true); + return parser(i.get(), nullptr, false, ignore_comments).accept(true); } /// @brief generate SAX events @@ -4119,12 +4110,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec static bool sax_parse(InputType&& i, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { auto ia = detail::input_adapter(std::forward(i)); return format == input_format_t::json - ? parser(std::move(ia), nullptr, true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict) + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) : detail::binary_reader(std::move(ia), format).sax_parse(format, sax, strict); } @@ -4135,12 +4125,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { auto ia = detail::input_adapter(std::move(first), std::move(last)); return format == input_format_t::json - ? parser(std::move(ia), nullptr, true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict) + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) : detail::binary_reader(std::move(ia), format).sax_parse(format, sax, strict); } @@ -4155,13 +4144,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec static bool sax_parse(detail::span_input_adapter&& i, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { auto ia = i.get(); return format == input_format_t::json // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - ? parser(std::move(ia), nullptr, true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict) + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) : detail::binary_reader(std::move(ia), format).sax_parse(format, sax, strict); } @@ -4216,9 +4204,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec case value_t::number_integer: case value_t::number_unsigned: case value_t::number_float: - return "number"; default: - return "invalid"; + return "number"; } } @@ -4810,7 +4797,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec result.at(top_pointer); } - // get reference to the parent of the JSON pointer ptr + // get reference to parent of JSON pointer ptr const auto last_path = ptr.back(); ptr.pop_back(); // parent must exist when performing patch add per RFC6902 specs @@ -4848,7 +4835,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec break; } - // if there exists a parent, it cannot be primitive + // if there exists a parent it cannot be primitive case value_t::string: // LCOV_EXCL_LINE case value_t::boolean: // LCOV_EXCL_LINE case value_t::number_integer: // LCOV_EXCL_LINE @@ -4864,7 +4851,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // wrapper for "remove" operation; remove value at ptr const auto operation_remove = [this, & result](json_pointer & ptr) { - // get reference to the parent of the JSON pointer ptr + // get reference to parent of JSON pointer ptr const auto last_path = ptr.back(); ptr.pop_back(); basic_json& parent = result.at(ptr); @@ -4910,14 +4897,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // context-sensitive error message const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\''); // NOLINT(bugprone-unused-local-non-trivial-variable) - // check if the desired value is present + // check if desired value is present if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end())) { // NOLINTNEXTLINE(performance-inefficient-string-concatenation) JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg, " must have member '", member, "'"), &val)); } - // check if the result is of type string + // check if result is of type string if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string())) { // NOLINTNEXTLINE(performance-inefficient-string-concatenation) @@ -5006,7 +4993,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // ignore out of range errors: success remains false } - // throw an exception if the test fails + // throw an exception if test fails if (JSON_HEDLEY_UNLIKELY(!success)) { JSON_THROW(other_error::create(501, detail::concat("unsuccessful: ", val.dump()), &val)); @@ -5044,7 +5031,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // the patch basic_json result(value_t::array); - // if the values are the same, return an empty patch + // if the values are the same, return empty patch if (source == target) { return result; @@ -5158,7 +5145,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec case value_t::discarded: default: { - // both primitive types: replace value + // both primitive type: replace value result.push_back( { {"op", "replace"}, {"path", path}, {"value", target} diff --git a/nlohmann_json/include/nlohmann/ordered_map.hpp b/nlohmann_json/include/nlohmann/ordered_map.hpp index 2a293fc9..d830c6d7 100644 --- a/nlohmann_json/include/nlohmann/ordered_map.hpp +++ b/nlohmann_json/include/nlohmann/ordered_map.hpp @@ -226,7 +226,7 @@ template , // Since we cannot move const Keys, we re-construct them in place. // We start at first and re-construct (viz. copy) the elements from - // the back of the vector. Example for the first iteration: + // the back of the vector. Example for first iteration: // ,--------. // v | destroy e and re-construct with h diff --git a/nlohmann_json/single_include/nlohmann/json.hpp b/nlohmann_json/single_include/nlohmann/json.hpp index 919b5fc4..82d69f7c 100644 --- a/nlohmann_json/single_include/nlohmann/json.hpp +++ b/nlohmann_json/single_include/nlohmann/json.hpp @@ -173,6 +173,9 @@ #include // forward_list #include // inserter, front_inserter, end #include // map +#ifdef JSON_HAS_CPP_17 + #include // optional +#endif #include // string #include // tuple, make_tuple #include // is_arithmetic, is_same, is_enum, underlying_type, is_convertible @@ -2394,15 +2397,9 @@ JSON_HEDLEY_DIAGNOSTIC_POP #endif // C++ language standard detection -// if the user manually specified the used C++ version, this is skipped -#if !defined(JSON_HAS_CPP_26) && !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) - #if (defined(__cplusplus) && __cplusplus > 202302L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202302L) - #define JSON_HAS_CPP_26 - #define JSON_HAS_CPP_23 - #define JSON_HAS_CPP_20 - #define JSON_HAS_CPP_17 - #define JSON_HAS_CPP_14 - #elif (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L) +// if the user manually specified the used c++ version this is skipped +#if !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) + #if (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L) #define JSON_HAS_CPP_23 #define JSON_HAS_CPP_20 #define JSON_HAS_CPP_17 @@ -2497,7 +2494,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP #endif #ifndef JSON_HAS_RANGES - // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error + // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 #define JSON_HAS_RANGES 0 #elif defined(__cpp_lib_ranges) @@ -2574,7 +2571,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP #define JSON_ASSERT(x) assert(x) #endif -// allow accessing some private functions (needed by the test suite) +// allow to access some private functions (needed by the test suite) #if defined(JSON_TESTS_PRIVATE) #define JSON_PRIVATE_UNLESS_TESTED public #else @@ -3102,10 +3099,10 @@ inline void replace_substring(StringType& s, const StringType& f, const StringType& t) { JSON_ASSERT(!f.empty()); - for (auto pos = s.find(f); // find the first occurrence of f + for (auto pos = s.find(f); // find first occurrence of f pos != StringType::npos; // make sure f was found s.replace(pos, f.size(), t), // replace with t, and - pos = s.find(f, pos + t.size())) // find the next occurrence of f + pos = s.find(f, pos + t.size())) // find next occurrence of f {} } @@ -3132,7 +3129,7 @@ inline StringType escape(StringType s) * Note the order of escaping "~1" to "/" and "~0" to "~" is important. */ template -inline void unescape(StringType& s) +static void unescape(StringType& s) { replace_substring(s, StringType{"~1"}, StringType{"/"}); replace_substring(s, StringType{"~0"}, StringType{"~"}); @@ -3373,9 +3370,7 @@ NLOHMANN_JSON_NAMESPACE_END #include // tuple #include // false_type, is_constructible, is_integral, is_same, true_type #include // declval -#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L - #include // byte -#endif + // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ @@ -3585,12 +3580,12 @@ namespace detail // Note to maintainers: // -// Every trait in this file expects a non-CV-qualified type. +// Every trait in this file expects a non CV-qualified type. // The only exceptions are in the 'aliases for detected' section -// (i.e., those of the form: decltype(T::member_function(std::declval()))) +// (i.e. those of the form: decltype(T::member_function(std::declval()))) // // In this case, T has to be properly CV-qualified to constraint the function arguments -// (e.g., to_json(BasicJsonType&, const T&)) +// (e.g. to_json(BasicJsonType&, const T&)) template struct is_basic_json : std::false_type {}; @@ -3598,7 +3593,7 @@ NLOHMANN_BASIC_JSON_TPL_DECLARATION struct is_basic_json : std::true_type {}; // used by exceptions create() member functions -// true_type for the pointer to possibly cv-qualified basic_json or std::nullptr_t +// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t // false_type otherwise template struct is_basic_json_context : @@ -3784,30 +3779,6 @@ struct char_traits : std::char_traits } }; -#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L -template<> -struct char_traits : std::char_traits -{ - using char_type = std::byte; - using int_type = uint64_t; - - static int_type to_int_type(char_type c) noexcept - { - return static_cast(std::to_integer(c)); - } - - static char_type to_char_type(int_type i) noexcept - { - return std::byte(static_cast(i)); - } - - static constexpr int_type eof() noexcept - { - return static_cast(std::char_traits::eof()); - } -}; -#endif - /////////////////// // is_ functions // /////////////////// @@ -3824,7 +3795,7 @@ template struct negation : std::integral_constant < bool, !B::value > { // Reimplementation of is_constructible and is_default_constructible, due to them being broken for // std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367). -// This causes compile errors in e.g., Clang 3.5 or GCC 4.9. +// This causes compile errors in e.g. clang 3.5 or gcc 4.9. template struct is_default_constructible : std::is_default_constructible {}; @@ -3904,7 +3875,7 @@ using range_value_t = value_type_t>>; // The following implementation of is_complete_type is taken from // https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ -// and is written by Xiang Fan who agreed to use it in this library. +// and is written by Xiang Fan who agreed to using it in this library. template struct is_complete_type : std::false_type {}; @@ -4141,7 +4112,7 @@ decltype(std::declval()(std::declval(), std::declval())) template using detect_is_transparent = typename T::is_transparent; -// type trait to check if KeyType can be used as an object key (without a BasicJsonType) +// type trait to check if KeyType can be used as object key (without a BasicJsonType) // see is_usable_as_basic_json_key_type below template> @@ -4155,7 +4126,7 @@ using is_usable_as_key_type = typename std::conditional < std::true_type, std::false_type >::type; -// type trait to check if KeyType can be used as an object key +// type trait to check if KeyType can be used as object key // true if: // - KeyType is comparable with BasicJsonType::object_t::key_type // - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type @@ -4519,7 +4490,7 @@ NLOHMANN_JSON_NAMESPACE_END // emitted in every translation unit. This issue cannot be fixed with a // header-only library as there is no implementation file to move these // functions to. As a result, we suppress this warning here to avoid client -// code stumbling over this. See https://github.com/nlohmann/json/issues/4087 +// code to stumble over this. See https://github.com/nlohmann/json/issues/4087 // for a discussion. #if defined(__clang__) #pragma clang diagnostic push @@ -4846,15 +4817,6 @@ NLOHMANN_JSON_NAMESPACE_END // #include -// include after macro_scope.hpp -#ifdef JSON_HAS_CPP_17 - #include // optional -#endif - -#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM - #include // u8string_view -#endif - NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { @@ -4870,6 +4832,7 @@ inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n) } #ifdef JSON_HAS_CPP_17 +#ifndef JSON_USE_IMPLICIT_CONVERSIONS template void from_json(const BasicJsonType& j, std::optional& opt) { @@ -4882,6 +4845,8 @@ void from_json(const BasicJsonType& j, std::optional& opt) opt.emplace(j.template get()); } } + +#endif // JSON_USE_IMPLICIT_CONVERSIONS #endif // JSON_HAS_CPP_17 // overloads for basic_json template parameters @@ -5215,7 +5180,7 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) } // overload for arithmetic types, not chosen for basic_json template arguments -// (BooleanType, etc.); note: Is it really necessary to provide explicit +// (BooleanType, etc..); note: Is it really necessary to provide explicit // overloads for boolean_t etc. in case of a custom BooleanType which is not // an arithmetic type? template < typename BasicJsonType, typename ArithmeticType, @@ -5360,10 +5325,7 @@ inline void from_json(const BasicJsonType& j, std_fs::path& p) JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j)); } const auto& s = *j.template get_ptr(); - // Checking for C++20 standard or later can be insufficient in case the - // library support for char8_t is either incomplete or was disabled - // altogether. Use the __cpp_lib_char8_t feature test instead. -#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L) +#ifdef JSON_HAS_CPP_20 p = std_fs::path(std::u8string_view(reinterpret_cast(s.data()), s.size())); #else p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20 @@ -5418,8 +5380,7 @@ NLOHMANN_JSON_NAMESPACE_END #include // copy #include // begin, end -#include // allocator_traits -#include // basic_string, char_traits +#include // string #include // tuple, get #include // is_same, is_constructible, is_floating_point, is_enum, underlying_type #include // move, forward, declval, pair @@ -5953,7 +5914,7 @@ struct external_constructor #ifdef JSON_HAS_CPP_17 template::value, int> = 0> -void to_json(BasicJsonType& j, const std::optional& opt) noexcept +void to_json(BasicJsonType& j, const std::optional& opt) { if (opt.has_value()) { @@ -6126,21 +6087,15 @@ inline void to_json(BasicJsonType& j, const T& t) } #if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM -#if defined(__cpp_lib_char8_t) -template -inline void to_json(BasicJsonType& j, const std::basic_string& s) -{ - using OtherAllocator = typename std::allocator_traits::template rebind_alloc; - j = std::basic_string, OtherAllocator>(s.begin(), s.end(), s.get_allocator()); -} -#endif - template inline void to_json(BasicJsonType& j, const std_fs::path& p) { - // Returns either a std::string or a std::u8string depending whether library - // support for char8_t is enabled. - j = p.u8string(); +#ifdef JSON_HAS_CPP_20 + const std::u8string s = p.u8string(); + j = std::string(s.begin(), s.end()); +#else + j = p.u8string(); // returns std::string in C++17 +#endif } #endif @@ -6601,7 +6556,7 @@ class input_stream_adapter : is(&i), sb(i.rdbuf()) {} - // deleted because of pointer members + // delete because of pointer members input_stream_adapter(const input_stream_adapter&) = delete; input_stream_adapter& operator=(input_stream_adapter&) = delete; input_stream_adapter& operator=(input_stream_adapter&&) = delete; @@ -6615,7 +6570,7 @@ class input_stream_adapter // std::istream/std::streambuf use std::char_traits::to_int_type, to // ensure that std::char_traits::eof() and the character 0xFF do not - // end up as the same value, e.g., 0xFFFFFFFF. + // end up as the same value, e.g. 0xFFFFFFFF. std::char_traits::int_type get_character() { auto res = sb->sbumpc(); @@ -6837,7 +6792,7 @@ class wide_string_input_adapter typename std::char_traits::int_type get_character() noexcept { - // check if the buffer needs to be filled + // check if buffer needs to be filled if (utf8_bytes_index == utf8_bytes_filled) { fill_buffer(); @@ -7194,7 +7149,7 @@ class lexer : public lexer_base , decimal_point_char(static_cast(get_decimal_point())) {} - // deleted because of pointer members + // delete because of pointer members lexer(const lexer&) = delete; lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) lexer& operator=(lexer&) = delete; @@ -7329,10 +7284,10 @@ class lexer : public lexer_base while (true) { - // get the next character + // get next character switch (get()) { - // end of file while parsing the string + // end of file while parsing string case char_traits::eof(): { error_message = "invalid string: missing closing quote"; @@ -7418,7 +7373,7 @@ class lexer : public lexer_base (static_cast(codepoint1) << 10u) // low surrogate occupies the least significant 15 bits + static_cast(codepoint2) - // there is still the 0xD800, 0xDC00, and 0x10000 noise + // there is still the 0xD800, 0xDC00 and 0x10000 noise // in the result, so we have to subtract with: // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 - 0x35FDC00u); @@ -7444,7 +7399,7 @@ class lexer : public lexer_base } } - // the result of the above calculation yields a proper codepoint + // result of the above calculation yields a proper codepoint JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF); // translate codepoint into bytes @@ -7895,7 +7850,7 @@ class lexer : public lexer_base break; } - // the remaining bytes (80..C1 and F5..FF) are ill-formed + // remaining bytes (80..C1 and F5..FF) are ill-formed default: { error_message = "invalid string: ill-formed UTF-8 byte"; @@ -8040,7 +7995,7 @@ class lexer : public lexer_base reset(); // the type of the parsed number; initially set to unsigned; will be - // changed if minus sign, decimal point, or exponent is read + // changed if minus sign, decimal point or exponent is read token_type number_type = token_type::value_unsigned; // state (init): we just found out we need to scan a number @@ -8412,7 +8367,7 @@ class lexer : public lexer_base if (next_unget) { - // only reset the next_unget variable and work with current + // just reset the next_unget variable and work with current next_unget = false; } else @@ -8591,7 +8546,7 @@ class lexer : public lexer_base return token_type::parse_error; } - // read the next character and ignore whitespace + // read next character and ignore whitespace skip_whitespace(); // ignore comments @@ -8955,7 +8910,7 @@ class json_sax_dom_parser JSON_ASSERT(!ref_stack.empty()); JSON_ASSERT(ref_stack.back()->is_object()); - // add null at the given key and store the reference for later + // add null at given key and store the reference for later object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val)); return true; } @@ -9271,11 +9226,11 @@ class json_sax_dom_callback_parser { BasicJsonType k = BasicJsonType(val); - // check callback for the key + // check callback for key const bool keep = callback(static_cast(ref_stack.size()), parse_event_t::key, k); key_keep_stack.push_back(keep); - // add discarded value at the given key and store the reference for later + // add discarded value at given key and store the reference for later if (keep && ref_stack.back()) { object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) = discarded); @@ -9874,7 +9829,7 @@ enum class cbor_tag_handler_t @note from https://stackoverflow.com/a/1001328/266378 */ -inline bool little_endianness(int num = 1) noexcept +static inline bool little_endianness(int num = 1) noexcept { return *reinterpret_cast(&num) == 1; } @@ -10155,7 +10110,7 @@ class binary_reader return get_number(input_format_t::bson, value) && sax->number_unsigned(value); } - default: // anything else is not supported (yet) + default: // anything else not supported (yet) { std::array cr{{}}; static_cast((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) @@ -10552,7 +10507,7 @@ class binary_reader case 0xD2: case 0xD3: case 0xD4: - case 0xD8: // tagged item (1 byte follows) + case 0xD8: // tagged item (1 bytes follow) case 0xD9: // tagged item (2 bytes follow) case 0xDA: // tagged item (4 bytes follow) case 0xDB: // tagged item (8 bytes follow) @@ -10604,7 +10559,7 @@ class binary_reader case cbor_tag_handler_t::store: { binary_t b; - // use binary subtype and store in a binary container + // use binary subtype and store in binary container switch (current) { case 0xD8: @@ -10673,7 +10628,7 @@ class binary_reader const auto byte1 = static_cast(byte1_raw); const auto byte2 = static_cast(byte2_raw); - // Code from RFC 7049, Appendix D, Figure 3: + // code from RFC 7049, Appendix D, Figure 3: // As half-precision floating-point numbers were only added // to IEEE 754 in 2008, today's programming platforms often // still only have limited support for them. It is very @@ -11980,7 +11935,7 @@ class binary_reader { break; } - if (is_ndarray) // ndarray dimensional vector can only contain integers and cannot embed another array + if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array { return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr)); } @@ -12013,16 +11968,8 @@ class binary_reader result = 1; for (auto i : dim) { - // Pre-multiplication overflow check: if i > 0 and result > SIZE_MAX/i, then result*i would overflow. - // This check must happen before multiplication since overflow detection after the fact is unreliable - // as modular arithmetic can produce any value, not just 0 or SIZE_MAX. - if (JSON_HEDLEY_UNLIKELY(i > 0 && result > (std::numeric_limits::max)() / i)) - { - return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr)); - } result *= i; - // Additional post-multiplication check to catch any edge cases the pre-check might miss - if (result == 0 || result == npos) + if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type() { return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr)); } @@ -12238,7 +12185,7 @@ class binary_reader const auto byte1 = static_cast(byte1_raw); const auto byte2 = static_cast(byte2_raw); - // Code from RFC 7049, Appendix D, Figure 3: + // code from RFC 7049, Appendix D, Figure 3: // As half-precision floating-point numbers were only added // to IEEE 754 in 2008, today's programming platforms often // still only have limited support for them. It is very @@ -12526,7 +12473,7 @@ class binary_reader bool get_ubjson_high_precision_number() { - // get the size of the following number string + // get size of following number string std::size_t size{}; bool no_ndarray = true; auto res = get_ubjson_size_value(size, no_ndarray); @@ -12624,7 +12571,7 @@ class binary_reader chars_read += new_chars_read; if (JSON_HEDLEY_UNLIKELY(new_chars_read < sizeof(T))) { - // in case of failure, advance position by 1 to report the failing location + // in case of failure, advance position by 1 to report failing location ++chars_read; sax->parse_error(chars_read, "", parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr)); return false; @@ -12655,22 +12602,17 @@ class binary_reader { return; } - else if constexpr(std::is_integral_v) + if constexpr(std::is_integral_v) { number = std::byteswap(number); return; } - else - { #endif - auto* ptr = reinterpret_cast(&number); - for (std::size_t i = 0; i < sz / 2; ++i) - { - std::swap(ptr[i], ptr[sz - i - 1]); - } -#ifdef __cpp_lib_byteswap + auto* ptr = reinterpret_cast(&number); + for (std::size_t i = 0; i < sz / 2; ++i) + { + std::swap(ptr[i], ptr[sz - i - 1]); } -#endif } /* @@ -12765,7 +12707,7 @@ class binary_reader success = false; break; } - result.push_back(static_cast(current)); + result.push_back(static_cast(current)); } return success; } @@ -12987,12 +12929,10 @@ class parser explicit parser(InputAdapterType&& adapter, parser_callback_t cb = nullptr, const bool allow_exceptions_ = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas_ = false) + const bool skip_comments = false) : callback(std::move(cb)) - , m_lexer(std::move(adapter), ignore_comments) + , m_lexer(std::move(adapter), skip_comments) , allow_exceptions(allow_exceptions_) - , ignore_trailing_commas(ignore_trailing_commas_) { // read first token get_token(); @@ -13024,7 +12964,7 @@ class parser exception_message(token_type::end_of_input, "value"), nullptr)); } - // in case of an error, return a discarded value + // in case of an error, return discarded value if (sdp.is_errored()) { result = value_t::discarded; @@ -13051,7 +12991,7 @@ class parser parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr)); } - // in case of an error, return a discarded value + // in case of an error, return discarded value if (sdp.is_errored()) { result = value_t::discarded; @@ -13254,7 +13194,7 @@ class parser case token_type::parse_error: { - // using "uninitialized" to avoid an "expected" message + // using "uninitialized" to avoid "expected" message return sax->parse_error(m_lexer.get_position(), m_lexer.get_token_string(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), nullptr)); @@ -13302,17 +13242,11 @@ class parser if (states.back()) // array { // comma -> next value - // or end of array (ignore_trailing_commas = true) if (get_token() == token_type::value_separator) { // parse a new value get_token(); - - // if ignore_trailing_commas and last_token is ], we can continue to "closing ]" - if (!(ignore_trailing_commas && last_token == token_type::end_array)) - { - continue; - } + continue; } // closing ] @@ -13341,39 +13275,32 @@ class parser // states.back() is false -> object // comma -> next value - // or end of object (ignore_trailing_commas = true) if (get_token() == token_type::value_separator) { - get_token(); - - // if ignore_trailing_commas and last_token is }, we can continue to "closing }" - if (!(ignore_trailing_commas && last_token == token_type::end_object)) + // parse key + if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string)) { - // parse key - if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string)) - { - return sax->parse_error(m_lexer.get_position(), - m_lexer.get_token_string(), - parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr)); - } - - if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) - { - return false; - } + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr)); + } - // parse separator (:) - if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) - { - return sax->parse_error(m_lexer.get_position(), - m_lexer.get_token_string(), - parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr)); - } + if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) + { + return false; + } - // parse values - get_token(); - continue; + // parse separator (:) + if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) + { + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr)); } + + // parse values + get_token(); + continue; } // closing } @@ -13444,8 +13371,6 @@ class parser lexer_t m_lexer; /// whether to throw exceptions in case of errors const bool allow_exceptions = true; - /// whether trailing commas in objects and arrays should be ignored (true) or signaled as errors (false) - const bool ignore_trailing_commas = false; }; } // namespace detail @@ -13489,9 +13414,9 @@ namespace detail @brief an iterator for primitive JSON types This class models an iterator for primitive JSON types (boolean, number, -string). Its only purpose is to allow the iterator/const_iterator classes +string). It's only purpose is to allow the iterator/const_iterator classes to "iterate" over primitive values. Internally, the iterator is modeled by -a `difference_type` variable. Value begin_value (`0`) models the begin and +a `difference_type` variable. Value begin_value (`0`) models the begin, end_value (`1`) models past the end. */ class primitive_iterator_t @@ -13656,7 +13581,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { -// forward declare to be able to friend it later on +// forward declare, to be able to friend it later on template class iteration_proxy; template class iteration_proxy_value; @@ -14864,7 +14789,7 @@ class json_pointer { if (reference_token == "0") { - // start a new array if the reference token is 0 + // start a new array if reference token is 0 result = &result->operator[](0); } else @@ -14893,7 +14818,7 @@ class json_pointer The following code is only reached if there exists a reference token _and_ the current value is primitive. In this case, we have an error situation, because primitive values may only occur as - a single value; that is, with an empty list of reference tokens. + single value; that is, with an empty list of reference tokens. */ case detail::value_t::string: case detail::value_t::boolean: @@ -14937,7 +14862,7 @@ class json_pointer // convert null values to arrays or objects before continuing if (ptr->is_null()) { - // check if the reference token is a number + // check if reference token is a number const bool nums = std::all_of(reference_token.begin(), reference_token.end(), [](const unsigned char x) @@ -14945,7 +14870,7 @@ class json_pointer return std::isdigit(x); }); - // change value to an array for numbers or "-" or to object otherwise + // change value to array for numbers or "-" or to object otherwise *ptr = (nums || reference_token == "-") ? detail::value_t::array : detail::value_t::object; @@ -15188,7 +15113,7 @@ class json_pointer { if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9'))) { - // the first char should be between '1' and '9' + // first char should be between '1' and '9' return false; } for (std::size_t i = 1; i < reference_token.size(); i++) @@ -15252,7 +15177,7 @@ class json_pointer return result; } - // check if a nonempty reference string begins with slash + // check if nonempty reference string begins with slash if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/')) { JSON_THROW(detail::parse_error::create(107, 1, detail::concat("JSON pointer must be empty or begin with '/' - was: '", reference_string, "'"), nullptr)); @@ -15326,7 +15251,7 @@ class json_pointer } else { - // iterate array and use index as a reference string + // iterate array and use index as reference string for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i) { flatten(detail::concat(reference_string, '/', std::to_string(i)), @@ -15364,7 +15289,7 @@ class json_pointer case detail::value_t::discarded: default: { - // add a primitive value with its reference string + // add primitive value with its reference string result[reference_string] = value; break; } @@ -15400,17 +15325,17 @@ class json_pointer JSON_THROW(detail::type_error::create(315, "values in object must be primitive", &element.second)); } - // Assign the value to the reference pointed to by JSON pointer. Note - // that if the JSON pointer is "" (i.e., points to the whole value), - // function get_and_create returns a reference to the result itself. - // An assignment will then create a primitive value. + // assign value to reference pointed to by JSON pointer; Note that if + // the JSON pointer is "" (i.e., points to the whole value), function + // get_and_create returns a reference to result itself. An assignment + // will then create a primitive value. json_pointer(element.first).get_and_create(result) = element.second; } return result; } - // can't use the conversion operator because of ambiguity + // can't use conversion operator because of ambiguity json_pointer convert() const& { json_pointer result; @@ -15505,7 +15430,7 @@ class json_pointer }; #if !JSON_HAS_THREE_WAY_COMPARISON -// functions cannot be defined inside the class due to ODR violations +// functions cannot be defined inside class due to ODR violations template inline bool operator==(const json_pointer& lhs, const json_pointer& rhs) noexcept @@ -16788,9 +16713,9 @@ class binary_writer if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos)) { JSON_THROW(out_of_range::create(409, concat("BSON key cannot contain code point U+0000 (at byte ", std::to_string(it), ")"), &j)); + static_cast(j); } - static_cast(j); return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; } @@ -17367,7 +17292,7 @@ class binary_writer { return 'L'; } - // anything else is treated as a high-precision number + // anything else is treated as high-precision number return 'H'; // LCOV_EXCL_LINE } @@ -17405,7 +17330,7 @@ class binary_writer { return 'M'; } - // anything else is treated as a high-precision number + // anything else is treated as high-precision number return 'H'; // LCOV_EXCL_LINE } @@ -17571,11 +17496,11 @@ class binary_writer template void write_number(const NumberType n, const bool OutputIsLittleEndian = false) { - // step 1: write the number to an array of length NumberType + // step 1: write number to array of length NumberType std::array vec{}; std::memcpy(vec.data(), &n, sizeof(NumberType)); - // step 2: write the array to output (with possible reordering) + // step 2: write array to output (with possible reordering) if (is_little_endian != OutputIsLittleEndian) { // reverse byte order prior to conversion if necessary @@ -17591,9 +17516,9 @@ class binary_writer #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wfloat-equal" #endif - if (!std::isfinite(n) || ((static_cast(n) >= static_cast(std::numeric_limits::lowest()) && - static_cast(n) <= static_cast((std::numeric_limits::max)()) && - static_cast(static_cast(n)) == static_cast(n)))) + if (static_cast(n) >= static_cast(std::numeric_limits::lowest()) && + static_cast(n) <= static_cast((std::numeric_limits::max)()) && + static_cast(static_cast(n)) == static_cast(n)) { oa->write_character(format == detail::input_format_t::cbor ? get_cbor_float_prefix(static_cast(n)) @@ -17628,21 +17553,8 @@ class binary_writer enable_if_t < std::is_signed::value && std::is_unsigned::value > * = nullptr > static CharType to_char_type(std::uint8_t x) noexcept { - // The std::is_trivial trait is deprecated in C++26. The replacement is to use - // std::is_trivially_copyable and std::is_trivially_default_constructible. - // However, some older library implementations support std::is_trivial - // but not all the std::is_trivially_* traits. - // Since detecting full support across all libraries is difficult, - // we use std::is_trivial unless we are using a standard where it has been deprecated. - // For more details, see: https://github.com/nlohmann/json/pull/4775#issuecomment-2884361627 -#ifdef JSON_HAS_CPP_26 - static_assert(std::is_trivially_copyable::value, "CharType must be trivially copyable"); - static_assert(std::is_trivially_default_constructible::value, "CharType must be trivially default constructible"); -#else - static_assert(std::is_trivial::value, "CharType must be trivial"); -#endif - static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t"); + static_assert(std::is_trivial::value, "CharType must be trivial"); CharType result; std::memcpy(&result, &x, sizeof(x)); return result; @@ -17838,7 +17750,7 @@ struct diyfp // f * 2^e // p_lo = p0_lo + (Q << 32) // // But in this particular case here, the full p_lo is not required. - // Effectively, we only need to add the highest bit in p_lo to p_hi (and + // Effectively we only need to add the highest bit in p_lo to p_hi (and // Q_hi + 1 does not overflow). Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up @@ -17928,7 +17840,7 @@ boundaries compute_boundaries(FloatType value) // Compute the boundaries m- and m+ of the floating-point value // v = f * 2^e. // - // Determine v- and v+, the floating-point predecessor and successor of v, + // Determine v- and v+, the floating-point predecessor and successor if v, // respectively. // // v- = v - 2^e if f != 2^(p-1) or e == e_min (A) @@ -18083,7 +17995,7 @@ inline cached_power get_cached_power_for_binary_exponent(int e) // (A smaller distance gamma-alpha would require a larger table.) // NB: - // Actually, this function returns c, such that -60 <= e_c + e + 64 <= -34. + // Actually this function returns c, such that -60 <= e_c + e + 64 <= -34. constexpr int kCachedPowersMinDecExp = -300; constexpr int kCachedPowersDecStep = 8; @@ -18395,8 +18307,8 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, decimal_exponent += n; - // We may now just stop. But instead, it looks as if the buffer - // could be decremented to bring V closer to w. + // We may now just stop. But instead look if the buffer could be + // decremented to bring V closer to w. // // pow10 = 10^n is now 1 ulp in the decimal representation V. // The rounding procedure works with diyfp's with an implicit @@ -18803,7 +18715,7 @@ char* to_chars(char* first, const char* last, FloatType value) // Compute v = buffer * 10^decimal_exponent. // The decimal digits are stored in the buffer, which needs to be interpreted // as an unsigned decimal integer. - // len is the length of the buffer, i.e., the number of decimal digits. + // len is the length of the buffer, i.e. the number of decimal digits. int len = 0; int decimal_exponent = 0; dtoa_impl::grisu2(first, len, decimal_exponent, value); @@ -18884,7 +18796,7 @@ class serializer , error_handler(error_handler_) {} - // deleted because of pointer members + // delete because of pointer members serializer(const serializer&) = delete; serializer& operator=(const serializer&) = delete; serializer(serializer&&) = delete; @@ -19382,7 +19294,7 @@ class serializer break; } - default: // decode found yet incomplete multibyte code point + default: // decode found yet incomplete multi-byte code point { if (!ensure_ascii) { @@ -19571,7 +19483,7 @@ class serializer // jump to the end to generate the string from backward, // so we later avoid reversing the result - buffer_ptr += static_cast(n_chars); + buffer_ptr += n_chars; // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu // See: https://www.youtube.com/watch?v=o4-CwDo2zpg @@ -19636,7 +19548,7 @@ class serializer void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/) { - // get the number of digits for a float -> text -> float round-trip + // get number of digits for a float -> text -> float round-trip static constexpr auto d = std::numeric_limits::max_digits10; // the actual conversion @@ -19645,10 +19557,10 @@ class serializer // negative value indicates an error JSON_ASSERT(len > 0); - // check if the buffer was large enough + // check if buffer was large enough JSON_ASSERT(static_cast(len) < number_buffer.size()); - // erase thousands separators + // erase thousands separator if (thousands_sep != '\0') { // NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::remove returns an iterator, see https://github.com/nlohmann/json/issues/3081 @@ -19756,8 +19668,8 @@ class serializer * Helper function for dump_integer * * This function takes a negative signed integer and returns its absolute - * value as an unsigned integer. The plus/minus shuffling is necessary as we - * cannot directly remove the sign of an arbitrary signed integer as the + * value as unsigned integer. The plus/minus shuffling is necessary as we can + * not directly remove the sign of an arbitrary signed integer as the * absolute values of INT_MIN and INT_MAX are usually not the same. See * #1708 for details. */ @@ -20031,7 +19943,7 @@ template , // Since we cannot move const Keys, we re-construct them in place. // We start at first and re-construct (viz. copy) the elements from - // the back of the vector. Example for the first iteration: + // the back of the vector. Example for first iteration: // ,--------. // v | destroy e and re-construct with h @@ -20236,12 +20148,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec InputAdapterType adapter, detail::parser_callback_tcb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false + const bool ignore_comments = false ) { return ::nlohmann::detail::parser(std::move(adapter), - std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas); + std::move(cb), allow_exceptions, ignore_comments); } private: @@ -20666,7 +20577,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec (t == value_t::binary && binary == nullptr) ) { - // not initialized (e.g., due to exception in the ctor) + //not initialized (e.g. due to exception in the ctor) return; } if (t == value_t::array || t == value_t::object) @@ -20691,7 +20602,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec while (!stack.empty()) { - // move the last item to a local variable to be processed + // move the last item to local variable to be processed basic_json current_item(std::move(stack.back())); stack.pop_back(); @@ -20713,7 +20624,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec current_item.m_data.m_value.object->clear(); } - // it's now safe that current_item gets destructed + // it's now safe that current_item get destructed // since it doesn't have any children } } @@ -21021,20 +20932,20 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { // The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int; // (many string types can be constructed from 0 via its null-pointer guise, so we get a - // broken call to op[key_type], the wrong semantics, and a 4804 warning on Windows) + // broken call to op[key_type], the wrong semantics and a 4804 warning on Windows) return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast(0)].is_string(); }); // adjust type if type deduction is not wanted if (!type_deduction) { - // if an array is wanted, do not create an object though possible + // if array is wanted, do not create an object though possible if (manual_type == value_t::array) { is_an_object = false; } - // if an object is wanted but impossible, throw an exception + // if object is wanted but impossible, throw an exception if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object)) { JSON_THROW(type_error::create(301, "cannot create object from initializer list", nullptr)); @@ -21043,7 +20954,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (is_an_object) { - // the initializer list is a list of pairs -> create an object + // the initializer list is a list of pairs -> create object m_data.m_type = value_t::object; m_data.m_value = value_t::object; @@ -21057,7 +20968,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } else { - // the initializer list describes an array -> create an array + // the initializer list describes an array -> create array m_data.m_type = value_t::array; m_data.m_value.array = create(init.begin(), init.end()); } @@ -21145,16 +21056,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_ASSERT(first.m_object != nullptr); JSON_ASSERT(last.m_object != nullptr); - // make sure the iterator fits the current value + // make sure iterator fits the current value if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) { JSON_THROW(invalid_iterator::create(201, "iterators are not compatible", nullptr)); } - // copy type from the first iterator + // copy type from first iterator m_data.m_type = first.m_object->m_data.m_type; - // check if the iterator range is complete for primitive values + // check if iterator range is complete for primitive values switch (m_data.m_type) { case value_t::boolean: @@ -21334,7 +21245,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec , end_position(other.end_position) // cppcheck-suppress[accessForwarded] TODO check #endif { - // check that the passed value is valid + // check that passed value is valid other.assert_invariant(false); // cppcheck-suppress[accessForwarded] // invalidate payload @@ -21360,7 +21271,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec std::is_nothrow_move_assignable::value ) { - // check that the passed value is valid + // check that passed value is valid other.assert_invariant(); using std::swap; @@ -22076,7 +21987,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } JSON_CATCH (std::out_of_range&) { - // create a better exception explanation + // create better exception explanation JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); } // cppcheck-suppress[missingReturn] } @@ -22099,7 +22010,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } JSON_CATCH (std::out_of_range&) { - // create a better exception explanation + // create better exception explanation JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); } // cppcheck-suppress[missingReturn] } @@ -22189,7 +22100,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ reference operator[](size_type idx) { - // implicitly convert a null value to an empty array + // implicitly convert null value to an empty array if (is_null()) { m_data.m_type = value_t::array; @@ -22200,7 +22111,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // operator[] only works for arrays if (JSON_HEDLEY_LIKELY(is_array())) { - // fill up the array with null values if given idx is outside the range + // fill up array with null values if given idx is outside range if (idx >= m_data.m_value.array->size()) { #if JSON_DIAGNOSTICS @@ -22248,7 +22159,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ reference operator[](typename object_t::key_type key) // NOLINT(performance-unnecessary-value-param) { - // implicitly convert a null value to an empty object + // implicitly convert null value to an empty object if (is_null()) { m_data.m_type = value_t::object; @@ -22301,7 +22212,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::is_usable_as_basic_json_key_type::value, int > = 0 > reference operator[](KeyType && key) { - // implicitly convert a null value to an empty object + // implicitly convert null value to an empty object if (is_null()) { m_data.m_type = value_t::object; @@ -22358,7 +22269,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If 'key' is found, return its value. Otherwise, return `default_value'. + // if key is found, return value and given default value otherwise const auto it = find(key); if (it != end()) { @@ -22383,7 +22294,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If 'key' is found, return its value. Otherwise, return `default_value'. + // if key is found, return value and given default value otherwise const auto it = find(key); if (it != end()) { @@ -22409,7 +22320,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If 'key' is found, return its value. Otherwise, return `default_value'. + // if key is found, return value and given default value otherwise const auto it = find(std::forward(key)); if (it != end()) { @@ -22436,7 +22347,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If 'key' is found, return its value. Otherwise, return `default_value'. + // if key is found, return value and given default value otherwise const auto it = find(std::forward(key)); if (it != end()) { @@ -22459,8 +22370,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If the pointer resolves to a value, return it. Otherwise, return - // 'default_value'. + // if pointer resolves a value, return it or use default value JSON_TRY { return ptr.get_checked(this).template get(); @@ -22485,8 +22395,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - // If the pointer resolves to a value, return it. Otherwise, return - // 'default_value'. + // if pointer resolves a value, return it or use default value JSON_TRY { return ptr.get_checked(this).template get(); @@ -22560,7 +22469,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec std::is_same::value, int > = 0 > IteratorType erase(IteratorType pos) // NOLINT(performance-unnecessary-value-param) { - // make sure the iterator fits the current value + // make sure iterator fits the current value if (JSON_HEDLEY_UNLIKELY(this != pos.m_object)) { JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", this)); @@ -22630,7 +22539,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec std::is_same::value, int > = 0 > IteratorType erase(IteratorType first, IteratorType last) // NOLINT(performance-unnecessary-value-param) { - // make sure the iterator fits the current value + // make sure iterator fits the current value if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object)) { JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value", this)); @@ -23225,7 +23134,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this)); } - // transform a null object into an array + // transform null object into an array if (is_null()) { m_data.m_type = value_t::array; @@ -23233,7 +23142,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - // add the element to the array (move semantics) + // add element to array (move semantics) const auto old_capacity = m_data.m_value.array->capacity(); m_data.m_value.array->push_back(std::move(val)); set_parent(m_data.m_value.array->back(), old_capacity); @@ -23258,7 +23167,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this)); } - // transform a null object into an array + // transform null object into an array if (is_null()) { m_data.m_type = value_t::array; @@ -23266,7 +23175,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - // add the element to the array + // add element to array const auto old_capacity = m_data.m_value.array->capacity(); m_data.m_value.array->push_back(val); set_parent(m_data.m_value.array->back(), old_capacity); @@ -23290,7 +23199,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this)); } - // transform a null object into an object + // transform null object into an object if (is_null()) { m_data.m_type = value_t::object; @@ -23298,7 +23207,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - // add the element to the object + // add element to object auto res = m_data.m_value.object->insert(val); set_parent(res.first->second); } @@ -23346,7 +23255,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(311, detail::concat("cannot use emplace_back() with ", type_name()), this)); } - // transform a null object into an array + // transform null object into an array if (is_null()) { m_data.m_type = value_t::array; @@ -23354,7 +23263,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - // add the element to the array (perfect forwarding) + // add element to array (perfect forwarding) const auto old_capacity = m_data.m_value.array->capacity(); m_data.m_value.array->emplace_back(std::forward(args)...); return set_parent(m_data.m_value.array->back(), old_capacity); @@ -23371,7 +23280,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(311, detail::concat("cannot use emplace() with ", type_name()), this)); } - // transform a null object into an object + // transform null object into an object if (is_null()) { m_data.m_type = value_t::object; @@ -23379,11 +23288,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - // add the element to the array (perfect forwarding) + // add element to array (perfect forwarding) auto res = m_data.m_value.object->emplace(std::forward(args)...); set_parent(res.first->second); - // create a result iterator and set iterator to the result of emplace + // create result iterator and set iterator to the result of emplace auto it = begin(); it.m_it.object_iterator = res.first; @@ -23547,7 +23456,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/update/ void update(const_iterator first, const_iterator last, bool merge_objects = false) // NOLINT(performance-unnecessary-value-param) { - // implicitly convert a null value to an empty object + // implicitly convert null value to an empty object if (is_null()) { m_data.m_type = value_t::object; @@ -24107,7 +24016,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/ friend std::ostream& operator<<(std::ostream& o, const basic_json& j) { - // read width member and use it as the indentation parameter if nonzero + // read width member and use it as indentation parameter if nonzero const bool pretty_print = o.width() > 0; const auto indentation = pretty_print ? o.width() : 0; @@ -24148,11 +24057,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec static basic_json parse(InputType&& i, parser_callback_t cb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { basic_json result; - parser(detail::input_adapter(std::forward(i)), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(true, result); // cppcheck-suppress[accessMoved,accessForwarded] + parser(detail::input_adapter(std::forward(i)), std::move(cb), allow_exceptions, ignore_comments).parse(true, result); // cppcheck-suppress[accessMoved,accessForwarded] return result; } @@ -24164,11 +24072,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec IteratorType last, parser_callback_t cb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { basic_json result; - parser(detail::input_adapter(std::move(first), std::move(last)), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(true, result); // cppcheck-suppress[accessMoved] + parser(detail::input_adapter(std::move(first), std::move(last)), std::move(cb), allow_exceptions, ignore_comments).parse(true, result); // cppcheck-suppress[accessMoved] return result; } @@ -24177,11 +24084,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec static basic_json parse(detail::span_input_adapter&& i, parser_callback_t cb = nullptr, const bool allow_exceptions = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { basic_json result; - parser(i.get(), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(true, result); // cppcheck-suppress[accessMoved] + parser(i.get(), std::move(cb), allow_exceptions, ignore_comments).parse(true, result); // cppcheck-suppress[accessMoved] return result; } @@ -24189,29 +24095,26 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/accept/ template static bool accept(InputType&& i, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { - return parser(detail::input_adapter(std::forward(i)), nullptr, false, ignore_comments, ignore_trailing_commas).accept(true); + return parser(detail::input_adapter(std::forward(i)), nullptr, false, ignore_comments).accept(true); } /// @brief check if the input is valid JSON /// @sa https://json.nlohmann.me/api/basic_json/accept/ template static bool accept(IteratorType first, IteratorType last, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { - return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments, ignore_trailing_commas).accept(true); + return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true); } JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len)) static bool accept(detail::span_input_adapter&& i, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { - return parser(i.get(), nullptr, false, ignore_comments, ignore_trailing_commas).accept(true); + return parser(i.get(), nullptr, false, ignore_comments).accept(true); } /// @brief generate SAX events @@ -24221,12 +24124,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec static bool sax_parse(InputType&& i, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { auto ia = detail::input_adapter(std::forward(i)); return format == input_format_t::json - ? parser(std::move(ia), nullptr, true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict) + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) : detail::binary_reader(std::move(ia), format).sax_parse(format, sax, strict); } @@ -24237,12 +24139,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { auto ia = detail::input_adapter(std::move(first), std::move(last)); return format == input_format_t::json - ? parser(std::move(ia), nullptr, true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict) + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) : detail::binary_reader(std::move(ia), format).sax_parse(format, sax, strict); } @@ -24257,13 +24158,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec static bool sax_parse(detail::span_input_adapter&& i, SAX* sax, input_format_t format = input_format_t::json, const bool strict = true, - const bool ignore_comments = false, - const bool ignore_trailing_commas = false) + const bool ignore_comments = false) { auto ia = i.get(); return format == input_format_t::json // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - ? parser(std::move(ia), nullptr, true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict) + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) : detail::binary_reader(std::move(ia), format).sax_parse(format, sax, strict); } @@ -24318,9 +24218,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec case value_t::number_integer: case value_t::number_unsigned: case value_t::number_float: - return "number"; default: - return "invalid"; + return "number"; } } @@ -24912,7 +24811,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec result.at(top_pointer); } - // get reference to the parent of the JSON pointer ptr + // get reference to parent of JSON pointer ptr const auto last_path = ptr.back(); ptr.pop_back(); // parent must exist when performing patch add per RFC6902 specs @@ -24950,7 +24849,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec break; } - // if there exists a parent, it cannot be primitive + // if there exists a parent it cannot be primitive case value_t::string: // LCOV_EXCL_LINE case value_t::boolean: // LCOV_EXCL_LINE case value_t::number_integer: // LCOV_EXCL_LINE @@ -24966,7 +24865,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // wrapper for "remove" operation; remove value at ptr const auto operation_remove = [this, & result](json_pointer & ptr) { - // get reference to the parent of the JSON pointer ptr + // get reference to parent of JSON pointer ptr const auto last_path = ptr.back(); ptr.pop_back(); basic_json& parent = result.at(ptr); @@ -25012,14 +24911,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // context-sensitive error message const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\''); // NOLINT(bugprone-unused-local-non-trivial-variable) - // check if the desired value is present + // check if desired value is present if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end())) { // NOLINTNEXTLINE(performance-inefficient-string-concatenation) JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg, " must have member '", member, "'"), &val)); } - // check if the result is of type string + // check if result is of type string if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string())) { // NOLINTNEXTLINE(performance-inefficient-string-concatenation) @@ -25108,7 +25007,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // ignore out of range errors: success remains false } - // throw an exception if the test fails + // throw an exception if test fails if (JSON_HEDLEY_UNLIKELY(!success)) { JSON_THROW(other_error::create(501, detail::concat("unsuccessful: ", val.dump()), &val)); @@ -25146,7 +25045,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // the patch basic_json result(value_t::array); - // if the values are the same, return an empty patch + // if the values are the same, return empty patch if (source == target) { return result; @@ -25260,7 +25159,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec case value_t::discarded: default: { - // both primitive types: replace value + // both primitive type: replace value result.push_back( { {"op", "replace"}, {"path", path}, {"value", target} @@ -25454,7 +25353,6 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC #undef JSON_HAS_CPP_17 #undef JSON_HAS_CPP_20 #undef JSON_HAS_CPP_23 - #undef JSON_HAS_CPP_26 #undef JSON_HAS_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #undef JSON_HAS_THREE_WAY_COMPARISON diff --git a/nlohmann_json/tests/module_cpp20/CMakeLists.txt b/nlohmann_json/tests/module_cpp20/CMakeLists.txt deleted file mode 100644 index 23884342..00000000 --- a/nlohmann_json/tests/module_cpp20/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -cmake_minimum_required(VERSION 3.28) - -project(json_test CXX) - -add_executable(json_test) - -target_sources(json_test - PRIVATE main.cpp - PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES json.cpp) - -target_compile_features(json_test PUBLIC cxx_std_20) -target_include_directories(json_test PRIVATE ../../include) diff --git a/nlohmann_json/tests/module_cpp20/json.cpp b/nlohmann_json/tests/module_cpp20/json.cpp deleted file mode 100644 index 8d5cc914..00000000 --- a/nlohmann_json/tests/module_cpp20/json.cpp +++ /dev/null @@ -1,17 +0,0 @@ -module; -#include -export module json; - -export namespace nlohmann -{ -using ::nlohmann::adl_serializer; - -using ::nlohmann::basic_json; -using ::nlohmann::json_pointer; - -using ::nlohmann::json; -using ::nlohmann::ordered_json; -using ::nlohmann::ordered_map; - -using ::nlohmann::json_pointer; -} // namespace nlohmann diff --git a/nlohmann_json/tests/module_cpp20/main.cpp b/nlohmann_json/tests/module_cpp20/main.cpp deleted file mode 100644 index ad7bd8b1..00000000 --- a/nlohmann_json/tests/module_cpp20/main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -import json; - -int main() -{ - nlohmann::json j; -} diff --git a/nlohmann_json/tests/src/BUILD b/nlohmann_json/tests/src/BUILD index b035286c..9d84ef83 100644 --- a/nlohmann_json/tests/src/BUILD +++ b/nlohmann_json/tests/src/BUILD @@ -28,6 +28,7 @@ cc_test( ], exclude = [ "unit-32bit.cpp", + "unit-disabled_exceptions.cpp", ], ) + select({ "@platforms//cpu:x86_32": ["unit-32bit.cpp"], # Only include on 32-bit x86 @@ -48,3 +49,28 @@ cc_test( "//nlohmann_json/tests/thirdparty/fifo_map", ], ) + +# sax_no_exception is defined in unit-disabled_exceptions.cpp and in unit-regression2.cpp which leads to a linker error when both files are included in the same test. + +cc_test( + name = "disabled_exceptions_test", + srcs = + [ + "unit.cpp", + "unit-disabled_exceptions.cpp", + ], + copts = [ + '-DTEST_DATA_DIRECTORY="json_test_data"', + ], + data = glob(["json_test_data/**"]), + includes = [ + ".", + ], + deps = [ + ":test_data_header", + "//nlohmann_json/single_include/nlohmann:nlohmann_json", + "//nlohmann_json/tests/thirdparty/doctest", + "//nlohmann_json/tests/thirdparty/doctest:doctest_compatibility", + "//nlohmann_json/tests/thirdparty/fifo_map", + ], +) diff --git a/nlohmann_json/tests/src/test_data.hpp b/nlohmann_json/tests/src/test_data.hpp deleted file mode 100644 index 7c4a4c93..00000000 --- a/nlohmann_json/tests/src/test_data.hpp +++ /dev/null @@ -1 +0,0 @@ -#define TEST_DATA_DIRECTORY "json_test_data" diff --git a/nlohmann_json/tests/src/test_utils.hpp b/nlohmann_json/tests/src/test_utils.hpp index 8a2b3eda..a6003890 100644 --- a/nlohmann_json/tests/src/test_utils.hpp +++ b/nlohmann_json/tests/src/test_utils.hpp @@ -11,7 +11,6 @@ #include // uint8_t #include // ifstream, istreambuf_iterator, ios #include // vector -#include // istream_iterator namespace utils { diff --git a/nlohmann_json/tests/src/unit-alt-string.cpp b/nlohmann_json/tests/src/unit-alt-string.cpp index fd6047c3..4f08290d 100644 --- a/nlohmann_json/tests/src/unit-alt-string.cpp +++ b/nlohmann_json/tests/src/unit-alt-string.cpp @@ -207,49 +207,49 @@ TEST_CASE("alternative string type") { alt_json doc; doc["pi"] = 3.141; - const alt_string dump = doc.dump(); + alt_string dump = doc.dump(); CHECK(dump == R"({"pi":3.141})"); } { alt_json doc; doc["happy"] = true; - const alt_string dump = doc.dump(); + alt_string dump = doc.dump(); CHECK(dump == R"({"happy":true})"); } { alt_json doc; doc["name"] = "I'm Batman"; - const alt_string dump = doc.dump(); + alt_string dump = doc.dump(); CHECK(dump == R"({"name":"I'm Batman"})"); } { alt_json doc; doc["nothing"] = nullptr; - const alt_string dump = doc.dump(); + alt_string dump = doc.dump(); CHECK(dump == R"({"nothing":null})"); } { alt_json doc; doc["answer"]["everything"] = 42; - const alt_string dump = doc.dump(); + alt_string dump = doc.dump(); CHECK(dump == R"({"answer":{"everything":42}})"); } { alt_json doc; doc["list"] = { 1, 0, 2 }; - const alt_string dump = doc.dump(); + alt_string dump = doc.dump(); CHECK(dump == R"({"list":[1,0,2]})"); } { alt_json doc; doc["object"] = { {"currency", "USD"}, {"value", 42.99} }; - const alt_string dump = doc.dump(); + alt_string dump = doc.dump(); CHECK(dump == R"({"object":{"currency":"USD","value":42.99}})"); } } @@ -257,7 +257,7 @@ TEST_CASE("alternative string type") SECTION("parse") { auto doc = alt_json::parse(R"({"foo": "bar"})"); - const alt_string dump = doc.dump(); + alt_string dump = doc.dump(); CHECK(dump == R"({"foo":"bar"})"); } diff --git a/nlohmann_json/tests/src/unit-bjdata.cpp b/nlohmann_json/tests/src/unit-bjdata.cpp index 666c0be5..a7c305d9 100644 --- a/nlohmann_json/tests/src/unit-bjdata.cpp +++ b/nlohmann_json/tests/src/unit-bjdata.cpp @@ -1226,21 +1226,21 @@ TEST_CASE("BJData") SECTION("0 (0 00000 0000000000)") { json const j = json::from_bjdata(std::vector({'h', 0x00, 0x00})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == 0.0); } SECTION("-0 (1 00000 0000000000)") { json const j = json::from_bjdata(std::vector({'h', 0x00, 0x80})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == -0.0); } SECTION("2**-24 (0 00000 0000000001)") { json const j = json::from_bjdata(std::vector({'h', 0x01, 0x00})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == std::pow(2.0, -24.0)); } } @@ -1250,7 +1250,7 @@ TEST_CASE("BJData") SECTION("infinity (0 11111 0000000000)") { json const j = json::from_bjdata(std::vector({'h', 0x00, 0x7c})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == std::numeric_limits::infinity()); CHECK(j.dump() == "null"); } @@ -1258,7 +1258,7 @@ TEST_CASE("BJData") SECTION("-infinity (1 11111 0000000000)") { json const j = json::from_bjdata(std::vector({'h', 0x00, 0xfc})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == -std::numeric_limits::infinity()); CHECK(j.dump() == "null"); } @@ -1269,21 +1269,21 @@ TEST_CASE("BJData") SECTION("1 (0 01111 0000000000)") { json const j = json::from_bjdata(std::vector({'h', 0x00, 0x3c})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == 1); } SECTION("-2 (1 10000 0000000000)") { json const j = json::from_bjdata(std::vector({'h', 0x00, 0xc0})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == -2); } SECTION("65504 (0 11110 1111111111)") { json const j = json::from_bjdata(std::vector({'h', 0xff, 0x7b})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == 65504); } } @@ -2815,129 +2815,6 @@ TEST_CASE("BJData") #endif } - SECTION("overflow detection in dimension multiplication") - { - // Simple SAX handler just to monitor if overflow is detected - struct SimpleOverflowSaxHandler : public nlohmann::json_sax - { - bool overflow_detected = false; - - // Implement all required virtual methods with minimal implementation - bool null() override - { - return true; - } - bool boolean(bool /*val*/) override - { - return true; - } - bool number_integer(json::number_integer_t /*val*/) override - { - return true; - } - bool number_unsigned(json::number_unsigned_t /*val*/) override - { - return true; - } - bool number_float(json::number_float_t /*val*/, const std::string& /*s*/) override - { - return true; - } - bool string(std::string& /*val*/) override - { - return true; - } - bool binary(json::binary_t& /*val*/) override - { - return true; - } - bool start_object(std::size_t /*elements*/) override - { - return true; - } - bool key(std::string& /*val*/) override - { - return true; - } - bool end_object() override - { - return true; - } - bool start_array(std::size_t /*elements*/) override - { - return true; - } - bool end_array() override - { - return true; - } - - // This is the only method we care about - detecting error 408 - bool parse_error(std::size_t /*position*/, const std::string& /*last_token*/, const json::exception& ex) override - { - if (ex.id == 408) - { - overflow_detected = true; - } - return false; - } - }; - - // Create BJData payload with overflow-causing dimensions (2^32+1) × (2^32) - const std::vector bjdata_payload = - { - 0x5B, // '[' start array - 0x24, 0x55, // '$', 'U' (type uint8) - 0x23, 0x5B, // '#', '[' (dimensions array) - 0x4D, // 'M' (uint64) - 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // 2^32 + 1 (4294967297) as little-endian - 0x4D, // 'M' (uint64) - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // 2^32 (4294967296) as little-endian - 0x5D // ']' end dimensions - // No data - we don't need it for this test, we just want to hit the overflow check - }; - - // Test with overflow dimensions using SAX parser - { - SimpleOverflowSaxHandler handler; - const auto result = json::sax_parse(bjdata_payload, &handler, - nlohmann::detail::input_format_t::bjdata, false); - - // Should detect overflow - CHECK(handler.overflow_detected == true); - CHECK(result == false); - } - - // Test with DOM parser (should throw) - { - json _; - CHECK_THROWS_AS(_ = json::from_bjdata(bjdata_payload), json::out_of_range); - } - - // Test with normal dimensions - const std::vector normal_payload = - { - 0x5B, // '[' start array - 0x24, 0x55, // '$', 'U' (type uint8) - 0x23, 0x5B, // '#', '[' (dimensions array) - 0x55, 0x02, // 'U', 2 (uint8) - 0x55, 0x03, // 'U', 3 (uint8) - 0x5D, // ']' end dimensions - // 6 data bytes for a 2×3 array (enough to avoid EOF but not entire array) - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 - }; - - // For normal dimensions, overflow should not be detected - { - SimpleOverflowSaxHandler handler; - const auto result = json::sax_parse(normal_payload, &handler, - nlohmann::detail::input_format_t::bjdata, false); - - CHECK(handler.overflow_detected == false); - CHECK(result == true); - } - } - SECTION("do not accept NTFZ markers in ndarray optimized type (with count)") { json _; @@ -3789,7 +3666,7 @@ TEST_CASE("BJData roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": std::vector"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse BJData file auto packed = utils::read_binary_file(filename + ".bjdata"); @@ -3804,7 +3681,7 @@ TEST_CASE("BJData roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": std::ifstream"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse BJData file std::ifstream f_bjdata(filename + ".bjdata", std::ios::binary); diff --git a/nlohmann_json/tests/src/unit-bson.cpp b/nlohmann_json/tests/src/unit-bson.cpp index 5d8d20fd..6f715340 100644 --- a/nlohmann_json/tests/src/unit-bson.cpp +++ b/nlohmann_json/tests/src/unit-bson.cpp @@ -565,10 +565,10 @@ TEST_CASE("BSON") SECTION("Example 1") { std::vector input = {0x16, 0x00, 0x00, 0x00, 0x02, 'h', 'e', 'l', 'l', 'o', 0x00, 0x06, 0x00, 0x00, 0x00, 'w', 'o', 'r', 'l', 'd', 0x00, 0x00}; - const json parsed = json::from_bson(input); - const json expected = {{"hello", "world"}}; + json parsed = json::from_bson(input); + json expected = {{"hello", "world"}}; CHECK(parsed == expected); - const auto dumped = json::to_bson(parsed); + auto dumped = json::to_bson(parsed); CHECK(dumped == input); CHECK(json::from_bson(dumped) == expected); } @@ -576,10 +576,10 @@ TEST_CASE("BSON") SECTION("Example 2") { std::vector input = {0x31, 0x00, 0x00, 0x00, 0x04, 'B', 'S', 'O', 'N', 0x00, 0x26, 0x00, 0x00, 0x00, 0x02, 0x30, 0x00, 0x08, 0x00, 0x00, 0x00, 'a', 'w', 'e', 's', 'o', 'm', 'e', 0x00, 0x01, 0x31, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x14, 0x40, 0x10, 0x32, 0x00, 0xc2, 0x07, 0x00, 0x00, 0x00, 0x00}; - const json parsed = json::from_bson(input); - const json expected = {{"BSON", {"awesome", 5.05, 1986}}}; + json parsed = json::from_bson(input); + json expected = {{"BSON", {"awesome", 5.05, 1986}}}; CHECK(parsed == expected); - const auto dumped = json::to_bson(parsed); + auto dumped = json::to_bson(parsed); CHECK(dumped == input); CHECK(json::from_bson(dumped) == expected); } @@ -588,7 +588,7 @@ TEST_CASE("BSON") TEST_CASE("BSON input/output_adapters") { - const json json_representation = + json json_representation = { {"double", 42.5}, {"entry", 4.2}, @@ -596,7 +596,7 @@ TEST_CASE("BSON input/output_adapters") {"object", {{ "string", "value" }}} }; - const std::vector bson_representation = + std::vector const bson_representation = { /*size */ 0x4f, 0x00, 0x00, 0x00, /*entry*/ 0x01, 'd', 'o', 'u', 'b', 'l', 'e', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x45, 0x40, @@ -621,7 +621,7 @@ TEST_CASE("BSON input/output_adapters") { std::basic_ostringstream ss; json::to_bson(json_representation, ss); - const json j3 = json::from_bson(ss.str()); + json j3 = json::from_bson(ss.str()); CHECK(json_representation == j3); } @@ -629,7 +629,7 @@ TEST_CASE("BSON input/output_adapters") { std::string s; json::to_bson(json_representation, s); - const json j3 = json::from_bson(s); + json j3 = json::from_bson(s); CHECK(json_representation == j3); } @@ -637,7 +637,7 @@ TEST_CASE("BSON input/output_adapters") { std::vector v; json::to_bson(json_representation, v); - const json j3 = json::from_bson(v); + json j3 = json::from_bson(v); CHECK(json_representation == j3); } } @@ -1227,7 +1227,7 @@ TEST_CASE("BSON roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": std::vector"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse BSON file auto packed = utils::read_binary_file(filename + ".bson"); @@ -1242,7 +1242,7 @@ TEST_CASE("BSON roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": std::ifstream"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse BSON file std::ifstream f_bson(filename + ".bson", std::ios::binary); @@ -1257,7 +1257,7 @@ TEST_CASE("BSON roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": uint8_t* and size"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse BSON file auto packed = utils::read_binary_file(filename + ".bson"); diff --git a/nlohmann_json/tests/src/unit-cbor.cpp b/nlohmann_json/tests/src/unit-cbor.cpp index 5ece0cb9..0404ca16 100644 --- a/nlohmann_json/tests/src/unit-cbor.cpp +++ b/nlohmann_json/tests/src/unit-cbor.cpp @@ -1022,21 +1022,21 @@ TEST_CASE("CBOR") SECTION("0 (0 00000 0000000000)") { json const j = json::from_cbor(std::vector({0xf9, 0x00, 0x00})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == 0.0); } SECTION("-0 (1 00000 0000000000)") { json const j = json::from_cbor(std::vector({0xf9, 0x80, 0x00})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == -0.0); } SECTION("2**-24 (0 00000 0000000001)") { json const j = json::from_cbor(std::vector({0xf9, 0x00, 0x01})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == std::pow(2.0, -24.0)); } } @@ -1046,7 +1046,7 @@ TEST_CASE("CBOR") SECTION("infinity (0 11111 0000000000)") { json const j = json::from_cbor(std::vector({0xf9, 0x7c, 0x00})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == std::numeric_limits::infinity()); CHECK(j.dump() == "null"); } @@ -1054,7 +1054,7 @@ TEST_CASE("CBOR") SECTION("-infinity (1 11111 0000000000)") { json const j = json::from_cbor(std::vector({0xf9, 0xfc, 0x00})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == -std::numeric_limits::infinity()); CHECK(j.dump() == "null"); } @@ -1065,21 +1065,21 @@ TEST_CASE("CBOR") SECTION("1 (0 01111 0000000000)") { json const j = json::from_cbor(std::vector({0xf9, 0x3c, 0x00})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == 1); } SECTION("-2 (1 10000 0000000000)") { json const j = json::from_cbor(std::vector({0xf9, 0xc0, 0x00})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == -2); } SECTION("65504 (0 11110 1111111111)") { json const j = json::from_cbor(std::vector({0xf9, 0x7b, 0xff})); - const json::number_float_t d{j}; + json::number_float_t d{j}; CHECK(d == 65504); } } @@ -1942,7 +1942,7 @@ TEST_CASE("CBOR regressions") { // parse CBOR file auto vec1 = utils::read_binary_file(filename); - const json j1 = json::from_cbor(vec1); + json j1 = json::from_cbor(vec1); try { @@ -2143,7 +2143,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": std::vector"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse CBOR file const auto packed = utils::read_binary_file(filename + ".cbor"); @@ -2158,7 +2158,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": std::ifstream"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse CBOR file std::ifstream f_cbor(filename + ".cbor", std::ios::binary); @@ -2173,7 +2173,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": uint8_t* and size"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse CBOR file const auto packed = utils::read_binary_file(filename + ".cbor"); diff --git a/nlohmann_json/tests/src/unit-class_parser.cpp b/nlohmann_json/tests/src/unit-class_parser.cpp index 394bad43..549cd4f2 100644 --- a/nlohmann_json/tests/src/unit-class_parser.cpp +++ b/nlohmann_json/tests/src/unit-class_parser.cpp @@ -206,7 +206,6 @@ class SaxCountdown : public nlohmann::json::json_sax_t json parser_helper(const std::string& s); bool accept_helper(const std::string& s); void comments_helper(const std::string& s); -void trailing_comma_helper(const std::string& s); json parser_helper(const std::string& s) { @@ -226,8 +225,6 @@ json parser_helper(const std::string& s) comments_helper(s); - trailing_comma_helper(s); - return j; } @@ -262,11 +259,10 @@ bool accept_helper(const std::string& s) // 6. check if this approach came to the same result CHECK(ok_noexcept == ok_noexcept_cb); - // 7. check if comments or trailing commas are properly ignored + // 7. check if comments are properly ignored if (ok_accept) { comments_helper(s); - trailing_comma_helper(s); } // 8. return result @@ -306,38 +302,6 @@ void comments_helper(const std::string& s) } } -void trailing_comma_helper(const std::string& s) -{ - json _; - - // parse/accept with default parser - CHECK_NOTHROW(_ = json::parse(s)); - CHECK(json::accept(s)); - - // parse/accept while allowing trailing commas - CHECK_NOTHROW(_ = json::parse(s, nullptr, false, false, true)); - CHECK(json::accept(s, false, true)); - - // note: [,] and {,} are not allowed - if (s.size() > 1 && (s.back() == ']' || s.back() == '}') && !_.empty()) - { - std::vector json_with_trailing_commas; - json_with_trailing_commas.push_back(s.substr(0, s.size() - 1) + " ," + s.back()); - json_with_trailing_commas.push_back(s.substr(0, s.size() - 1) + "," + s.back()); - json_with_trailing_commas.push_back(s.substr(0, s.size() - 1) + ", " + s.back()); - - for (const auto& json_with_trailing_comma : json_with_trailing_commas) - { - CAPTURE(json_with_trailing_comma) - CHECK_THROWS_AS(_ = json::parse(json_with_trailing_comma), json::parse_error); - CHECK(!json::accept(json_with_trailing_comma)); - - CHECK_NOTHROW(_ = json::parse(json_with_trailing_comma, nullptr, true, false, true)); - CHECK(json::accept(json_with_trailing_comma, false, true)); - } - } -} - } // namespace TEST_CASE("parser class") @@ -1402,7 +1366,7 @@ TEST_CASE("parser class") return event != json::parse_event_t::key; }; - const json x = json::parse("{\"key\": false}", cb); + json x = json::parse("{\"key\": false}", cb); CHECK(x == json::object()); } } @@ -1436,14 +1400,14 @@ TEST_CASE("parser class") SECTION("filter nothing") { - const json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return true; }); CHECK (j_object == json({{"foo", 2}, {"bar", {{"baz", 1}}}})); - const json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return true; }); @@ -1472,7 +1436,7 @@ TEST_CASE("parser class") SECTION("filter specific element") { - const json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t event, const json & j) noexcept + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t event, const json & j) noexcept { // filter all number(2) elements return event != json::parse_event_t::value || j != json(2); @@ -1480,7 +1444,7 @@ TEST_CASE("parser class") CHECK (j_object == json({{"bar", {{"baz", 1}}}})); - const json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t event, const json & j) noexcept + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t event, const json & j) noexcept { return event != json::parse_event_t::value || j != json(2); }); @@ -1490,7 +1454,7 @@ TEST_CASE("parser class") SECTION("filter object in array") { - const json j_filtered1 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json & parsed) + json j_filtered1 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json & parsed) { return !(e == json::parse_event_t::object_end && parsed.contains("foo")); }); @@ -1499,7 +1463,7 @@ TEST_CASE("parser class") CHECK (j_filtered1.size() == 2); CHECK (j_filtered1 == json({1, {{"qux", "baz"}}})); - const json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/) noexcept + json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/) noexcept { return e != json::parse_event_t::object_end; }); @@ -1514,7 +1478,7 @@ TEST_CASE("parser class") SECTION("first closing event") { { - const json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { static bool first = true; if (e == json::parse_event_t::object_end && first) @@ -1531,7 +1495,7 @@ TEST_CASE("parser class") } { - const json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { static bool first = true; if (e == json::parse_event_t::array_end && first) @@ -1555,13 +1519,13 @@ TEST_CASE("parser class") // object and array is discarded only after the closing character // has been read - const json j_empty_object = json::parse("{}", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept + json j_empty_object = json::parse("{}", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { return e != json::parse_event_t::object_end; }); CHECK(j_empty_object == json()); - const json j_empty_array = json::parse("[]", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept + json j_empty_array = json::parse("[]", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { return e != json::parse_event_t::array_end; }); diff --git a/nlohmann_json/tests/src/unit-class_parser_diagnostic_positions.cpp b/nlohmann_json/tests/src/unit-class_parser_diagnostic_positions.cpp index c8a03aee..976c4f9d 100644 --- a/nlohmann_json/tests/src/unit-class_parser_diagnostic_positions.cpp +++ b/nlohmann_json/tests/src/unit-class_parser_diagnostic_positions.cpp @@ -1413,7 +1413,7 @@ TEST_CASE("parser class") return event != json::parse_event_t::key; }; - const json x = json::parse("{\"key\": false}", cb); + json x = json::parse("{\"key\": false}", cb); CHECK(x == json::object()); } } @@ -1447,14 +1447,14 @@ TEST_CASE("parser class") SECTION("filter nothing") { - const json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return true; }); CHECK (j_object == json({{"foo", 2}, {"bar", {{"baz", 1}}}})); - const json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return true; }); @@ -1483,7 +1483,7 @@ TEST_CASE("parser class") SECTION("filter specific element") { - const json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t event, const json & j) noexcept + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t event, const json & j) noexcept { // filter all number(2) elements return event != json::parse_event_t::value || j != json(2); @@ -1491,7 +1491,7 @@ TEST_CASE("parser class") CHECK (j_object == json({{"bar", {{"baz", 1}}}})); - const json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t event, const json & j) noexcept + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t event, const json & j) noexcept { return event != json::parse_event_t::value || j != json(2); }); @@ -1501,7 +1501,7 @@ TEST_CASE("parser class") SECTION("filter object in array") { - const json j_filtered1 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json & parsed) + json j_filtered1 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json & parsed) { return !(e == json::parse_event_t::object_end && parsed.contains("foo")); }); @@ -1510,7 +1510,7 @@ TEST_CASE("parser class") CHECK (j_filtered1.size() == 2); CHECK (j_filtered1 == json({1, {{"qux", "baz"}}})); - const json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/) noexcept + json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/) noexcept { return e != json::parse_event_t::object_end; }); @@ -1525,7 +1525,7 @@ TEST_CASE("parser class") SECTION("first closing event") { { - const json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { static bool first = true; if (e == json::parse_event_t::object_end && first) @@ -1542,7 +1542,7 @@ TEST_CASE("parser class") } { - const json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { static bool first = true; if (e == json::parse_event_t::array_end && first) @@ -1566,13 +1566,13 @@ TEST_CASE("parser class") // object and array is discarded only after the closing character // has been read - const json j_empty_object = json::parse("{}", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept + json j_empty_object = json::parse("{}", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { return e != json::parse_event_t::object_end; }); CHECK(j_empty_object == json()); - const json j_empty_array = json::parse("[]", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept + json j_empty_array = json::parse("[]", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept { return e != json::parse_event_t::array_end; }); diff --git a/nlohmann_json/tests/src/unit-comparison.cpp b/nlohmann_json/tests/src/unit-comparison.cpp index 891c4206..d87faaae 100644 --- a/nlohmann_json/tests/src/unit-comparison.cpp +++ b/nlohmann_json/tests/src/unit-comparison.cpp @@ -576,7 +576,7 @@ TEST_CASE("lexicographical comparison operators") [1,2,[3,4,5],4,5] )"; - const json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j) noexcept + json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j) noexcept { // filter all number(2) elements return j != json(2); @@ -584,7 +584,7 @@ TEST_CASE("lexicographical comparison operators") CHECK (j_object == json({{"bar", {{"baz", 1}}}})); - const json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j) noexcept + json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j) noexcept { return j != json(2); }); diff --git a/nlohmann_json/tests/src/unit-constructor1.cpp b/nlohmann_json/tests/src/unit-constructor1.cpp index f23c1478..02a08215 100644 --- a/nlohmann_json/tests/src/unit-constructor1.cpp +++ b/nlohmann_json/tests/src/unit-constructor1.cpp @@ -779,7 +779,7 @@ TEST_CASE("constructors") SECTION("integer literal with u suffix") { - const json j(42u); + json j(42u); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } @@ -793,7 +793,7 @@ TEST_CASE("constructors") SECTION("integer literal with ul suffix") { - const json j(42ul); + json j(42ul); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } @@ -807,7 +807,7 @@ TEST_CASE("constructors") SECTION("integer literal with ull suffix") { - const json j(42ull); + json j(42ull); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } @@ -1362,7 +1362,7 @@ TEST_CASE("constructors") { { json jarray = {1, 2, 3, 4, 5}; - const json j_new(jarray.begin(), jarray.begin()); + json j_new(jarray.begin(), jarray.begin()); CHECK(j_new == json::array()); } { diff --git a/nlohmann_json/tests/src/unit-constructor2.cpp b/nlohmann_json/tests/src/unit-constructor2.cpp index 33871ecf..153addcf 100644 --- a/nlohmann_json/tests/src/unit-constructor2.cpp +++ b/nlohmann_json/tests/src/unit-constructor2.cpp @@ -17,63 +17,63 @@ TEST_CASE("other constructors and destructor") { SECTION("object") { - const json j {{"foo", 1}, {"bar", false}}; + json j {{"foo", 1}, {"bar", false}}; json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("array") { - const json j {"foo", 1, 42.23, false}; + json j {"foo", 1, 42.23, false}; json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("null") { - const json j(nullptr); + json j(nullptr); json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("boolean") { - const json j(true); + json j(true); json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("string") { - const json j("Hello world"); + json j("Hello world"); json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("number (integer)") { - const json j(42); + json j(42); json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("number (unsigned)") { - const json j(42u); + json j(42u); json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("number (floating-point)") { - const json j(42.23); + json j(42.23); json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } SECTION("binary") { - const json j = json::binary({1, 2, 3}); + json j = json::binary({1, 2, 3}); json k(j); // NOLINT(performance-unnecessary-copy-initialization) CHECK(j == k); } @@ -92,7 +92,7 @@ TEST_CASE("other constructors and destructor") { SECTION("object") { - const json j {{"foo", 1}, {"bar", false}}; + json j {{"foo", 1}, {"bar", false}}; json k; k = j; CHECK(j == k); @@ -100,7 +100,7 @@ TEST_CASE("other constructors and destructor") SECTION("array") { - const json j {"foo", 1, 42.23, false}; + json j {"foo", 1, 42.23, false}; json k; k = j; CHECK(j == k); @@ -108,7 +108,7 @@ TEST_CASE("other constructors and destructor") SECTION("null") { - const json j(nullptr); + json j(nullptr); json k; k = j; CHECK(j == k); @@ -116,7 +116,7 @@ TEST_CASE("other constructors and destructor") SECTION("boolean") { - const json j(true); + json j(true); json k; k = j; CHECK(j == k); @@ -124,7 +124,7 @@ TEST_CASE("other constructors and destructor") SECTION("string") { - const json j("Hello world"); + json j("Hello world"); json k; k = j; CHECK(j == k); @@ -132,7 +132,7 @@ TEST_CASE("other constructors and destructor") SECTION("number (integer)") { - const json j(42); + json j(42); json k; k = j; CHECK(j == k); @@ -140,7 +140,7 @@ TEST_CASE("other constructors and destructor") SECTION("number (unsigned)") { - const json j(42u); + json j(42u); json k; k = j; CHECK(j == k); @@ -148,7 +148,7 @@ TEST_CASE("other constructors and destructor") SECTION("number (floating-point)") { - const json j(42.23); + json j(42.23); json k; k = j; CHECK(j == k); @@ -156,7 +156,7 @@ TEST_CASE("other constructors and destructor") SECTION("binary") { - const json j = json::binary({1, 2, 3}); + json j = json::binary({1, 2, 3}); json k; k = j; CHECK(j == k); diff --git a/nlohmann_json/tests/src/unit-convenience.cpp b/nlohmann_json/tests/src/unit-convenience.cpp index 027c183e..0d6d1359 100644 --- a/nlohmann_json/tests/src/unit-convenience.cpp +++ b/nlohmann_json/tests/src/unit-convenience.cpp @@ -179,9 +179,9 @@ TEST_CASE("convenience functions") SECTION("std::string") { - const std::string str1 = concat(hello_iter, world, '!'); - const std::string str2 = concat(hello_data, world, '!'); - const std::string str3 = concat("Hello, ", world, '!'); + std::string str1 = concat(hello_iter, world, '!'); + std::string str2 = concat(hello_data, world, '!'); + std::string str3 = concat("Hello, ", world, '!'); CHECK(str1 == expected); CHECK(str2 == expected); @@ -190,14 +190,14 @@ TEST_CASE("convenience functions") SECTION("alt_string_iter") { - const alt_string_iter str = concat(hello_iter, world, '!'); + alt_string_iter str = concat(hello_iter, world, '!'); CHECK(str.impl == expected); } SECTION("alt_string_data") { - const alt_string_data str = concat(hello_data, world, '!'); + alt_string_data str = concat(hello_data, world, '!'); CHECK(str.impl == expected); } diff --git a/nlohmann_json/tests/src/unit-conversions.cpp b/nlohmann_json/tests/src/unit-conversions.cpp index 2ca0d1c4..98c4321d 100644 --- a/nlohmann_json/tests/src/unit-conversions.cpp +++ b/nlohmann_json/tests/src/unit-conversions.cpp @@ -1514,7 +1514,7 @@ TEST_CASE("value conversion") SECTION("std::map (array of pairs)") { - const std::map m{{0, 1}, {1, 2}, {2, 3}}; + std::map m{{0, 1}, {1, 2}, {2, 3}}; json const j6 = m; auto m2 = j6.get>(); @@ -1539,7 +1539,7 @@ TEST_CASE("value conversion") SECTION("std::unordered_map (array of pairs)") { - const std::unordered_map m{{0, 1}, {1, 2}, {2, 3}}; + std::unordered_map m{{0, 1}, {1, 2}, {2, 3}}; json const j6 = m; auto m2 = j6.get>(); diff --git a/nlohmann_json/tests/src/unit-deserialization.cpp b/nlohmann_json/tests/src/unit-deserialization.cpp index ef538665..84a970a1 100644 --- a/nlohmann_json/tests/src/unit-deserialization.cpp +++ b/nlohmann_json/tests/src/unit-deserialization.cpp @@ -227,7 +227,7 @@ TEST_CASE("deserialization") ss1 << R"(["foo",1,2,3,false,{"one":1}])"; ss2 << R"(["foo",1,2,3,false,{"one":1}])"; ss3 << R"(["foo",1,2,3,false,{"one":1}])"; - const json j = json::parse(ss1); + json j = json::parse(ss1); CHECK(json::accept(ss2)); CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}})); @@ -246,7 +246,7 @@ TEST_CASE("deserialization") SECTION("string literal") { const auto* s = R"(["foo",1,2,3,false,{"one":1}])"; - const json j = json::parse(s); + json j = json::parse(s); CHECK(json::accept(s)); CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}})); @@ -265,7 +265,7 @@ TEST_CASE("deserialization") SECTION("string_t") { json::string_t const s = R"(["foo",1,2,3,false,{"one":1}])"; - const json j = json::parse(s); + json j = json::parse(s); CHECK(json::accept(s)); CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}})); @@ -1134,10 +1134,9 @@ TEST_CASE("deserialization") } } -// select the types to test - char8_t is only available since C++20 if and only -// if __cpp_char8_t is defined. +// select the types to test - char8_t is only available in C++20 #define TYPE_LIST(...) __VA_ARGS__ -#if defined(__cpp_char8_t) && (__cpp_char8_t >= 201811L) +#ifdef JSON_HAS_CPP_20 #define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t, char8_t) #else #define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t) diff --git a/nlohmann_json/tests/src/unit-disabled_exceptions.cpp b/nlohmann_json/tests/src/unit-disabled_exceptions.cpp index f02d9563..e4a9cb03 100644 --- a/nlohmann_json/tests/src/unit-disabled_exceptions.cpp +++ b/nlohmann_json/tests/src/unit-disabled_exceptions.cpp @@ -33,7 +33,7 @@ class sax_no_exception : public nlohmann::detail::json_sax_dom_parser(f_escaped)), - std::istreambuf_iterator()); + std::string expected((std::istreambuf_iterator(f_escaped)), + std::istreambuf_iterator()); CHECK(text == expected); } } @@ -333,7 +333,7 @@ TEST_CASE("object inspection") }) { json const j1 = json::parse(s); - const std::string s1 = j1.dump(); + std::string s1 = j1.dump(); json const j2 = json::parse(s1); std::string s2 = j2.dump(); CHECK(s1 == s2); @@ -396,63 +396,63 @@ TEST_CASE("object inspection") SECTION("null") { json const j = nullptr; - const json::value_t t = j; + json::value_t t = j; CHECK(t == j.type()); } SECTION("object") { json const j = {{"foo", "bar"}}; - const json::value_t t = j; + json::value_t t = j; CHECK(t == j.type()); } SECTION("array") { json const j = {1, 2, 3, 4}; - const json::value_t t = j; + json::value_t t = j; CHECK(t == j.type()); } SECTION("boolean") { json const j = true; - const json::value_t t = j; + json::value_t t = j; CHECK(t == j.type()); } SECTION("string") { json const j = "Hello world"; - const json::value_t t = j; + json::value_t t = j; CHECK(t == j.type()); } SECTION("number (integer)") { json const j = 23; - const json::value_t t = j; + json::value_t t = j; CHECK(t == j.type()); } SECTION("number (unsigned)") { json const j = 23u; - const json::value_t t = j; + json::value_t t = j; CHECK(t == j.type()); } SECTION("number (floating-point)") { json const j = 42.23; - const json::value_t t = j; + json::value_t t = j; CHECK(t == j.type()); } SECTION("binary") { json const j = json::binary({}); - const json::value_t t = j; + json::value_t t = j; CHECK(t == j.type()); } } diff --git a/nlohmann_json/tests/src/unit-iterators1.cpp b/nlohmann_json/tests/src/unit-iterators1.cpp index 1a4ec472..595a1b68 100644 --- a/nlohmann_json/tests/src/unit-iterators1.cpp +++ b/nlohmann_json/tests/src/unit-iterators1.cpp @@ -18,10 +18,10 @@ TEST_CASE("iterators 1") { SECTION("uninitialized") { - json::iterator it; // NOLINT(misc-const-correctness) + json::iterator it; CHECK(it.m_object == nullptr); - json::const_iterator cit; // NOLINT(misc-const-correctness) + json::const_iterator cit; CHECK(cit.m_object == nullptr); } @@ -1498,46 +1498,46 @@ TEST_CASE("iterators 1") SECTION("json + begin/end") { - const json::iterator it = j.begin(); + json::iterator it = j.begin(); CHECK(it == j.end()); } SECTION("const json + begin/end") { - const json::const_iterator it_begin = j_const.begin(); + json::const_iterator it_begin = j_const.begin(); json::const_iterator it_end = j_const.end(); CHECK(it_begin == it_end); } SECTION("json + cbegin/cend") { - const json::const_iterator it_begin = j.cbegin(); + json::const_iterator it_begin = j.cbegin(); json::const_iterator it_end = j.cend(); CHECK(it_begin == it_end); } SECTION("const json + cbegin/cend") { - const json::const_iterator it_begin = j_const.cbegin(); + json::const_iterator it_begin = j_const.cbegin(); json::const_iterator it_end = j_const.cend(); CHECK(it_begin == it_end); } SECTION("json + rbegin/rend") { - const json::reverse_iterator it = j.rbegin(); + json::reverse_iterator it = j.rbegin(); CHECK(it == j.rend()); } SECTION("json + crbegin/crend") { - const json::const_reverse_iterator it = j.crbegin(); + json::const_reverse_iterator it = j.crbegin(); CHECK(it == j.crend()); } SECTION("const json + crbegin/crend") { - const json::const_reverse_iterator it = j_const.crbegin(); + json::const_reverse_iterator it = j_const.crbegin(); CHECK(it == j_const.crend()); } diff --git a/nlohmann_json/tests/src/unit-iterators2.cpp b/nlohmann_json/tests/src/unit-iterators2.cpp index 9e7c66f0..abf28ebe 100644 --- a/nlohmann_json/tests/src/unit-iterators2.cpp +++ b/nlohmann_json/tests/src/unit-iterators2.cpp @@ -955,8 +955,7 @@ TEST_CASE("iterators 2") }; json j_expected{"a_key", "b_key", "c_key"}; - // NOLINTNEXTLINE(fuchsia-trailing-return) - auto transformed = j.items() | std::views::transform([](const auto & item) -> std::string_view + auto transformed = j.items() | std::views::transform([](const auto & item) { return item.key(); }); diff --git a/nlohmann_json/tests/src/unit-json_patch.cpp b/nlohmann_json/tests/src/unit-json_patch.cpp index a58ebd9d..a5b3b261 100644 --- a/nlohmann_json/tests/src/unit-json_patch.cpp +++ b/nlohmann_json/tests/src/unit-json_patch.cpp @@ -24,9 +24,9 @@ TEST_CASE("JSON patch") SECTION("4. Operations") { // the ordering of members in JSON objects is not significant: - const json op1 = R"({ "op": "add", "path": "/a/b/c", "value": "foo" })"_json; - const json op2 = R"({ "path": "/a/b/c", "op": "add", "value": "foo" })"_json; - const json op3 = R"({ "value": "foo", "path": "/a/b/c", "op": "add" })"_json; + json op1 = R"({ "op": "add", "path": "/a/b/c", "value": "foo" })"_json; + json op2 = R"({ "path": "/a/b/c", "op": "add", "value": "foo" })"_json; + json op3 = R"({ "value": "foo", "path": "/a/b/c", "op": "add" })"_json; // check if the operation objects are equivalent CHECK(op1 == op2); @@ -642,12 +642,12 @@ TEST_CASE("JSON patch") )"_json; // apply the patch - const json target = source.patch(p1); + json target = source.patch(p1); // target = { "D": "Berlin", "F": "Paris", "GB": "London" } CHECK(target == R"({ "D": "Berlin", "F": "Paris", "GB": "London" })"_json); // create a diff from two JSONs - const json p2 = json::diff(target, source); // NOLINT(readability-suspicious-call-argument) + json p2 = json::diff(target, source); // NOLINT(readability-suspicious-call-argument) // p2 = [{"op": "delete", "path": "/GB"}] CHECK(p2 == R"([{"op":"remove","path":"/GB"}])"_json); } @@ -666,7 +666,7 @@ TEST_CASE("JSON patch") j["/2/en"_json_pointer] = "ugly"; CHECK(j == R"(["good","bad",{"en":"ugly","it":"cattivo"}])"_json); - const json flat = j.flatten(); + json flat = j.flatten(); CHECK(flat == R"({"/0":"good","/1":"bad","/2/en":"ugly","/2/it":"cattivo"})"_json); } } diff --git a/nlohmann_json/tests/src/unit-locale-cpp.cpp b/nlohmann_json/tests/src/unit-locale-cpp.cpp index 28457c01..2d1328cb 100644 --- a/nlohmann_json/tests/src/unit-locale-cpp.cpp +++ b/nlohmann_json/tests/src/unit-locale-cpp.cpp @@ -139,12 +139,7 @@ TEST_CASE("locale-dependent test (LC_NUMERIC=de_DE)") { std::array buffer = {}; CHECK(std::snprintf(buffer.data(), buffer.size(), "%.2f", 12.34) == 5); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - const auto snprintf_result = std::string(buffer.data()); - if (snprintf_result != "12,34") - { - CAPTURE(snprintf_result) - MESSAGE("To test if number parsing is locale-independent, we set the locale to de_DE. However, on this system, the decimal separator doesn't change to `,` potentially due to a known musl issue (https://github.com/nlohmann/json/issues/4767)."); - } + CHECK(std::string(buffer.data()) == "12,34"); } SECTION("parsing") diff --git a/nlohmann_json/tests/src/unit-msgpack.cpp b/nlohmann_json/tests/src/unit-msgpack.cpp index 3ff4ba30..0d49ae6d 100644 --- a/nlohmann_json/tests/src/unit-msgpack.cpp +++ b/nlohmann_json/tests/src/unit-msgpack.cpp @@ -1606,7 +1606,7 @@ TEST_CASE("single MessagePack roundtrip") // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse MessagePack file auto packed = utils::read_binary_file(filename + ".msgpack"); @@ -1817,7 +1817,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": std::vector"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse MessagePack file auto packed = utils::read_binary_file(filename + ".msgpack"); @@ -1832,7 +1832,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": std::ifstream"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse MessagePack file std::ifstream f_msgpack(filename + ".msgpack", std::ios::binary); @@ -1847,7 +1847,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": uint8_t* and size"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse MessagePack file auto packed = utils::read_binary_file(filename + ".msgpack"); @@ -1880,82 +1880,3 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip()) } } } - -#ifdef JSON_HAS_CPP_17 -// Test suite for verifying MessagePack handling with std::byte input -TEST_CASE("MessagePack with std::byte") -{ - - SECTION("std::byte compatibility") - { - SECTION("vector roundtrip") - { - json original = - { - {"name", "test"}, - {"value", 42}, - {"array", {1, 2, 3}} - }; - - std::vector temp = json::to_msgpack(original); - // Convert the uint8_t vector to std::byte vector - std::vector msgpack_data(temp.size()); - for (size_t i = 0; i < temp.size(); ++i) - { - msgpack_data[i] = std::byte(temp[i]); - } - // Deserialize from std::byte vector back to JSON - json from_bytes; - CHECK_NOTHROW(from_bytes = json::from_msgpack(msgpack_data)); - - CHECK(from_bytes == original); - } - - SECTION("empty vector") - { - const std::vector empty_data; - CHECK_THROWS_WITH_AS([&]() - { - [[maybe_unused]] auto result = json::from_msgpack(empty_data); - return true; - } - (), - "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input", - json::parse_error&); - } - - SECTION("comparison with workaround") - { - json original = - { - {"string", "hello"}, - {"integer", 42}, - {"float", 3.14}, - {"boolean", true}, - {"null", nullptr}, - {"array", {1, 2, 3}}, - {"object", {{"key", "value"}}} - }; - - std::vector temp = json::to_msgpack(original); - - std::vector msgpack_data(temp.size()); - for (size_t i = 0; i < temp.size(); ++i) - { - msgpack_data[i] = std::byte(temp[i]); - } - // Attempt direct deserialization using std::byte input - const json direct_result = json::from_msgpack(msgpack_data); - - // Test the workaround approach: reinterpret as unsigned char* and use iterator range - const auto* const char_start = reinterpret_cast(msgpack_data.data()); - const auto* const char_end = char_start + msgpack_data.size(); - json workaround_result = json::from_msgpack(char_start, char_end); - - // Verify that the final deserialized JSON matches the original JSON - CHECK(direct_result == workaround_result); - CHECK(direct_result == original); - } - } -} -#endif diff --git a/nlohmann_json/tests/src/unit-ordered_map.cpp b/nlohmann_json/tests/src/unit-ordered_map.cpp index b4ea28d6..b8aaf8c5 100644 --- a/nlohmann_json/tests/src/unit-ordered_map.cpp +++ b/nlohmann_json/tests/src/unit-ordered_map.cpp @@ -36,7 +36,7 @@ TEST_CASE("ordered_map") { std::map m {{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; ordered_map om(m.begin(), m.end()); - const auto com = om; // NOLINT(performance-unnecessary-copy-initialization) + const auto com = om; SECTION("with Key&&") { @@ -69,7 +69,7 @@ TEST_CASE("ordered_map") { std::map m {{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; ordered_map om(m.begin(), m.end()); - const auto com = om; // NOLINT(performance-unnecessary-copy-initialization) + const auto com = om; SECTION("with Key&&") { diff --git a/nlohmann_json/tests/src/unit-pointer_access.cpp b/nlohmann_json/tests/src/unit-pointer_access.cpp index fec134ae..2bb0f603 100644 --- a/nlohmann_json/tests/src/unit-pointer_access.cpp +++ b/nlohmann_json/tests/src/unit-pointer_access.cpp @@ -19,7 +19,7 @@ TEST_CASE("pointer access") json value = {{"one", 1}, {"two", 2}}; // check if pointers are returned correctly - const test_type* p1 = value.get_ptr(); + test_type* p1 = value.get_ptr(); CHECK(p1 == value.get_ptr()); CHECK(*p1 == value.get()); @@ -77,7 +77,7 @@ TEST_CASE("pointer access") json value = {1, 2, 3, 4}; // check if pointers are returned correctly - const test_type* p1 = value.get_ptr(); + test_type* p1 = value.get_ptr(); CHECK(p1 == value.get_ptr()); CHECK(*p1 == value.get()); @@ -135,7 +135,7 @@ TEST_CASE("pointer access") json value = "hello"; // check if pointers are returned correctly - const test_type* p1 = value.get_ptr(); + test_type* p1 = value.get_ptr(); CHECK(p1 == value.get_ptr()); CHECK(*p1 == value.get()); @@ -193,7 +193,7 @@ TEST_CASE("pointer access") json value = false; // check if pointers are returned correctly - const test_type* p1 = value.get_ptr(); + test_type* p1 = value.get_ptr(); CHECK(p1 == value.get_ptr()); CHECK(*p1 == value.get()); @@ -251,7 +251,7 @@ TEST_CASE("pointer access") json value = 23; // check if pointers are returned correctly - const test_type* p1 = value.get_ptr(); + test_type* p1 = value.get_ptr(); CHECK(p1 == value.get_ptr()); CHECK(*p1 == value.get()); @@ -309,7 +309,7 @@ TEST_CASE("pointer access") json value = 23u; // check if pointers are returned correctly - const test_type* p1 = value.get_ptr(); + test_type* p1 = value.get_ptr(); CHECK(p1 == value.get_ptr()); CHECK(*p1 == value.get()); @@ -367,7 +367,7 @@ TEST_CASE("pointer access") json value = 42.23; // check if pointers are returned correctly - const test_type* p1 = value.get_ptr(); + test_type* p1 = value.get_ptr(); CHECK(p1 == value.get_ptr()); CHECK(*p1 == Approx(value.get())); diff --git a/nlohmann_json/tests/src/unit-readme.cpp b/nlohmann_json/tests/src/unit-readme.cpp index 3bb28860..8b81e8fe 100644 --- a/nlohmann_json/tests/src/unit-readme.cpp +++ b/nlohmann_json/tests/src/unit-readme.cpp @@ -136,7 +136,7 @@ TEST_CASE("README" * doctest::skip()) j.push_back(true); // comparison - const bool x = (j == R"(["foo", 1, true])"_json); // true + bool x = (j == R"(["foo", 1, true])"_json); // true CHECK(x == true); // iterate the array @@ -154,7 +154,7 @@ TEST_CASE("README" * doctest::skip()) // getter/setter const auto tmp = j[0].get(); // NOLINT(bugprone-unused-local-non-trivial-variable) j[1] = 42; - const bool foo{j.at(2)}; + bool foo{j.at(2)}; CHECK(foo == true); // other stuff @@ -242,21 +242,21 @@ TEST_CASE("README" * doctest::skip()) // Booleans bool const b1 = true; json const jb = b1; - const bool b2{jb}; + bool b2{jb}; CHECK(b2 == true); // numbers int const i = 42; json const jn = i; - const double f{jn}; + double f{jn}; CHECK(f == 42); // etc. std::string const vs = js.get(); // NOLINT(bugprone-unused-local-non-trivial-variable) - const bool vb = jb.get(); + bool vb = jb.get(); CHECK(vb == true); - const int vi = jn.get(); + int vi = jn.get(); CHECK(vi == 42); // etc. diff --git a/nlohmann_json/tests/src/unit-regression1.cpp b/nlohmann_json/tests/src/unit-regression1.cpp index 47b00e85..64853dde 100644 --- a/nlohmann_json/tests/src/unit-regression1.cpp +++ b/nlohmann_json/tests/src/unit-regression1.cpp @@ -122,7 +122,7 @@ TEST_CASE("regression tests 1") SECTION("escape_doublequote") { const auto* s = R"(["\"foo\""])"; - const json j = json::parse(s); + json j = json::parse(s); auto expected = R"(["\"foo\""])"_json; CHECK(j == expected); } @@ -182,7 +182,7 @@ TEST_CASE("regression tests 1") j.push_back(t); // maybe this is not the place to test this? - const json j2 = u; + json j2 = u; auto anon_enum_value = j2.get(); CHECK(u == anon_enum_value); @@ -247,9 +247,9 @@ TEST_CASE("regression tests 1") auto test = j["Test"].get(); CHECK(test == "Test1"); - const int number{j["Number"]}; + int number{j["Number"]}; CHECK(number == 100); - const float foo{j["Foo"]}; + float foo{j["Foo"]}; CHECK(static_cast(foo) == Approx(42.42)); } @@ -371,7 +371,7 @@ TEST_CASE("regression tests 1") { json o = {{"name", "value"}}; - const std::string s1 = o["name"]; + std::string s1 = o["name"]; CHECK(s1 == "value"); std::string s2; @@ -607,8 +607,8 @@ TEST_CASE("regression tests 1") {"object", {{"key1", 1}, {"key2", 2}}}, }; - const int at_integer{j.at("/object/key2"_json_pointer)}; - const int val_integer = j.value("/object/key2"_json_pointer, 0); + int at_integer{j.at("/object/key2"_json_pointer)}; + int val_integer = j.value("/object/key2"_json_pointer, 0); CHECK(at_integer == val_integer); } @@ -1099,7 +1099,7 @@ TEST_CASE("regression tests 1") #if JSON_USE_IMPLICIT_CONVERSIONS SECTION("issue #464 - VS2017 implicit to std::string conversion fix") { - const json v = "test"; + json v = "test"; std::string test; test = v; CHECK(v == "test"); @@ -1109,9 +1109,9 @@ TEST_CASE("regression tests 1") SECTION("issue #465 - roundtrip error while parsing 1000000000000000010E5") { json const j1 = json::parse("1000000000000000010E5"); - const std::string s1 = j1.dump(); + std::string s1 = j1.dump(); json const j2 = json::parse(s1); - const std::string s2 = j2.dump(); + std::string s2 = j2.dump(); CHECK(s1 == s2); } @@ -1243,7 +1243,7 @@ TEST_CASE("regression tests 1") SECTION("example 1") { // create a map - const std::map m1 {{"key", 1}}; + std::map m1 {{"key", 1}}; // create and print a JSON from the map json const j = m1; @@ -1258,7 +1258,7 @@ TEST_CASE("regression tests 1") SECTION("example 2") { // create a map - const std::map m1 {{"key", "val"}}; + std::map m1 {{"key", "val"}}; // create and print a JSON from the map json const j = m1; @@ -1322,7 +1322,7 @@ TEST_CASE("regression tests 1") auto m1 = j1.get>(); auto m2 = j2.get>(); - const int i3{j3}; + int i3{j3}; CHECK( m1 == ( std::map {{ "first", "one" }} )); CHECK( m2 == ( std::map {{ "second", "two" }} )); @@ -1431,7 +1431,7 @@ TEST_CASE("regression tests 1") '1', '2', '3', 0xFF }; - const json j = json::from_cbor(v_cbor); + json j = json::from_cbor(v_cbor); CHECK(j == "abcd123"); } @@ -1477,7 +1477,7 @@ TEST_CASE("regression tests 1") }; // parse (with callback) and serialize JSON - const json j_filtered = json::parse(text, cb); + json j_filtered = json::parse(text, cb); CHECK(j_filtered == R"({"Image":{"Animated":false,"Height":600,"IDs":[116,943,234,38793], "Title":"View from 15th Floor","Width":800}})"_json); } @@ -1490,7 +1490,7 @@ TEST_CASE("regression tests 1") SECTION("issue #977 - Assigning between different json types") { foo_json lj = ns::foo{3}; - const ns::foo ff(lj); + ns::foo ff(lj); CHECK(lj.is_object()); CHECK(lj.size() == 1); CHECK(lj["x"] == 3); diff --git a/nlohmann_json/tests/src/unit-regression2.cpp b/nlohmann_json/tests/src/unit-regression2.cpp index 54b3fd59..2c3977fe 100644 --- a/nlohmann_json/tests/src/unit-regression2.cpp +++ b/nlohmann_json/tests/src/unit-regression2.cpp @@ -36,30 +36,6 @@ using ordered_json = nlohmann::ordered_json; #include #endif -#ifdef JSON_HAS_CPP_17 - #if __has_include() - #include - #elif __has_include() - #include - #endif - - ///////////////////////////////////////////////////////////////////// - // for #4804 - ///////////////////////////////////////////////////////////////////// - using json_4804 = nlohmann::basic_json, // BinaryType - void // CustomBaseClass - >; -#endif - #ifdef JSON_HAS_CPP_20 #if __has_include() #include @@ -412,20 +388,7 @@ struct Example_3810 Example_3810() = default; }; -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Example_3810, bla) // NOLINT(misc-use-internal-linkage) - -///////////////////////////////////////////////////////////////////// -// for #4740 -///////////////////////////////////////////////////////////////////// - -#ifdef JSON_HAS_CPP_17 -struct Example_4740 -{ - std::optional host = std::nullopt; - std::optional port = std::nullopt; - NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Example_4740, host, port) -}; -#endif +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Example_3810, bla); // NOLINT(misc-use-internal-linkage) TEST_CASE("regression tests 2") { @@ -565,7 +528,7 @@ TEST_CASE("regression tests 2") {"3", {{"a", "testa_3"}, {"b", "testb_3"}}}, }; - const std::map expected + std::map expected { {"1", {"testa_1", "testb_1"}}, {"2", {"testa_2", "testb_2"}}, @@ -582,7 +545,7 @@ TEST_CASE("regression tests 2") const auto length = 300; json dump_test; - dump_test["1"] = std::string(length, static_cast(-1)); + dump_test["1"] = std::string(length, -1); std::string expected = R"({"1":")"; for (int i = 0; i < length; ++i) @@ -599,7 +562,7 @@ TEST_CASE("regression tests 2") const auto length = 500; json dump_test; - dump_test["1"] = std::string(length, static_cast(-2)); + dump_test["1"] = std::string(length, -2); std::string expected = R"({"1":")"; for (int i = 0; i < length; ++i) @@ -658,7 +621,7 @@ TEST_CASE("regression tests 2") #if !(defined(__INTEL_COMPILER) && __cplusplus >= 202000) { const json j; - const NonDefaultFromJsonStruct x(j); + NonDefaultFromJsonStruct x(j); NonDefaultFromJsonStruct y; CHECK(x == y); } @@ -936,7 +899,7 @@ TEST_CASE("regression tests 2") SECTION("issue #2982 - to_{binary format} does not provide a mechanism for specifying a custom allocator for the returned type") { std::vector> my_vector; - const json j = {1, 2, 3, 4}; + json j = {1, 2, 3, 4}; json::to_cbor(j, my_vector); json k = json::from_cbor(my_vector); CHECK(j == k); @@ -1035,8 +998,8 @@ TEST_CASE("regression tests 2") SECTION("issue #3204 - ambiguous regression") { - const for_3204_bar bar_from_foo([](for_3204_foo) noexcept {}); // NOLINT(performance-unnecessary-value-param) - const for_3204_bar bar_from_json([](json) noexcept {}); // NOLINT(performance-unnecessary-value-param) + for_3204_bar bar_from_foo([](for_3204_foo) noexcept {}); // NOLINT(performance-unnecessary-value-param) + for_3204_bar bar_from_json([](json) noexcept {}); // NOLINT(performance-unnecessary-value-param) CHECK(bar_from_foo.constructed_from == for_3204_bar::constructed_from_foo); CHECK(bar_from_json.constructed_from == for_3204_bar::constructed_from_json); @@ -1049,7 +1012,7 @@ TEST_CASE("regression tests 2") {"x", 1}, {"y", 2} }; - const for_3333 p = j; + for_3333 p = j; CHECK(p.x == 1); CHECK(p.y == 2); @@ -1074,118 +1037,6 @@ TEST_CASE("regression tests 2") oj["test"] = states; CHECK(oj["test"].dump() == expected); } - -#ifdef JSON_HAS_CPP_17 - SECTION("issue #4740 - build issue with std::optional") - { - const auto t1 = Example_4740(); - const auto j1 = nlohmann::json(t1); - CHECK(j1.dump() == "{\"host\":null,\"port\":null}"); - const auto t2 = j1.get(); - CHECK(!t2.host.has_value()); - CHECK(!t2.port.has_value()); - - // improve coverage - auto t3 = Example_4740(); - t3.port = 80; - t3.host = "example.com"; - const auto j2 = nlohmann::json(t3); - CHECK(j2.dump() == "{\"host\":\"example.com\",\"port\":80}"); - const auto t4 = j2.get(); - CHECK(t4.host.has_value()); - CHECK(t4.port.has_value()); - } -#endif - -#if !defined(_MSVC_LANG) - // MSVC returns garbage on invalid enum values, so this test is excluded - // there. - SECTION("issue #4762 - json exception 302 with unhelpful explanation : type must be number, but is number") - { - // In #4762, the main issue was that a json object with an invalid type - // returned "number" as type_name(), because this was the default case. - // This test makes sure we now return "invalid" instead. - json j; - j.m_data.m_type = static_cast(100); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) - CHECK(j.type_name() == "invalid"); - } -#endif - -#ifdef JSON_HAS_CPP_17 - SECTION("issue #4804: from_cbor incompatible with std::vector as binary_t") - { - const std::vector data = {0x80}; - const auto decoded = json_4804::from_cbor(data); - CHECK((decoded == json_4804::array())); - } -#endif -} - -TEST_CASE_TEMPLATE("issue #4798 - nlohmann::json::to_msgpack() encode float NaN as double", T, double, float) // NOLINT(readability-math-missing-parentheses) -{ - // With issue #4798, we encode NaN, infinity, and -infinity as float instead - // of double to allow for smaller encodings. - const json jx = std::numeric_limits::quiet_NaN(); - const json jy = std::numeric_limits::infinity(); - const json jz = -std::numeric_limits::infinity(); - - ///////////////////////////////////////////////////////////////////////// - // MessagePack - ///////////////////////////////////////////////////////////////////////// - - // expected MessagePack values - const std::vector msgpack_x = {{0xCA, 0x7F, 0xC0, 0x00, 0x00}}; - const std::vector msgpack_y = {{0xCA, 0x7F, 0x80, 0x00, 0x00}}; - const std::vector msgpack_z = {{0xCA, 0xFF, 0x80, 0x00, 0x00}}; - - CHECK(json::to_msgpack(jx) == msgpack_x); - CHECK(json::to_msgpack(jy) == msgpack_y); - CHECK(json::to_msgpack(jz) == msgpack_z); - - CHECK(std::isnan(json::from_msgpack(msgpack_x).get())); - CHECK(json::from_msgpack(msgpack_y).get() == std::numeric_limits::infinity()); - CHECK(json::from_msgpack(msgpack_z).get() == -std::numeric_limits::infinity()); - - // Make sure the other MessagePakc encodings for NaN, infinity, and - // -infinity are still supported. - const std::vector msgpack_x_2 = {{0xCB, 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; - const std::vector msgpack_y_2 = {{0xCB, 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; - const std::vector msgpack_z_2 = {{0xCB, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; - CHECK(std::isnan(json::from_msgpack(msgpack_x_2).get())); - CHECK(json::from_msgpack(msgpack_y_2).get() == std::numeric_limits::infinity()); - CHECK(json::from_msgpack(msgpack_z_2).get() == -std::numeric_limits::infinity()); - - ///////////////////////////////////////////////////////////////////////// - // CBOR - ///////////////////////////////////////////////////////////////////////// - - // expected CBOR values - const std::vector cbor_x = {{0xF9, 0x7E, 0x00}}; - const std::vector cbor_y = {{0xF9, 0x7C, 0x00}}; - const std::vector cbor_z = {{0xF9, 0xfC, 0x00}}; - - CHECK(json::to_cbor(jx) == cbor_x); - CHECK(json::to_cbor(jy) == cbor_y); - CHECK(json::to_cbor(jz) == cbor_z); - - CHECK(std::isnan(json::from_cbor(cbor_x).get())); - CHECK(json::from_cbor(cbor_y).get() == std::numeric_limits::infinity()); - CHECK(json::from_cbor(cbor_z).get() == -std::numeric_limits::infinity()); - - // Make sure the other CBOR encodings for NaN, infinity, and -infinity are - // still supported. - const std::vector cbor_x_2 = {{0xFA, 0x7F, 0xC0, 0x00, 0x00}}; - const std::vector cbor_y_2 = {{0xFA, 0x7F, 0x80, 0x00, 0x00}}; - const std::vector cbor_z_2 = {{0xFA, 0xFF, 0x80, 0x00, 0x00}}; - const std::vector cbor_x_3 = {{0xFB, 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; - const std::vector cbor_y_3 = {{0xFB, 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; - const std::vector cbor_z_3 = {{0xFB, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; - CHECK(std::isnan(json::from_cbor(cbor_x_2).get())); - CHECK(json::from_cbor(cbor_y_2).get() == std::numeric_limits::infinity()); - CHECK(json::from_cbor(cbor_z_2).get() == -std::numeric_limits::infinity()); - CHECK(std::isnan(json::from_cbor(cbor_x_3).get())); - CHECK(json::from_cbor(cbor_y_3).get() == std::numeric_limits::infinity()); - CHECK(json::from_cbor(cbor_z_3).get() == -std::numeric_limits::infinity()); } DOCTEST_CLANG_SUPPRESS_WARNING_POP diff --git a/nlohmann_json/tests/src/unit-testsuites.cpp b/nlohmann_json/tests/src/unit-testsuites.cpp index ab1d6987..7e1600cc 100644 --- a/nlohmann_json/tests/src/unit-testsuites.cpp +++ b/nlohmann_json/tests/src/unit-testsuites.cpp @@ -10,9 +10,7 @@ #include using nlohmann::json; -#include -#include -#include + #include #include "make_test_data_available.hpp" @@ -60,13 +58,6 @@ TEST_CASE("compliance tests from json.org") }) { CAPTURE(filename) - //std::cout << "CWD: " << getcwd(nullptr, 0) << std::endl; - //struct stat buffer; - //if (stat(filename, &buffer) == 0) { - // std::cout << "File exists: " << filename << std::endl; - //} else { - // std::cout << "File does NOT exist: " << filename << std::endl; - //} std::ifstream f(filename); json _; CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&); diff --git a/nlohmann_json/tests/src/unit-to_chars.cpp b/nlohmann_json/tests/src/unit-to_chars.cpp index 0375d72d..4a548280 100644 --- a/nlohmann_json/tests/src/unit-to_chars.cpp +++ b/nlohmann_json/tests/src/unit-to_chars.cpp @@ -340,7 +340,7 @@ TEST_CASE("formatting") { std::array buf{}; char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - const std::string actual(buf.data(), end); + std::string actual(buf.data(), end); CHECK(actual == expected); }; @@ -400,7 +400,7 @@ TEST_CASE("formatting") { std::array buf{}; char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - const std::string actual(buf.data(), end); + std::string actual(buf.data(), end); CHECK(actual == expected); }; diff --git a/nlohmann_json/tests/src/unit-ubjson.cpp b/nlohmann_json/tests/src/unit-ubjson.cpp index 2093c057..895ccc89 100644 --- a/nlohmann_json/tests/src/unit-ubjson.cpp +++ b/nlohmann_json/tests/src/unit-ubjson.cpp @@ -2515,7 +2515,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": uint8_t* and size"); // parse JSON file std::ifstream f_json(filename); - const json j1 = json::parse(f_json); + json j1 = json::parse(f_json); // parse UBJSON file auto const packed = utils::read_binary_file(filename + ".ubjson"); diff --git a/nlohmann_json/tests/src/unit-udt.cpp b/nlohmann_json/tests/src/unit-udt.cpp index 97b6cc58..bc6bb7dc 100644 --- a/nlohmann_json/tests/src/unit-udt.cpp +++ b/nlohmann_json/tests/src/unit-udt.cpp @@ -735,14 +735,14 @@ TEST_CASE("different basic_json types conversions") SECTION("null") { json const j; - const custom_json cj = j; + custom_json cj = j; CHECK(cj == nullptr); } SECTION("boolean") { json const j = true; - const custom_json cj = j; + custom_json cj = j; CHECK(cj == true); } @@ -764,28 +764,28 @@ TEST_CASE("different basic_json types conversions") SECTION("integer") { json const j = 42; - const custom_json cj = j; + custom_json cj = j; CHECK(cj == 42); } SECTION("float") { json const j = 42.0; - const custom_json cj = j; + custom_json cj = j; CHECK(cj == 42.0); } SECTION("unsigned") { json const j = 42u; - const custom_json cj = j; + custom_json cj = j; CHECK(cj == 42u); } SECTION("string") { json const j = "forty-two"; - const custom_json cj = j; + custom_json cj = j; CHECK(cj == "forty-two"); } @@ -794,7 +794,7 @@ TEST_CASE("different basic_json types conversions") json j = json::binary({1, 2, 3}, 42); custom_json cj = j; CHECK(cj.get_binary().subtype() == 42); - const std::vector& cv = cj.get_binary(); + std::vector cv = cj.get_binary(); std::vector v = j.get_binary(); CHECK(cv == v); } @@ -802,7 +802,7 @@ TEST_CASE("different basic_json types conversions") SECTION("object") { json const j = {{"forty", "two"}}; - const custom_json cj = j; + custom_json cj = j; auto m = j.get>(); CHECK(cj == m); } @@ -810,7 +810,7 @@ TEST_CASE("different basic_json types conversions") SECTION("get") { json const j = 42; - const custom_json cj = j.get(); + custom_json cj = j.get(); CHECK(cj == 42); } } @@ -841,7 +841,7 @@ class Evil public: Evil() = default; template - Evil(const T& t) : m_i(sizeof(t)) + Evil(T t) : m_i(sizeof(t)) { static_cast(t); // fix MSVC's C4100 warning } @@ -861,12 +861,8 @@ TEST_CASE("Issue #924") CHECK_NOTHROW(j.get>()); // silence Wunused-template warnings - const Evil e(1); + Evil e(1); CHECK(e.m_i >= 0); - - // suppress warning: function "::Evil::Evil(T) [with T=std::string]" was declared but never referenced [declared_but_not_referenced] - const Evil e2(std::string("foo")); - CHECK(e2.m_i >= 0); } TEST_CASE("Issue #1237") diff --git a/nlohmann_json/tests/src/unit-udt_macro.cpp b/nlohmann_json/tests/src/unit-udt_macro.cpp index 63a38b78..5d204e45 100644 --- a/nlohmann_json/tests/src/unit-udt_macro.cpp +++ b/nlohmann_json/tests/src/unit-udt_macro.cpp @@ -640,7 +640,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv SECTION("alphabet") { - T obj1; // NOLINT(misc-const-correctness) + T obj1; Json const j = obj1; T obj2; j.get_to(obj2); diff --git a/nlohmann_json/tests/src/unit-user_defined_input.cpp b/nlohmann_json/tests/src/unit-user_defined_input.cpp index 5115e8fd..befc4b17 100644 --- a/nlohmann_json/tests/src/unit-user_defined_input.cpp +++ b/nlohmann_json/tests/src/unit-user_defined_input.cpp @@ -60,12 +60,12 @@ TEST_CASE("Custom container member begin/end") { const char* data; - const char* begin() const noexcept + const char* begin() const { return data; } - const char* end() const noexcept + const char* end() const { return data + strlen(data); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } diff --git a/nlohmann_json/tests/thirdparty/Fuzzer/build.sh b/nlohmann_json/tests/thirdparty/Fuzzer/build.sh old mode 100644 new mode 100755 diff --git a/nlohmann_json/tests/thirdparty/doctest/doctest.h b/nlohmann_json/tests/thirdparty/doctest/doctest.h index 2a29eb40..5c754cde 100644 --- a/nlohmann_json/tests/thirdparty/doctest/doctest.h +++ b/nlohmann_json/tests/thirdparty/doctest/doctest.h @@ -48,7 +48,7 @@ #define DOCTEST_VERSION_MAJOR 2 #define DOCTEST_VERSION_MINOR 4 -#define DOCTEST_VERSION_PATCH 12 +#define DOCTEST_VERSION_PATCH 11 // util we need here #define DOCTEST_TOSTR_IMPL(x) #x @@ -925,7 +925,6 @@ struct ContextOptions //!OCLINT too many fields bool no_skip; // don't skip test cases which are marked to be skipped bool gnu_file_line; // if line numbers should be surrounded with :x: and not (x): bool no_path_in_filenames; // if the path to files should be removed from the output - String strip_file_prefixes;// remove the longest matching one of these prefixes from any file paths in the output bool no_line_numbers; // if source code line numbers should be omitted from the output bool no_debug_output; // no output in the debug console when a debugger is attached bool no_skipped_summary; // don't print "skipped" in the summary !!! UNDOCUMENTED !!! @@ -1579,8 +1578,8 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP // https://github.com/catchorg/Catch2/issues/870 // https://github.com/catchorg/Catch2/issues/565 template - Expression_lhs operator<<(const L&& operand) { //bitfields bind to universal ref but not const rvalue ref - return Expression_lhs(static_cast(operand), m_at); + Expression_lhs operator<<(L&& operand) { + return Expression_lhs(static_cast(operand), m_at); } template ::value,void >::type* = nullptr> @@ -3244,10 +3243,6 @@ DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END #define DOCTEST_CONFIG_OPTIONS_PREFIX "dt-" #endif -#ifndef DOCTEST_CONFIG_OPTIONS_FILE_PREFIX_SEPARATOR -#define DOCTEST_CONFIG_OPTIONS_FILE_PREFIX_SEPARATOR ':' -#endif - #ifndef DOCTEST_THREAD_LOCAL #if defined(DOCTEST_CONFIG_NO_MULTITHREADING) || DOCTEST_MSVC && (DOCTEST_MSVC < DOCTEST_COMPILER(19, 0, 0)) #define DOCTEST_THREAD_LOCAL @@ -3756,7 +3751,7 @@ String::size_type String::capacity() const { } String String::substr(size_type pos, size_type cnt) && { - cnt = std::min(cnt, size() - pos); + cnt = std::min(cnt, size() - 1 - pos); char* cptr = c_str(); memmove(cptr, cptr + pos, cnt); setSize(cnt); @@ -3764,7 +3759,7 @@ String String::substr(size_type pos, size_type cnt) && { } String String::substr(size_type pos, size_type cnt) const & { - cnt = std::min(cnt, size() - pos); + cnt = std::min(cnt, size() - 1 - pos); return String{ c_str() + pos, cnt }; } @@ -3896,26 +3891,6 @@ const char* skipPathFromFilename(const char* file) { forward = back; return forward + 1; } - } else { - const auto prefixes = getContextOptions()->strip_file_prefixes; - const char separator = DOCTEST_CONFIG_OPTIONS_FILE_PREFIX_SEPARATOR; - String::size_type longest_match = 0U; - for(String::size_type pos = 0U; pos < prefixes.size(); ++pos) - { - const auto prefix_start = pos; - pos = std::min(prefixes.find(separator, prefix_start), prefixes.size()); - - const auto prefix_size = pos - prefix_start; - if(prefix_size > longest_match) - { - // TODO under DOCTEST_MSVC: does the comparison need strnicmp() to work with drive letter capitalization? - if(0 == std::strncmp(prefixes.c_str() + prefix_start, file, prefix_size)) - { - longest_match = prefix_size; - } - } - } - return &file[longest_match]; } #endif // DOCTEST_CONFIG_DISABLE return file; @@ -4497,12 +4472,11 @@ namespace { String translateActiveException() { #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS + String res; auto& translators = getExceptionTranslators(); - for(auto& curr : translators) { - String res; - if (curr->translate(res)) + for(auto& curr : translators) + if(curr->translate(res)) return res; - } // clang-format off DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wcatch-value") try { @@ -6207,8 +6181,6 @@ namespace { << Whitespace(sizePrefixDisplay*1) << ":n: vs (n): for line numbers in output\n"; s << " -" DOCTEST_OPTIONS_PREFIX_DISPLAY "npf, --" DOCTEST_OPTIONS_PREFIX_DISPLAY "no-path-filenames= " << Whitespace(sizePrefixDisplay*1) << "only filenames and no paths in output\n"; - s << " -" DOCTEST_OPTIONS_PREFIX_DISPLAY "spp, --" DOCTEST_OPTIONS_PREFIX_DISPLAY "skip-path-prefixes= " - << Whitespace(sizePrefixDisplay*1) << "whenever file paths start with this prefix, remove it from the output\n"; s << " -" DOCTEST_OPTIONS_PREFIX_DISPLAY "nln, --" DOCTEST_OPTIONS_PREFIX_DISPLAY "no-line-numbers= " << Whitespace(sizePrefixDisplay*1) << "0 instead of real line numbers in output\n"; // ================================================================================== << 79 @@ -6713,7 +6685,6 @@ void Context::parseArgs(int argc, const char* const* argv, bool withDefaults) { DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-skip", "ns", no_skip, false); DOCTEST_PARSE_AS_BOOL_OR_FLAG("gnu-file-line", "gfl", gnu_file_line, !bool(DOCTEST_MSVC)); DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-path-filenames", "npf", no_path_in_filenames, false); - DOCTEST_PARSE_STR_OPTION("strip-file-prefixes", "sfp", strip_file_prefixes, ""); DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-line-numbers", "nln", no_line_numbers, false); DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-debug-output", "ndo", no_debug_output, false); DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-skipped-summary", "nss", no_skipped_summary, false); diff --git a/nlohmann_json/tests/thirdparty/imapdl/filterbr.py b/nlohmann_json/tests/thirdparty/imapdl/filterbr.py old mode 100644 new mode 100755 diff --git a/nlohmann_json/tools/amalgamate/amalgamate.py b/nlohmann_json/tools/amalgamate/amalgamate.py old mode 100644 new mode 100755 diff --git a/nlohmann_json/tools/generate_natvis/generate_natvis.py b/nlohmann_json/tools/generate_natvis/generate_natvis.py old mode 100644 new mode 100755 diff --git a/nlohmann_json/tools/macro_builder/main.cpp b/nlohmann_json/tools/macro_builder/main.cpp index e676daac..2250d677 100644 --- a/nlohmann_json/tools/macro_builder/main.cpp +++ b/nlohmann_json/tools/macro_builder/main.cpp @@ -4,40 +4,39 @@ using namespace std; -void build_code(int max_args) -{ - stringstream ss; - ss << "#define NLOHMANN_JSON_EXPAND( x ) x" << endl; - ss << "#define NLOHMANN_JSON_GET_MACRO("; - for (int i = 0 ; i < max_args ; i++) - ss << "_" << i + 1 << ", "; - ss << "NAME,...) NAME" << endl; - - ss << "#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \\" << endl; - for (int i = max_args ; i > 1 ; i--) - ss << "NLOHMANN_JSON_PASTE" << i << ", \\" << endl; - ss << "NLOHMANN_JSON_PASTE1)(__VA_ARGS__))" << endl; - - ss << "#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)" << endl; - for (int i = 3 ; i <= max_args ; i++) - { - ss << "#define NLOHMANN_JSON_PASTE" << i << "(func, "; - for (int j = 1 ; j < i -1 ; j++) - ss << "v" << j << ", "; - ss << "v" << i-1 << ") NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE" << i-1 << "(func, "; - for (int j = 2 ; j < i-1 ; j++) - ss << "v" << j << ", "; - ss << "v" << i-1 << ")" << endl; - } - - cout << ss.str() << endl; -} +void build_code(int max_args) { + stringstream ss; + ss << "#define NLOHMANN_JSON_EXPAND( x ) x" << endl; + ss << "#define NLOHMANN_JSON_GET_MACRO("; + for (int i = 0; i < max_args; i++) + ss << "_" << i + 1 << ", "; + ss << "NAME,...) NAME" << endl; + + ss << "#define NLOHMANN_JSON_PASTE(...) " + "NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \\" + << endl; + for (int i = max_args; i > 1; i--) + ss << "NLOHMANN_JSON_PASTE" << i << ", \\" << endl; + ss << "NLOHMANN_JSON_PASTE1)(__VA_ARGS__))" << endl; + + ss << "#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)" << endl; + for (int i = 3; i <= max_args; i++) { + ss << "#define NLOHMANN_JSON_PASTE" << i << "(func, "; + for (int j = 1; j < i - 1; j++) + ss << "v" << j << ", "; + ss << "v" << i - 1 << ") NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE" + << i - 1 << "(func, "; + for (int j = 2; j < i - 1; j++) + ss << "v" << j << ", "; + ss << "v" << i - 1 << ")" << endl; + } -int main(int argc, char** argv) -{ - int max_args = 64; - build_code(max_args); - - return 0; + cout << ss.str() << endl; } +int main(int argc, char **argv) { + int max_args = 64; + build_code(max_args); + + return 0; +} diff --git a/nlohmann_json/tools/serve_header/README.md b/nlohmann_json/tools/serve_header/README.md index 0d0ed69f..123fd447 100644 --- a/nlohmann_json/tools/serve_header/README.md +++ b/nlohmann_json/tools/serve_header/README.md @@ -17,7 +17,7 @@ The header file is automatically amalgamated on demand. (see `tools/serve_header/requirements.txt`) 2. To serve the header over HTTPS (which is required by Compiler Explorer at this time), a certificate is needed. - The recommended method for creating a locally trusted certificate is to use [`mkcert`](https://github.com/FiloSottile/mkcert). + The recommended method for creating a locally-trusted certificate is to use [`mkcert`](https://github.com/FiloSottile/mkcert). - Install the `mkcert` certificate authority into your trust store(s): ``` $ mkcert -install diff --git a/nlohmann_json/tools/serve_header/serve_header.py b/nlohmann_json/tools/serve_header/serve_header.py old mode 100644 new mode 100755