diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a9c0b46923..1529ab9911 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -22,17 +22,17 @@ Clearly describe the issue: - 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. -Please stick to the provided issue templates ([bug report](https://github.com/nlohmann/json/blob/develop/.github/ISSUE_TEMPLATE/Bug_report.md), [feature request](https://github.com/nlohmann/json/blob/develop/.github/ISSUE_TEMPLATE/Feature_request.md), or [question](https://github.com/nlohmann/json/blob/develop/.github/ISSUE_TEMPLATE/question.md)) if possible. +Please stick to the provided issue template ([bug report](https://github.com/nlohmann/json/blob/develop/.github/ISSUE_TEMPLATE/bug.yml) if possible. For questions, feature or support requests, please [open a discussion](https://github.com/nlohmann/json/discussions/new). ## Files to change -:exclamation: Before you make any changes, note the single-header file [`single_include/nlohmann/json.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp) is **generated** from the source files in the [`include/nlohmann` directory](https://github.com/nlohmann/json/tree/develop/include/nlohmann). Please **do not** edit file `single_include/nlohmann/json.hpp` directly, but change the `include/nlohmann` sources and regenerate file `single_include/nlohmann/json.hpp` by executing `make amalgamate`. +:exclamation: Before you make any changes, note the single-header files [`single_include/nlohmann/json.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp) and [`single_include/nlohmann/json_fwd.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json_fwd.hpp) are **generated** from the source files in the [`include/nlohmann` directory](https://github.com/nlohmann/json/tree/develop/include/nlohmann). Please **do not** edit the files `single_include/nlohmann/json.hpp` and `single_include/nlohmann/json_fwd.hpp` directly, but change the `include/nlohmann` sources and regenerate the files by executing `make amalgamate`. To make changes, you need to edit the following files: -1. [`include/nlohmann/*`](https://github.com/nlohmann/json/tree/develop/include/nlohmann) - These files are the sources of the library. Before testing or creating a pull request, execute `make amalgamate` to regenerate `single_include/nlohmann/json.hpp`. +1. [`include/nlohmann/*`](https://github.com/nlohmann/json/tree/develop/include/nlohmann) - These files are the sources of the library. Before testing or creating a pull request, execute `make amalgamate` to regenerate `single_include/nlohmann/json.hpp` and `single_include/nlohmann/json_fwd.hpp`. -2. [`test/src/unit-*.cpp`](https://github.com/nlohmann/json/tree/develop/test/src) - These files contain the [doctest](https://github.com/onqtam/doctest) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code. +2. [`tests/src/unit-*.cpp`](https://github.com/nlohmann/json/tree/develop/tests/src) - These files contain the [doctest](https://github.com/onqtam/doctest) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code. If you add or change a feature, please also add a unit test to this file. The unit tests can be compiled and executed with diff --git a/.github/ISSUE_TEMPLATE/bug.yaml b/.github/ISSUE_TEMPLATE/bug.yaml index c168a9c5d8..571a1cc447 100644 --- a/.github/ISSUE_TEMPLATE/bug.yaml +++ b/.github/ISSUE_TEMPLATE/bug.yaml @@ -76,7 +76,7 @@ body: label: Library version description: > Which version of the library did you use? If it is a released version, - please enter the version number (e.g., 3.11.1). Otherwise, please enter + please enter the version number (e.g., 3.11.2). Otherwise, please enter the commit hash. If you got the library from another source as the GitHub repository (e.g., via a package manager), please also state this. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 5f303a6e0a..56854fb7a0 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -9,7 +9,7 @@ Read the [Contribution Guidelines](https://github.com/nlohmann/json/blob/develop - [ ] Changes are described in the pull request, or an [existing issue is referenced](https://github.com/nlohmann/json/issues). - [ ] The test suite [compiles and runs](https://github.com/nlohmann/json/blob/develop/README.md#execute-unit-tests) without error. - [ ] [Code coverage](https://coveralls.io/github/nlohmann/json) is 100%. Test cases can be added by editing the [test suite](https://github.com/nlohmann/json/tree/develop/test/src). -- [ ] The source code is amalgamated; that is, after making changes to the sources in the `include/nlohmann` directory, run `make amalgamate` to create the single-header file `single_include/nlohmann/json.hpp`. The whole process is described [here](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#files-to-change). +- [ ] The source code is amalgamated; that is, after making changes to the sources in the `include/nlohmann` directory, run `make amalgamate` to create the single-header files `single_include/nlohmann/json.hpp` and `single_include/nlohmann/json_fwd.hpp`. The whole process is described [here](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#files-to-change). ## Please don't diff --git a/.github/external_ci/appveyor.yml b/.github/external_ci/appveyor.yml index 0a7de686da..126ed99b35 100644 --- a/.github/external_ci/appveyor.yml +++ b/.github/external_ci/appveyor.yml @@ -1,5 +1,19 @@ 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) +branches: + only: + - develop + +only_commits: + files: + - .github/external_ci/appveyor.yml + - cmake/ + - include/ + - tests/ + - CMakeLists.txt + environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -75,9 +89,3 @@ test_script: # occasional timeouts on AppVeyor. # More info: https://github.com/nlohmann/json/pull/1570 - if "%configuration%"=="Debug" ctest --exclude-regex "test-unicode" -C "%configuration%" --parallel 2 --output-on-failure - -# only build PRs and commits to develop branch -# (see https://help.appveyor.com/discussions/questions/55079-two-builds-per-commit-to-pull-request) -branches: - only: - - develop diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000000..024d3e6da2 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +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 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 1ba938cd64..7ba83ac1c7 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -23,38 +23,15 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can check out the head. - fetch-depth: 2 - - # If this run was triggered by a pull request event, then checkout - # the head of the pull request instead of the merge commit. - - run: git checkout HEAD^2 - if: ${{ github.event_name == 'pull_request' }} # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v2 - # Override language selection by uncommenting this and choosing your languages - # with: - # languages: go, javascript, csharp, python, cpp, java # 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@v2 - # ℹ️ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000000..66cb7eb348 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,18 @@ +name: "Pull Request Labeler" + +on: + pull_request_target: + types: [opened, synchronize] + +jobs: + label: + permissions: + contents: read + pull-requests: write + + runs-on: ubuntu-latest + + steps: + - uses: srvaroa/labeler@master + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 85b1b70524..7eaedd73c1 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -15,37 +15,37 @@ concurrency: jobs: xcode_1: - runs-on: macos-10.15 + runs-on: macos-11 strategy: matrix: - xcode: [12.4, 12.3, 12.2, 12.1.1, 12.1, 12, 11.7, 11.6, 11.5, 11.4.1, 11.3.1, 11.2.1, 10.3] + xcode: ['11.7', '12.4', '12.5.1', '13.0'] env: DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON - - name: build + - name: Build run: cmake --build build --parallel 10 - - name: test + - name: Test run: cd build ; ctest -j 10 --output-on-failure xcode_2: runs-on: macos-12 strategy: matrix: - xcode: [13.3.1, 13.3, 13.2.1, 13.2, 13.1] + xcode: ['13.1', '13.2.1', '13.3.1', '13.4.1'] env: DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON - - name: build + - name: Build run: cmake --build build --parallel 10 - - name: test + - name: Test run: cd build ; ctest -j 10 --output-on-failure xcode_standards: @@ -58,9 +58,9 @@ jobs: steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_TestStandards=${{ matrix.standard }} - - name: build + - name: Build run: cmake --build build --parallel 10 - - name: test + - name: Test run: cd build ; ctest -j 10 --output-on-failure diff --git a/.github/workflows/publish_documentation.yml b/.github/workflows/publish_documentation.yml new file mode 100644 index 0000000000..65c42a74e0 --- /dev/null +++ b/.github/workflows/publish_documentation.yml @@ -0,0 +1,32 @@ +name: Publish documentation + +# publish the documentation on every merge to develop branch +on: + push: + branches: + - develop + paths: + - docs/mkdocs/** + - docs/examples/** + workflow_dispatch: + +# we don't want to have concurrent jobs, and we don't want to cancel running jobs to avoid broken publications +concurrency: + group: documentation + cancel-in-progress: false + +jobs: + publish_documentation: + if: github.repository == 'nlohmann/json' + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - name: Install and update PlantUML + run: sudo apt-get update ; sudo apt-get install -y plantuml + + - name: Install virtual environment + run: make install_venv -C docs/mkdocs + + - name: Publish documentation + run: make publish -C docs/mkdocs diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 7fd292f78f..eff653cc40 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -19,9 +19,9 @@ jobs: container: ghcr.io/nlohmann/json-ci:v2.4.0 steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build + - name: Build run: cmake --build build --target ci_test_clang ci_test_gcc: @@ -29,9 +29,9 @@ jobs: container: ghcr.io/nlohmann/json-ci:v2.4.0 steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build + - name: Build run: cmake --build build --target ci_test_gcc ci_static_analysis: @@ -42,9 +42,9 @@ jobs: target: [ci_clang_tidy, ci_cppcheck, ci_test_valgrind, ci_test_clang_sanitizer, ci_test_amalgamation, ci_clang_analyze, ci_cpplint, ci_cmake_flags, ci_single_binaries, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_infer] steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build + - name: Build run: cmake --build build --target ${{ matrix.target }} ci_test_single_header: @@ -52,9 +52,9 @@ jobs: container: ghcr.io/nlohmann/json-ci:v2.4.0 steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build + - name: Build run: cmake --build build --target ci_test_single_header ci_cmake_options: @@ -65,9 +65,9 @@ jobs: target: [ci_test_diagnostics, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls] steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build + - name: Build run: cmake --build build --target ${{ matrix.target }} ci_test_coverage: @@ -75,20 +75,20 @@ jobs: container: ghcr.io/nlohmann/json-ci:v2.4.0 steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build + - name: Build run: cmake --build build --target ci_test_coverage - - name: archive coverage report + - name: Archive coverage report uses: actions/upload-artifact@v3 with: name: code-coverage-report - path: /__w/json/json/build/html - - name: Coveralls + path: ${{ github.workspace }}/build/html + - name: Publish report to Coveralls uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: /__w/json/json/build/json.info.filtered.noexcept + path-to-lcov: ${{ github.workspace }}/build/json.info.filtered.noexcept ci_test_compilers: runs-on: ubuntu-latest @@ -98,9 +98,9 @@ jobs: compiler: [g++-4.8, g++-4.9, g++-5, g++-6, g++-7, g++-8, g++-9, g++-10, g++-11, clang++-3.5, clang++-3.6, clang++-3.7, clang++-3.8, clang++-3.9, clang++-4.0, clang++-5.0, clang++-6.0, clang++-7, clang++-8, clang++-9, clang++-10, clang++-11, clang++-12, clang++-13, clang++-14] steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build + - name: Build run: cmake --build build --target ci_test_compiler_${{ matrix.compiler }} ci_test_standards: @@ -112,9 +112,9 @@ jobs: compiler: [gcc, clang] steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build + - name: Build run: cmake --build build --target ci_test_${{ matrix.compiler }}_cxx${{ matrix.standard }} ci_cuda_example: @@ -122,9 +122,9 @@ jobs: container: ghcr.io/nlohmann/json-ci:v2.4.0 steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build + - name: Build run: cmake --build build --target ci_cuda_example ci_icpc: @@ -132,27 +132,31 @@ jobs: container: ghcr.io/nlohmann/json-ci:v2.2.0 steps: - uses: actions/checkout@v2 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build + - name: Build run: | . /opt/intel/oneapi/setvars.sh cmake --build build --target ci_icpc + ci_reuse_compliance: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - - name: install REUSE tool + - name: Install REUSE tool run: python -m pip install reuse - - name: REUSE lint + - name: Run REUSE lint run: reuse lint ci_test_documentation: runs-on: ubuntu-latest + strategy: + matrix: + target: [ci_test_examples, ci_test_api_documentation] steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -DJSON_CI=On - - name: build - run: cmake --build build --target ci_test_documentation + - name: Build + run: cmake --build build --target ${{ matrix.target }} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 0fd723c84f..fb4b893d69 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -47,11 +47,11 @@ jobs: # uses: egor-tensin/setup-mingw@v2 # with: # platform: ${{ matrix.architecture }} - - name: cmake + - name: Run CMake run: cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On - - name: build + - name: Build run: cmake --build build --parallel 10 - - name: test + - name: Test run: cd build ; ctest -j 10 -C Debug --output-on-failure msvc2019: @@ -63,15 +63,15 @@ jobs: steps: - uses: actions/checkout@v3 - - name: cmake + - 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: cmake + - 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 + - name: Build run: cmake --build build --config ${{ matrix.build_type }} --parallel 10 - - name: test + - name: Test run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure msvc2019_latest: @@ -79,11 +79,11 @@ jobs: steps: - uses: actions/checkout@v3 - - name: cmake + - 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 + - name: Build run: cmake --build build --config Release --parallel 10 - - name: test + - name: Test run: cd build ; ctest -j 10 -C Release --output-on-failure msvc2022: @@ -95,15 +95,15 @@ jobs: steps: - uses: actions/checkout@v3 - - name: cmake + - 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: cmake + - 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 + - name: Build run: cmake --build build --config ${{ matrix.build_type }} --parallel 10 - - name: test + - name: Test run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure msvc2022_latest: @@ -111,11 +111,11 @@ jobs: steps: - uses: actions/checkout@v3 - - name: cmake + - 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 + - name: Build run: cmake --build build --config Release --parallel 10 - - name: test + - name: Test run: cd build ; ctest -j 10 -C Release --output-on-failure clang: @@ -126,13 +126,13 @@ jobs: steps: - uses: actions/checkout@v3 - - name: install Clang + - name: Install Clang run: curl -fsSL -o LLVM${{ matrix.version }}.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.version }}.0.0/LLVM-${{ matrix.version }}.0.0-win64.exe ; 7z x LLVM${{ matrix.version }}.exe -y -o"C:/Program Files/LLVM" - - name: cmake + - name: Run CMake run: cmake -S . -B build -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On - - name: build + - name: Build run: cmake --build build --parallel 10 - - name: test + - name: Test run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure clang-cl-11: @@ -143,9 +143,9 @@ jobs: steps: - uses: actions/checkout@v3 - - name: cmake + - name: Run CMake run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -T ClangCL -DJSON_BuildTests=On - - name: build + - name: Build run: cmake --build build --config Debug --parallel 10 - - name: test + - name: Test run: cd build ; ctest -j 10 -C Debug --exclude-regex "test-unicode" --output-on-failure diff --git a/.lgtm.yml b/.lgtm.yml new file mode 100644 index 0000000000..b62f9fb37b --- /dev/null +++ b/.lgtm.yml @@ -0,0 +1,4 @@ +path_classifiers: + thirdparty: + - /tools/amalgamate + - /tools/cpplint diff --git a/.reuse/templates/json.jinja2 b/.reuse/templates/json.jinja2 index e2d997862a..4abf481b74 100644 --- a/.reuse/templates/json.jinja2 +++ b/.reuse/templates/json.jinja2 @@ -1,6 +1,6 @@ __ _____ _____ _____ __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 3.11.1 +| | |__ | | | | | | version 3.11.2 |_____|_____|_____|_|___| https://github.com/nlohmann/json {% for copyright_line in copyright_lines %} diff --git a/.reuse/templates/json_support.jinja2 b/.reuse/templates/json_support.jinja2 index f46034566a..1fab99fab7 100644 --- a/.reuse/templates/json_support.jinja2 +++ b/.reuse/templates/json_support.jinja2 @@ -1,6 +1,6 @@ __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (supporting code) -| | |__ | | | | | | version 3.11.1 +| | |__ | | | | | | version 3.11.2 |_____|_____|_____|_|___| https://github.com/nlohmann/json {% for copyright_line in copyright_lines %} diff --git a/CITATION.cff b/CITATION.cff index 07848fac94..cc9d7022d8 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -7,8 +7,8 @@ authors: email: mail@nlohmann.me website: https://nlohmann.me title: "JSON for Modern C++" -version: 3.11.1 -date-released: 2022-01-03 +version: 3.11.2 +date-released: 2022-08-12 license: MIT repository-code: "https://github.com/nlohmann" url: https://json.nlohmann.me diff --git a/CMakeLists.txt b/CMakeLists.txt index 8268cede0f..d88feb5c2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.1) ## PROJECT ## name and version ## -project(nlohmann_json VERSION 3.11.1 LANGUAGES CXX) +project(nlohmann_json VERSION 3.11.2 LANGUAGES CXX) ## ## MAIN_PROJECT CHECK diff --git a/ChangeLog.md b/ChangeLog.md index dfbacdac1f..656d68bcfc 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,9 +1,49 @@ # Changelog All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [3.11.1](https://github.com/nlohmann/json/releases/tag/3.11.1) (2022-08-01) - -[Full Changelog](https://github.com/nlohmann/json/compare/v3.11.0...3.11.1) +## [3.11.2](https://github.com/nlohmann/json/releases/tag/3.11.2) (2022-08-12) + +[Full Changelog](https://github.com/nlohmann/json/compare/v3.11.1...3.11.2) + +- MSVC natvis visualizer does not work after introduction of inline ABI namespace [\#3696](https://github.com/nlohmann/json/issues/3696) +- The use of parenthesis gives compilation errors in some situations [\#3682](https://github.com/nlohmann/json/issues/3682) +- extern from/to\_json result in linker error [\#3657](https://github.com/nlohmann/json/issues/3657) +- json\_fwd.hpp no longer standalone [\#3656](https://github.com/nlohmann/json/issues/3656) +- regression: `.value` is compilation error. [\#3655](https://github.com/nlohmann/json/issues/3655) +- Regression: no match for 'operator!=' comparing json\_pointer and const char \*/string\_t [\#3654](https://github.com/nlohmann/json/issues/3654) +- Regression: call to member function 'value' is ambiguous [\#3652](https://github.com/nlohmann/json/issues/3652) +- macOS 10.15 Actions runner image deprecation [\#3612](https://github.com/nlohmann/json/issues/3612) + +- generate\_natvis.py: validate version number; cleanup [\#3698](https://github.com/nlohmann/json/pull/3698) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Add Python script for generating Natvis file and update file for 3.11.2 [\#3697](https://github.com/nlohmann/json/pull/3697) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- fix typo in json\_pointer.md [\#3692](https://github.com/nlohmann/json/pull/3692) ([eltociear](https://github.com/eltociear)) +- Add amalgamated json-fwd.hpp to release [\#3687](https://github.com/nlohmann/json/pull/3687) ([nlohmann](https://github.com/nlohmann)) +- Documentation updates for 3.11.2 [\#3686](https://github.com/nlohmann/json/pull/3686) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Make json\_pointer usable as map key \(again\) [\#3685](https://github.com/nlohmann/json/pull/3685) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Deprecate json\_pointer/string\_t comparisons [\#3684](https://github.com/nlohmann/json/pull/3684) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Restructure inline namespace and allow version component to be disabled [\#3683](https://github.com/nlohmann/json/pull/3683) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Properly constrain non-string json\_pointer overloads [\#3681](https://github.com/nlohmann/json/pull/3681) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Amalgamate the forward declaration header [\#3679](https://github.com/nlohmann/json/pull/3679) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Fix 'const' qualifier on bool& has no effect [\#3678](https://github.com/nlohmann/json/pull/3678) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Fix whitespace in workflow files [\#3675](https://github.com/nlohmann/json/pull/3675) ([nlohmann](https://github.com/nlohmann)) +- Attempt to fix labeler permissions [\#3674](https://github.com/nlohmann/json/pull/3674) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Refine 'Publish documentation' workflow [\#3673](https://github.com/nlohmann/json/pull/3673) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Documentation change [\#3672](https://github.com/nlohmann/json/pull/3672) ([nlohmann](https://github.com/nlohmann)) +- Add labeler action [\#3671](https://github.com/nlohmann/json/pull/3671) ([nlohmann](https://github.com/nlohmann)) +- Complete contributor list [\#3670](https://github.com/nlohmann/json/pull/3670) ([nlohmann](https://github.com/nlohmann)) +- Add json\_pointer/string\_t equality comparison operators [\#3664](https://github.com/nlohmann/json/pull/3664) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Reimplement value\(\) access functions [\#3663](https://github.com/nlohmann/json/pull/3663) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Complete contributor list [\#3662](https://github.com/nlohmann/json/pull/3662) ([nlohmann](https://github.com/nlohmann)) +- Adjust naming of GitHub action jobs [\#3661](https://github.com/nlohmann/json/pull/3661) ([nlohmann](https://github.com/nlohmann)) +- Publish documentation on push to develop branch [\#3660](https://github.com/nlohmann/json/pull/3660) ([nlohmann](https://github.com/nlohmann)) +- Add Discord badge to README [\#3651](https://github.com/nlohmann/json/pull/3651) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Miscellaneous small fixes [\#3643](https://github.com/nlohmann/json/pull/3643) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Minor BJData fixes [\#3637](https://github.com/nlohmann/json/pull/3637) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) +- Update CI [\#3626](https://github.com/nlohmann/json/pull/3626) ([falbrechtskirchinger](https://github.com/falbrechtskirchinger)) + +## [v3.11.1](https://github.com/nlohmann/json/releases/tag/v3.11.1) (2022-08-01) + +[Full Changelog](https://github.com/nlohmann/json/compare/v3.11.0...v3.11.1) - Regression: no matching literal operator for call to 'operator""\_json' [\#3645](https://github.com/nlohmann/json/issues/3645) - \_json operator""\(\) [\#3644](https://github.com/nlohmann/json/issues/3644) diff --git a/Makefile b/Makefile index 1f220b2618..18b08a51ab 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,9 @@ SRCS=$(shell find include -type f | sort) # the list of sources in the tests folder TESTS_SRCS=$(shell find tests -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort) -# the single header (amalgamated from the source files) +# the single headers (amalgamated from the source files) AMALGAMATED_FILE=single_include/nlohmann/json.hpp +AMALGAMATED_FWD_FILE=single_include/nlohmann/json_fwd.hpp ########################################################################## @@ -28,7 +29,7 @@ AMALGAMATED_FILE=single_include/nlohmann/json.hpp # main target all: - @echo "amalgamate - amalgamate file single_include/nlohmann/json.hpp from the include/nlohmann sources" + @echo "amalgamate - amalgamate files single_include/nlohmann/json{,_fwd}.hpp from the include/nlohmann sources" @echo "ChangeLog.md - generate ChangeLog file" @echo "check-amalgamation - check whether sources have been amalgamated" @echo "clean - remove built files" @@ -144,9 +145,9 @@ pvs_studio: # call the Artistic Style pretty printer on all source files pretty: astyle \ - --style=allman \ - --indent=spaces=4 \ - --indent-modifiers \ + --style=allman \ + --indent=spaces=4 \ + --indent-modifiers \ --indent-switches \ --indent-preproc-block \ --indent-preproc-define \ @@ -162,27 +163,34 @@ pretty: --preserve-date \ --suffix=none \ --formatted \ - $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/examples/*.cpp + $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) docs/examples/*.cpp # call the Clang-Format on all source files pretty_format: for FILE in $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done -# create single header file -amalgamate: $(AMALGAMATED_FILE) +# create single header files and pretty print +amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) + $(MAKE) pretty -# call the amalgamation tool and pretty print +# call the amalgamation tool for json.hpp $(AMALGAMATED_FILE): $(SRCS) - tools/amalgamate/amalgamate.py -c tools/amalgamate/config.json -s . --verbose=yes - $(MAKE) pretty + tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json.json -s . --verbose=yes + +# call the amalgamation tool for json_fwd.hpp +$(AMALGAMATED_FWD_FILE): $(SRCS) + tools/amalgamate/amalgamate.py -c tools/amalgamate/config_json_fwd.json -s . --verbose=yes # check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources # Note: this target is called by Travis check-amalgamation: @mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~ + @mv $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~ @$(MAKE) amalgamate @diff $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE) ; false) + @diff $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~ || (echo "===================================================================\n Amalgamation required! Please read the contribution guidelines\n in file .github/CONTRIBUTING.md.\n===================================================================" ; mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE) ; false) @mv $(AMALGAMATED_FILE)~ $(AMALGAMATED_FILE) + @mv $(AMALGAMATED_FWD_FILE)~ $(AMALGAMATED_FWD_FILE) ########################################################################## @@ -224,9 +232,11 @@ release: include.zip json.tar.xz mkdir release_files gpg --armor --detach-sig include.zip gpg --armor --detach-sig $(AMALGAMATED_FILE) + gpg --armor --detach-sig $(AMALGAMATED_FWD_FILE) gpg --armor --detach-sig json.tar.xz cp $(AMALGAMATED_FILE) release_files - mv $(AMALGAMATED_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files + cp $(AMALGAMATED_FWD_FILE) release_files + mv $(AMALGAMATED_FILE).asc $(AMALGAMATED_FWD_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files cd release_files ; shasum -a 256 json.hpp include.zip json.tar.xz > hashes.txt diff --git a/README.md b/README.md index a1e59e7c56..d74aa7b1f8 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/289/badge)](https://bestpractices.coreinfrastructure.org/projects/289) [![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) - [Design goals](#design-goals) - [Sponsors](#sponsors) @@ -1143,24 +1144,14 @@ The following compilers are currently used in continuous integration at [AppVeyo | Compiler | Operating System | CI Provider | |--------------------------------------------------------------------------------------------------------|--------------------|----------------| -| Apple Clang 10.0.1 (clang-1001.0.46.4); Xcode 10.3 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 11.0.0 (clang-1100.0.33.12); Xcode 11.2.1 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 11.0.0 (clang-1100.0.33.17); Xcode 11.3.1 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 11.0.3 (clang-1103.0.32.59); Xcode 11.4.1 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 11.0.3 (clang-1103.0.32.62); Xcode 11.5 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 11.0.3 (clang-1103.0.32.62); Xcode 11.6 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 11.0.3 (clang-1103.0.32.62); Xcode 11.7 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 12.0.0 (clang-1200.0.32.2); Xcode 12 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 12.0.0 (clang-1200.0.32.21); Xcode 12.1 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 12.0.0 (clang-1200.0.32.21); Xcode 12.1.1 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 12.0.0 (clang-1200.0.32.27); Xcode 12.2 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 12.0.0 (clang-1200.0.32.28); Xcode 12.3 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 12.0.0 (clang-1200.0.32.29); Xcode 12.4 | macOS 10.15.7 | GitHub Actions | -| Apple Clang 13.0.0 (clang-1300.0.29.3); Xcode 13.1 | macOS 12.3.1 | GitHub Actions | -| Apple Clang 13.0.0 (clang-1300.0.29.30); Xcode 13.2 | macOS 12.3.1 | GitHub Actions | -| Apple Clang 13.0.0 (clang-1300.0.29.30); Xcode 13.2.1 | macOS 12.3.1 | GitHub Actions | -| Apple Clang 13.1.6 (clang-1316.0.21.2); Xcode 13.3 | macOS 12.3.1 | GitHub Actions | -| Apple Clang 13.1.6 (clang-1316.0.21.2.3); Xcode 13.3.1 | macOS 12.3.1 | GitHub Actions | +| Apple Clang 11.0.3 (clang-1103.0.32.62); Xcode 11.7 | macOS 11.6.8 | GitHub Actions | +| Apple Clang 12.0.0 (clang-1200.0.32.29); Xcode 12.4 | macOS 11.6.8 | GitHub Actions | +| Apple Clang 12.0.5 (clang-1205.0.22.11); Xcode 12.5.1 | macOS 11.6.8 | GitHub Actions | +| Apple Clang 13.0.0 (clang-1300.0.29.3); Xcode 13.0 | macOS 11.6.8 | GitHub Actions | +| Apple Clang 13.0.0 (clang-1300.0.29.3); Xcode 13.1 | macOS 12.4 | GitHub Actions | +| Apple Clang 13.0.0 (clang-1300.0.29.30); Xcode 13.2.1 | macOS 12.4 | GitHub Actions | +| Apple Clang 13.1.6 (clang-1316.0.21.2.3); Xcode 13.3.1 | macOS 12.4 | GitHub Actions | +| Apple Clang 13.1.6 (clang-1316.0.21.2.5); Xcode 13.4.1 | macOS 12.4 | GitHub Actions | | Clang 3.5.2 (3.5.2-3ubuntu1) | Ubuntu 20.04.3 LTS | GitHub Actions | | Clang 3.6.2 (3.6.2-3ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions | | Clang 3.7.1 (3.7.1-2ubuntu2) | Ubuntu 20.04.3 LTS | GitHub Actions | @@ -1271,7 +1262,7 @@ Example: ```cmake include(FetchContent) -FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.1/json.tar.xz) +FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz) FetchContent_MakeAvailable(json) target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json) @@ -1411,288 +1402,322 @@ I deeply appreciate the help of the following people. -- [Teemperor](https://github.com/Teemperor) implemented CMake support and lcov integration, realized escape and Unicode handling in the string parser, and fixed the JSON serialization. -- [elliotgoodrich](https://github.com/elliotgoodrich) fixed an issue with double deletion in the iterator classes. -- [kirkshoop](https://github.com/kirkshoop) made the iterators of the class composable to other libraries. -- [wancw](https://github.com/wanwc) fixed a bug that hindered the class to compile with Clang. -- Tomas Åblad found a bug in the iterator implementation. -- [Joshua C. Randall](https://github.com/jrandall) fixed a bug in the floating-point serialization. -- [Aaron Burghardt](https://github.com/aburgh) implemented code to parse streams incrementally. Furthermore, he greatly improved the parser class by allowing the definition of a filter function to discard undesired elements while parsing. -- [Daniel Kopeček](https://github.com/dkopecek) fixed a bug in the compilation with GCC 5.0. -- [Florian Weber](https://github.com/Florianjw) fixed a bug in and improved the performance of the comparison operators. -- [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. -- [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums. -- [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual studio. -- [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. -- [Caio Luppi](https://github.com/caiovlp) fixed a bug in the Unicode handling. -- [dariomt](https://github.com/dariomt) fixed some typos in the examples. -- [Daniel Frey](https://github.com/d-frey) cleaned up some pointers and implemented exception-safe memory allocation. -- [Colin Hirsch](https://github.com/ColinH) took care of a small namespace issue. -- [Huu Nguyen](https://github.com/whoshuu) correct a variable name in the documentation. -- [Silverweed](https://github.com/silverweed) overloaded `parse()` to accept an rvalue reference. -- [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. -- [ZahlGraf](https://github.com/ZahlGraf) added a workaround that allows compilation using Android NDK. -- [whackashoe](https://github.com/whackashoe) replaced a function that was marked as unsafe by Visual Studio. -- [406345](https://github.com/406345) fixed two small warnings. -- [Glen Fernandes](https://github.com/glenfe) noted a potential portability problem in the `has_mapped_type` function. -- [Corbin Hughes](https://github.com/nibroc) fixed some typos in the contribution guidelines. -- [twelsby](https://github.com/twelsby) fixed the array subscript operator, an issue that failed the MSVC build, and floating-point parsing/dumping. He further added support for unsigned integer numbers and implemented better roundtrip support for parsed numbers. -- [Volker Diels-Grabsch](https://github.com/vog) fixed a link in the README file. -- [msm-](https://github.com/msm-) added support for American Fuzzy Lop. -- [Annihil](https://github.com/Annihil) fixed an example in the README file. -- [Themercee](https://github.com/Themercee) noted a wrong URL in the README file. -- [Lv Zheng](https://github.com/lv-zheng) fixed a namespace issue with `int64_t` and `uint64_t`. -- [abc100m](https://github.com/abc100m) analyzed the issues with GCC 4.8 and proposed a [partial solution](https://github.com/nlohmann/json/pull/212). -- [zewt](https://github.com/zewt) added useful notes to the README file about Android. -- [Róbert Márki](https://github.com/robertmrk) added a fix to use move iterators and improved the integration via CMake. -- [Chris Kitching](https://github.com/ChrisKitching) cleaned up the CMake files. -- [Tom Needham](https://github.com/06needhamt) fixed a subtle bug with MSVC 2015 which was also proposed by [Michael K.](https://github.com/Epidal). -- [Mário Feroldi](https://github.com/thelostt) fixed a small typo. -- [duncanwerner](https://github.com/duncanwerner) found a really embarrassing performance regression in the 2.0.0 release. -- [Damien](https://github.com/dtoma) fixed one of the last conversion warnings. -- [Thomas Braun](https://github.com/t-b) fixed a warning in a test case and adjusted MSVC calls in the CI. -- [Théo DELRIEU](https://github.com/theodelrieu) patiently and constructively oversaw the long way toward [iterator-range parsing](https://github.com/nlohmann/json/issues/290). He also implemented the magic behind the serialization/deserialization of user-defined types and split the single header file into smaller chunks. -- [Stefan](https://github.com/5tefan) fixed a minor issue in the documentation. -- [Vasil Dimov](https://github.com/vasild) fixed the documentation regarding conversions from `std::multiset`. -- [ChristophJud](https://github.com/ChristophJud) overworked the CMake files to ease project inclusion. -- [Vladimir Petrigo](https://github.com/vpetrigo) made a SFINAE hack more readable and added Visual Studio 17 to the build matrix. -- [Denis Andrejew](https://github.com/seeekr) fixed a grammar issue in the README file. -- [Pierre-Antoine Lacaze](https://github.com/palacaze) found a subtle bug in the `dump()` function. -- [TurpentineDistillery](https://github.com/TurpentineDistillery) pointed to [`std::locale::classic()`](https://en.cppreference.com/w/cpp/locale/locale/classic) to avoid too much locale joggling, found some nice performance improvements in the parser, improved the benchmarking code, and realized locale-independent number parsing and printing. -- [cgzones](https://github.com/cgzones) had an idea how to fix the Coverity scan. -- [Jared Grubb](https://github.com/jaredgrubb) silenced a nasty documentation warning. -- [Yixin Zhang](https://github.com/qwename) fixed an integer overflow check. -- [Bosswestfalen](https://github.com/Bosswestfalen) merged two iterator classes into a smaller one. -- [Daniel599](https://github.com/Daniel599) helped to get Travis execute the tests with Clang's sanitizers. -- [Jonathan Lee](https://github.com/vjon) fixed an example in the README file. -- [gnzlbg](https://github.com/gnzlbg) supported the implementation of user-defined types. -- [Alexej Harm](https://github.com/qis) helped to get the user-defined types working with Visual Studio. -- [Jared Grubb](https://github.com/jaredgrubb) supported the implementation of user-defined types. -- [EnricoBilla](https://github.com/EnricoBilla) noted a typo in an example. -- [Martin Hořeňovský](https://github.com/horenmar) found a way for a 2x speedup for the compilation time of the test suite. -- [ukhegg](https://github.com/ukhegg) found proposed an improvement for the examples section. -- [rswanson-ihi](https://github.com/rswanson-ihi) noted a typo in the README. -- [Mihai Stan](https://github.com/stanmihai4) fixed a bug in the comparison with `nullptr`s. -- [Tushar Maheshwari](https://github.com/tusharpm) added [cotire](https://github.com/sakra/cotire) support to speed up the compilation. -- [TedLyngmo](https://github.com/TedLyngmo) noted a typo in the README, removed unnecessary bit arithmetic, and fixed some `-Weffc++` warnings. -- [Krzysztof Woś](https://github.com/krzysztofwos) made exceptions more visible. -- [ftillier](https://github.com/ftillier) fixed a compiler warning. -- [tinloaf](https://github.com/tinloaf) made sure all pushed warnings are properly popped. -- [Fytch](https://github.com/Fytch) found a bug in the documentation. -- [Jay Sistar](https://github.com/Type1J) implemented a Meson build description. -- [Henry Lee](https://github.com/HenryRLee) fixed a warning in ICC and improved the iterator implementation. -- [Vincent Thiery](https://github.com/vthiery) maintains a package for the Conan package manager. -- [Steffen](https://github.com/koemeet) fixed a potential issue with MSVC and `std::min`. -- [Mike Tzou](https://github.com/Chocobo1) fixed some typos. -- [amrcode](https://github.com/amrcode) noted a misleading documentation about comparison of floats. -- [Oleg Endo](https://github.com/olegendo) reduced the memory consumption by replacing `` with ``. -- [dan-42](https://github.com/dan-42) cleaned up the CMake files to simplify including/reusing of the library. -- [Nikita Ofitserov](https://github.com/himikof) allowed for moving values from initializer lists. -- [Greg Hurrell](https://github.com/wincent) fixed a typo. -- [Dmitry Kukovinets](https://github.com/DmitryKuk) fixed a typo. -- [kbthomp1](https://github.com/kbthomp1) fixed an issue related to the Intel OSX compiler. -- [Markus Werle](https://github.com/daixtrose) fixed a typo. -- [WebProdPP](https://github.com/WebProdPP) fixed a subtle error in a precondition check. -- [Alex](https://github.com/leha-bot) noted an error in a code sample. -- [Tom de Geus](https://github.com/tdegeus) reported some warnings with ICC and helped to fix them. -- [Perry Kundert](https://github.com/pjkundert) simplified reading from input streams. -- [Sonu Lohani](https://github.com/sonulohani) fixed a small compilation error. -- [Jamie Seward](https://github.com/jseward) fixed all MSVC warnings. -- [Nate Vargas](https://github.com/eld00d) added a Doxygen tag file. -- [pvleuven](https://github.com/pvleuven) helped to fix a warning in ICC. -- [Pavel](https://github.com/crea7or) helped to fix some warnings in MSVC. -- [Jamie Seward](https://github.com/jseward) avoided unnecessary string copies in `find()` and `count()`. -- [Mitja](https://github.com/Itja) fixed some typos. -- [Jorrit Wronski](https://github.com/jowr) updated the Hunter package links. -- [Matthias Möller](https://github.com/TinyTinni) added a `.natvis` for the MSVC debug view. -- [bogemic](https://github.com/bogemic) fixed some C++17 deprecation warnings. -- [Eren Okka](https://github.com/erengy) fixed some MSVC warnings. -- [abolz](https://github.com/abolz) integrated the Grisu2 algorithm for proper floating-point formatting, allowing more roundtrip checks to succeed. -- [Vadim Evard](https://github.com/Pipeliner) fixed a Markdown issue in the README. -- [zerodefect](https://github.com/zerodefect) fixed a compiler warning. -- [Kert](https://github.com/kaidokert) allowed to template the string type in the serialization and added the possibility to override the exceptional behavior. -- [mark-99](https://github.com/mark-99) helped fixing an ICC error. -- [Patrik Huber](https://github.com/patrikhuber) fixed links in the README file. -- [johnfb](https://github.com/johnfb) found a bug in the implementation of CBOR's indefinite length strings. -- [Paul Fultz II](https://github.com/pfultz2) added a note on the cget package manager. -- [Wilson Lin](https://github.com/wla80) made the integration section of the README more concise. -- [RalfBielig](https://github.com/ralfbielig) detected and fixed a memory leak in the parser callback. -- [agrianius](https://github.com/agrianius) allowed to dump JSON to an alternative string type. -- [Kevin Tonon](https://github.com/ktonon) overworked the C++11 compiler checks in CMake. -- [Axel Huebl](https://github.com/ax3l) simplified a CMake check and added support for the [Spack package manager](https://spack.io). -- [Carlos O'Ryan](https://github.com/coryan) fixed a typo. -- [James Upjohn](https://github.com/jammehcow) fixed a version number in the compilers section. -- [Chuck Atkins](https://github.com/chuckatkins) adjusted the CMake files to the CMake packaging guidelines and provided documentation for the CMake integration. -- [Jan Schöppach](https://github.com/dns13) fixed a typo. -- [martin-mfg](https://github.com/martin-mfg) fixed a typo. -- [Matthias Möller](https://github.com/TinyTinni) removed the dependency from `std::stringstream`. -- [agrianius](https://github.com/agrianius) added code to use alternative string implementations. -- [Daniel599](https://github.com/Daniel599) allowed to use more algorithms with the `items()` function. -- [Julius Rakow](https://github.com/jrakow) fixed the Meson include directory and fixed the links to [cppreference.com](cppreference.com). -- [Sonu Lohani](https://github.com/sonulohani) fixed the compilation with MSVC 2015 in debug mode. -- [grembo](https://github.com/grembo) fixed the test suite and re-enabled several test cases. -- [Hyeon Kim](https://github.com/simnalamburt) introduced the macro `JSON_INTERNAL_CATCH` to control the exception handling inside the library. -- [thyu](https://github.com/thyu) fixed a compiler warning. -- [David Guthrie](https://github.com/LEgregius) fixed a subtle compilation error with Clang 3.4.2. -- [Dennis Fischer](https://github.com/dennisfischer) allowed to call `find_package` without installing the library. -- [Hyeon Kim](https://github.com/simnalamburt) fixed an issue with a double macro definition. -- [Ben Berman](https://github.com/rivertam) made some error messages more understandable. -- [zakalibit](https://github.com/zakalibit) fixed a compilation problem with the Intel C++ compiler. -- [mandreyel](https://github.com/mandreyel) fixed a compilation problem. -- [Kostiantyn Ponomarenko](https://github.com/koponomarenko) added version and license information to the Meson build file. -- [Henry Schreiner](https://github.com/henryiii) added support for GCC 4.8. -- [knilch](https://github.com/knilch0r) made sure the test suite does not stall when run in the wrong directory. -- [Antonio Borondo](https://github.com/antonioborondo) fixed an MSVC 2017 warning. -- [Dan Gendreau](https://github.com/dgendreau) implemented the `NLOHMANN_JSON_SERIALIZE_ENUM` macro to quickly define an enum/JSON mapping. -- [efp](https://github.com/efp) added line and column information to parse errors. -- [julian-becker](https://github.com/julian-becker) added BSON support. -- [Pratik Chowdhury](https://github.com/pratikpc) added support for structured bindings. -- [David Avedissian](https://github.com/davedissian) added support for Clang 5.0.1 (PS4 version). -- [Jonathan Dumaresq](https://github.com/dumarjo) implemented an input adapter to read from `FILE*`. -- [kjpus](https://github.com/kjpus) fixed a link in the documentation. -- [Manvendra Singh](https://github.com/manu-chroma) fixed a typo in the documentation. -- [ziggurat29](https://github.com/ziggurat29) fixed an MSVC warning. -- [Sylvain Corlay](https://github.com/SylvainCorlay) added code to avoid an issue with MSVC. -- [mefyl](https://github.com/mefyl) fixed a bug when JSON was parsed from an input stream. -- [Millian Poquet](https://github.com/mpoquet) allowed to install the library via Meson. -- [Michael Behrns-Miller](https://github.com/moodboom) found an issue with a missing namespace. -- [Nasztanovics Ferenc](https://github.com/naszta) fixed a compilation issue with libc 2.12. -- [Andreas Schwab](https://github.com/andreas-schwab) fixed the endian conversion. -- [Mark-Dunning](https://github.com/Mark-Dunning) fixed a warning in MSVC. -- [Gareth Sylvester-Bradley](https://github.com/garethsb-sony) added `operator/` for JSON Pointers. -- [John-Mark](https://github.com/johnmarkwayve) noted a missing header. -- [Vitaly Zaitsev](https://github.com/xvitaly) fixed compilation with GCC 9.0. -- [Laurent Stacul](https://github.com/stac47) fixed compilation with GCC 9.0. -- [Ivor Wanders](https://github.com/iwanders) helped to reduce the CMake requirement to version 3.1. -- [njlr](https://github.com/njlr) updated the Buckaroo instructions. -- [Lion](https://github.com/lieff) fixed a compilation issue with GCC 7 on CentOS. -- [Isaac Nickaein](https://github.com/nickaein) improved the integer serialization performance and implemented the `contains()` function. -- [past-due](https://github.com/past-due) suppressed an unfixable warning. -- [Elvis Oric](https://github.com/elvisoric) improved Meson support. -- [Matěj Plch](https://github.com/Afforix) fixed an example in the README. -- [Mark Beckwith](https://github.com/wythe) fixed a typo. -- [scinart](https://github.com/scinart) fixed bug in the serializer. -- [Patrick Boettcher](https://github.com/pboettch) implemented `push_back()` and `pop_back()` for JSON Pointers. -- [Bruno Oliveira](https://github.com/nicoddemus) added support for Conda. -- [Michele Caini](https://github.com/skypjack) fixed links in the README. -- [Hani](https://github.com/hnkb) documented how to install the library with NuGet. -- [Mark Beckwith](https://github.com/wythe) fixed a typo. -- [yann-morin-1998](https://github.com/yann-morin-1998) helped to reduce the CMake requirement to version 3.1. -- [Konstantin Podsvirov](https://github.com/podsvirov) maintains a package for the MSYS2 software distro. -- [remyabel](https://github.com/remyabel) added GNUInstallDirs to the CMake files. -- [Taylor Howard](https://github.com/taylorhoward92) fixed a unit test. -- [Gabe Ron](https://github.com/Macr0Nerd) implemented the `to_string` method. -- [Watal M. Iwasaki](https://github.com/heavywatal) fixed a Clang warning. -- [Viktor Kirilov](https://github.com/onqtam) switched the unit tests from [Catch](https://github.com/philsquared/Catch) to [doctest](https://github.com/onqtam/doctest) -- [Juncheng E](https://github.com/ejcjason) fixed a typo. -- [tete17](https://github.com/tete17) fixed a bug in the `contains` function. -- [Xav83](https://github.com/Xav83) fixed some cppcheck warnings. -- [0xflotus](https://github.com/0xflotus) fixed some typos. -- [Christian Deneke](https://github.com/chris0x44) added a const version of `json_pointer::back`. -- [Julien Hamaide](https://github.com/crazyjul) made the `items()` function work with custom string types. -- [Evan Nemerson](https://github.com/nemequ) updated fixed a bug in Hedley and updated this library accordingly. -- [Florian Pigorsch](https://github.com/flopp) fixed a lot of typos. -- [Camille Bégué](https://github.com/cbegue) fixed an issue in the conversion from `std::pair` and `std::tuple` to `json`. -- [Anthony VH](https://github.com/AnthonyVH) fixed a compile error in an enum deserialization. -- [Yuriy Vountesmery](https://github.com/ua-code-dragon) noted a subtle bug in a preprocessor check. -- [Chen](https://github.com/dota17) fixed numerous issues in the library. -- [Antony Kellermann](https://github.com/aokellermann) added a CI step for GCC 10.1. -- [Alex](https://github.com/gistrec) fixed an MSVC warning. -- [Rainer](https://github.com/rvjr) proposed an improvement in the floating-point serialization in CBOR. -- [Francois Chabot](https://github.com/FrancoisChabot) made performance improvements in the input adapters. -- [Arthur Sonzogni](https://github.com/ArthurSonzogni) documented how the library can be included via `FetchContent`. -- [Rimas Misevičius](https://github.com/rmisev) fixed an error message. -- [Alexander Myasnikov](https://github.com/alexandermyasnikov) fixed some examples and a link in the README. -- [Hubert Chathi](https://github.com/uhoreg) made CMake's version config file architecture-independent. -- [OmnipotentEntity](https://github.com/OmnipotentEntity) implemented the binary values for CBOR, MessagePack, BSON, and UBJSON. -- [ArtemSarmini](https://github.com/ArtemSarmini) fixed a compilation issue with GCC 10 and fixed a leak. -- [Evgenii Sopov](https://github.com/sea-kg) integrated the library to the wsjcpp package manager. -- [Sergey Linev](https://github.com/linev) fixed a compiler warning. -- [Miguel Magalhães](https://github.com/magamig) fixed the year in the copyright. -- [Gareth Sylvester-Bradley](https://github.com/garethsb-sony) fixed a compilation issue with MSVC. -- [Alexander “weej” Jones](https://github.com/alex-weej) fixed an example in the README. -- [Antoine Cœur](https://github.com/Coeur) fixed some typos in the documentation. -- [jothepro](https://github.com/jothepro) updated links to the Hunter package. -- [Dave Lee](https://github.com/kastiglione) fixed link in the README. -- [Joël Lamotte](https://github.com/Klaim) added instruction for using Build2's package manager. -- [Paul Jurczak](https://github.com/pauljurczak) fixed an example in the README. -- [Sonu Lohani](https://github.com/sonulohani) fixed a warning. -- [Carlos Gomes Martinho](https://github.com/gocarlos) updated the Conan package source. -- [Konstantin Podsvirov](https://github.com/podsvirov) fixed the MSYS2 package documentation. -- [Tridacnid](https://github.com/Tridacnid) improved the CMake tests. -- [Michael](https://github.com/MBalszun) fixed MSVC warnings. -- [Quentin Barbarat](https://github.com/quentin-dev) fixed an example in the documentation. -- [XyFreak](https://github.com/XyFreak) fixed a compiler warning. -- [TotalCaesar659](https://github.com/TotalCaesar659) fixed links in the README. -- [Tanuj Garg](https://github.com/tanuj208) improved the fuzzer coverage for UBSAN input. -- [AODQ](https://github.com/AODQ) fixed a compiler warning. -- [jwittbrodt](https://github.com/jwittbrodt) made `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE` inline. -- [pfeatherstone](https://github.com/pfeatherstone) improved the upper bound of arguments of the `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE`/`NLOHMANN_DEFINE_TYPE_INTRUSIVE` macros. -- [Jan Procházka](https://github.com/jprochazk) fixed a bug in the CBOR parser for binary and string values. -- [T0b1-iOS](https://github.com/T0b1-iOS) fixed a bug in the new hash implementation. -- [Matthew Bauer](https://github.com/matthewbauer) adjusted the CBOR writer to create tags for binary subtypes. -- [gatopeich](https://github.com/gatopeich) implemented an ordered map container for `nlohmann::ordered_json`. -- [Érico Nogueira Rolim](https://github.com/ericonr) added support for pkg-config. -- [KonanM](https://github.com/KonanM) proposed an implementation for the `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE`/`NLOHMANN_DEFINE_TYPE_INTRUSIVE` macros. -- [Guillaume Racicot](https://github.com/gracicot) implemented `string_view` support and allowed C++20 support. -- [Alex Reinking](https://github.com/alexreinking) improved CMake support for `FetchContent`. -- [Hannes Domani](https://github.com/ssbssa) provided a GDB pretty printer. -- Lars Wirzenius reviewed the README file. -- [Jun Jie](https://github.com/ongjunjie) fixed a compiler path in the CMake scripts. -- [Ronak Buch](https://github.com/rbuch) fixed typos in the documentation. -- [Alexander Karzhenkov](https://github.com/karzhenkov) fixed a move constructor and the Travis builds. -- [Leonardo Lima](https://github.com/leozz37) added CPM.Cmake support. -- [Joseph Blackman](https://github.com/jbzdarkid) fixed a warning. -- [Yaroslav](https://github.com/YarikTH) updated doctest and implemented unit tests. -- [Martin Stump](https://github.com/globberwops) fixed a bug in the CMake files. -- [Jaakko Moisio](https://github.com/jasujm) fixed a bug in the input adapters. -- [bl-ue](https://github.com/bl-ue) fixed some Markdown issues in the README file. -- [William A. Wieselquist](https://github.com/wawiesel) fixed an example from the README. -- [abbaswasim](https://github.com/abbaswasim) fixed an example from the README. -- [Remy Jette](https://github.com/remyjette) fixed a warning. -- [Fraser](https://github.com/frasermarlow) fixed the documentation. -- [Ben Beasley](https://github.com/musicinmybrain) updated doctest. -- [Doron Behar](https://github.com/doronbehar) fixed pkg-config.pc. -- [raduteo](https://github.com/raduteo) fixed a warning. -- [David Pfahler](https://github.com/theShmoo) added the possibility to compile the library without I/O support. -- [Morten Fyhn Amundsen](https://github.com/mortenfyhn) fixed a typo. -- [jpl-mac](https://github.com/jpl-mac) allowed to treat the library as a system header in CMake. -- [Jason Dsouza](https://github.com/jasmcaus) fixed the indentation of the CMake file. -- [offa](https://github.com/offa) added a link to Conan Center to the documentation. -- [TotalCaesar659](https://github.com/TotalCaesar659) updated the links in the documentation to use HTTPS. -- [Rafail Giavrimis](https://github.com/grafail) fixed the Google Benchmark default branch. -- [Louis Dionne](https://github.com/ldionne) fixed a conversion operator. -- [justanotheranonymoususer](https://github.com/justanotheranonymoususer) made the examples in the README more consistent. -- [Finkman](https://github.com/Finkman) suppressed some `-Wfloat-equal` warnings. -- [Ferry Huberts](https://github.com/fhuberts) fixed `-Wswitch-enum` warnings. -- [Arseniy Terekhin](https://github.com/senyai) made the GDB pretty-printer robust against unset variable names. -- [Amir Masoud Abdol](https://github.com/amirmasoudabdol) updated the Homebrew command as nlohmann/json is now in homebrew-core. -- [Hallot](https://github.com/Hallot) fixed some `-Wextra-semi-stmt warnings`. -- [Giovanni Cerretani](https://github.com/gcerretani) fixed `-Wunused` warnings on `JSON_DIAGNOSTICS`. -- [Bogdan Popescu](https://github.com/Kapeli) hosts the [docset](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for offline documentation viewers. -- [Carl Smedstad](https://github.com/carlsmedstad) fixed an assertion error when using `JSON_DIAGNOSTICS`. -- [miikka75](https://github.com/miikka75) provided an important fix to compile C++17 code with Clang 9. -- [Maarten Becker](https://github.com/kernie) fixed a warning for shadowed variables. -- [Cristi Vîjdea](https://github.com/axnsan12) fixed typos in the `operator[]` documentation. -- [Alex Beregszaszi](https://github.com/axic) fixed spelling mistakes in comments. -- [Dirk Stolle](https://github.com/striezel) fixed typos in documentation. -- [Daniel Albuschat](https://github.com/daniel-kun) corrected the parameter name in the `parse` documentation. -- [Prince Mendiratta](https://github.com/Prince-Mendiratta) fixed a link to the FAQ. -- [Florian Albrechtskirchinger](https://github.com/falbrechtskirchinger) implemented `std::string_view` support for object keys and made dozens of other improvements. -- [Qianqian Fang](https://github.com/fangq) implemented the Binary JData (BJData) format. -- [pketelsen](https://github.com/pketelsen) added macros `NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT` and `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT`. -- [DarkZeros](https://github.com/DarkZeros) adjusted to code to not clash with Arduino defines. -- [flagarde](https://github.com/flagarde) fixed the output of `meta()` for MSVC. -- [Giovanni Cerretani](https://github.com/gcerretani) fixed a check for `std::filesystem`. -- [Dimitris Apostolou](https://github.com/rex4539) fixed a typo. -- [Ferry Huberts](https://github.com/fhuberts) fixed a typo. -- [Michael Nosthoff](https://github.com/heinemml) fixed a typo. -- [JungHoon Lee](https://github.com/jhnlee) fixed a typo. -- [Faruk D.](https://github.com/fdiblen) fixed the CITATION.CFF file. -- [Andrea Cocito](https://github.com/puffetto) added a clarification on macro usage to the documentation. -- [Krzysiek Karbowiak](https://github.com/kkarbowiak) refactored the tests to use `CHECK_THROWS_WITH_AS`. -- [Chaoqi Zhang](https://github.com/prncoprs) fixed a typo. -- [ivanovmp](https://github.com/ivanovmp) fixed a whitespace error. +1. [Teemperor](https://github.com/Teemperor) implemented CMake support and lcov integration, realized escape and Unicode handling in the string parser, and fixed the JSON serialization. +2. [elliotgoodrich](https://github.com/elliotgoodrich) fixed an issue with double deletion in the iterator classes. +3. [kirkshoop](https://github.com/kirkshoop) made the iterators of the class composable to other libraries. +4. [wancw](https://github.com/wanwc) fixed a bug that hindered the class to compile with Clang. +5. Tomas Åblad found a bug in the iterator implementation. +6. [Joshua C. Randall](https://github.com/jrandall) fixed a bug in the floating-point serialization. +7. [Aaron Burghardt](https://github.com/aburgh) implemented code to parse streams incrementally. Furthermore, he greatly improved the parser class by allowing the definition of a filter function to discard undesired elements while parsing. +8. [Daniel Kopeček](https://github.com/dkopecek) fixed a bug in the compilation with GCC 5.0. +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. +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) 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. +22. [whackashoe](https://github.com/whackashoe) replaced a function that was marked as unsafe by Visual Studio. +23. [406345](https://github.com/406345) fixed two small warnings. +24. [Glen Fernandes](https://github.com/glenfe) noted a potential portability problem in the `has_mapped_type` function. +25. [Corbin Hughes](https://github.com/nibroc) fixed some typos in the contribution guidelines. +26. [twelsby](https://github.com/twelsby) fixed the array subscript operator, an issue that failed the MSVC build, and floating-point parsing/dumping. He further added support for unsigned integer numbers and implemented better roundtrip support for parsed numbers. +27. [Volker Diels-Grabsch](https://github.com/vog) fixed a link in the README file. +28. [msm-](https://github.com/msm-) added support for American Fuzzy Lop. +29. [Annihil](https://github.com/Annihil) fixed an example in the README file. +30. [Themercee](https://github.com/Themercee) noted a wrong URL in the README file. +31. [Lv Zheng](https://github.com/lv-zheng) fixed a namespace issue with `int64_t` and `uint64_t`. +32. [abc100m](https://github.com/abc100m) analyzed the issues with GCC 4.8 and proposed a [partial solution](https://github.com/nlohmann/json/pull/212). +33. [zewt](https://github.com/zewt) added useful notes to the README file about Android. +34. [Róbert Márki](https://github.com/robertmrk) added a fix to use move iterators and improved the integration via CMake. +35. [Chris Kitching](https://github.com/ChrisKitching) cleaned up the CMake files. +36. [Tom Needham](https://github.com/06needhamt) fixed a subtle bug with MSVC 2015 which was also proposed by [Michael K.](https://github.com/Epidal). +37. [Mário Feroldi](https://github.com/thelostt) fixed a small typo. +38. [duncanwerner](https://github.com/duncanwerner) found a really embarrassing performance regression in the 2.0.0 release. +39. [Damien](https://github.com/dtoma) fixed one of the last conversion warnings. +40. [Thomas Braun](https://github.com/t-b) fixed a warning in a test case and adjusted MSVC calls in the CI. +41. [Théo DELRIEU](https://github.com/theodelrieu) patiently and constructively oversaw the long way toward [iterator-range parsing](https://github.com/nlohmann/json/issues/290). He also implemented the magic behind the serialization/deserialization of user-defined types and split the single header file into smaller chunks. +42. [Stefan](https://github.com/5tefan) fixed a minor issue in the documentation. +43. [Vasil Dimov](https://github.com/vasild) fixed the documentation regarding conversions from `std::multiset`. +44. [ChristophJud](https://github.com/ChristophJud) overworked the CMake files to ease project inclusion. +45. [Vladimir Petrigo](https://github.com/vpetrigo) made a SFINAE hack more readable and added Visual Studio 17 to the build matrix. +46. [Denis Andrejew](https://github.com/seeekr) fixed a grammar issue in the README file. +47. [Pierre-Antoine Lacaze](https://github.com/palacaze) found a subtle bug in the `dump()` function. +48. [TurpentineDistillery](https://github.com/TurpentineDistillery) pointed to [`std::locale::classic()`](https://en.cppreference.com/w/cpp/locale/locale/classic) to avoid too much locale joggling, found some nice performance improvements in the parser, improved the benchmarking code, and realized locale-independent number parsing and printing. +49. [cgzones](https://github.com/cgzones) had an idea how to fix the Coverity scan. +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 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. +57. [Jared Grubb](https://github.com/jaredgrubb) supported the implementation of user-defined types. +58. [EnricoBilla](https://github.com/EnricoBilla) noted a typo in an example. +59. [Martin Hořeňovský](https://github.com/horenmar) found a way for a 2x speedup for the compilation time of the test suite. +60. [ukhegg](https://github.com/ukhegg) found proposed an improvement for the examples section. +61. [rswanson-ihi](https://github.com/rswanson-ihi) noted a typo in the README. +62. [Mihai Stan](https://github.com/stanmihai4) fixed a bug in the comparison with `nullptr`s. +63. [Tushar Maheshwari](https://github.com/tusharpm) added [cotire](https://github.com/sakra/cotire) support to speed up the compilation. +64. [TedLyngmo](https://github.com/TedLyngmo) noted a typo in the README, removed unnecessary bit arithmetic, and fixed some `-Weffc++` warnings. +65. [Krzysztof Woś](https://github.com/krzysztofwos) made exceptions more visible. +66. [ftillier](https://github.com/ftillier) fixed a compiler warning. +67. [tinloaf](https://github.com/tinloaf) made sure all pushed warnings are properly popped. +68. [Fytch](https://github.com/Fytch) found a bug in the documentation. +69. [Jay Sistar](https://github.com/Type1J) implemented a Meson build description. +70. [Henry Lee](https://github.com/HenryRLee) fixed a warning in ICC and improved the iterator implementation. +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 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. +78. [Greg Hurrell](https://github.com/wincent) fixed a typo. +79. [Dmitry Kukovinets](https://github.com/DmitryKuk) fixed a typo. +80. [kbthomp1](https://github.com/kbthomp1) fixed an issue related to the Intel OSX compiler. +81. [Markus Werle](https://github.com/daixtrose) fixed a typo. +82. [WebProdPP](https://github.com/WebProdPP) fixed a subtle error in a precondition check. +83. [Alex](https://github.com/leha-bot) noted an error in a code sample. +84. [Tom de Geus](https://github.com/tdegeus) reported some warnings with ICC and helped to fix them. +85. [Perry Kundert](https://github.com/pjkundert) simplified reading from input streams. +86. [Sonu Lohani](https://github.com/sonulohani) fixed a small compilation error. +87. [Jamie Seward](https://github.com/jseward) fixed all MSVC warnings. +88. [Nate Vargas](https://github.com/eld00d) added a Doxygen tag file. +89. [pvleuven](https://github.com/pvleuven) helped to fix a warning in ICC. +90. [Pavel](https://github.com/crea7or) helped to fix some warnings in MSVC. +91. [Jamie Seward](https://github.com/jseward) avoided unnecessary string copies in `find()` and `count()`. +92. [Mitja](https://github.com/Itja) fixed some typos. +93. [Jorrit Wronski](https://github.com/jowr) updated the Hunter package links. +94. [Matthias Möller](https://github.com/TinyTinni) added a `.natvis` for the MSVC debug view. +95. [bogemic](https://github.com/bogemic) fixed some C++17 deprecation warnings. +96. [Eren Okka](https://github.com/erengy) fixed some MSVC warnings. +97. [abolz](https://github.com/abolz) integrated the Grisu2 algorithm for proper floating-point formatting, allowing more roundtrip checks to succeed. +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 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 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. +111. [James Upjohn](https://github.com/jammehcow) fixed a version number in the compilers section. +112. [Chuck Atkins](https://github.com/chuckatkins) adjusted the CMake files to the CMake packaging guidelines and provided documentation for the CMake integration. +113. [Jan Schöppach](https://github.com/dns13) fixed a typo. +114. [martin-mfg](https://github.com/martin-mfg) fixed a typo. +115. [Matthias Möller](https://github.com/TinyTinni) removed the dependency from `std::stringstream`. +116. [agrianius](https://github.com/agrianius) added code to use alternative string implementations. +117. [Daniel599](https://github.com/Daniel599) allowed to use more algorithms with the `items()` function. +118. [Julius Rakow](https://github.com/jrakow) fixed the Meson include directory and fixed the links to [cppreference.com](cppreference.com). +119. [Sonu Lohani](https://github.com/sonulohani) fixed the compilation with MSVC 2015 in debug mode. +120. [grembo](https://github.com/grembo) fixed the test suite and re-enabled several test cases. +121. [Hyeon Kim](https://github.com/simnalamburt) introduced the macro `JSON_INTERNAL_CATCH` to control the exception handling inside the library. +122. [thyu](https://github.com/thyu) fixed a compiler warning. +123. [David Guthrie](https://github.com/LEgregius) fixed a subtle compilation error with Clang 3.4.2. +124. [Dennis Fischer](https://github.com/dennisfischer) allowed to call `find_package` without installing the library. +125. [Hyeon Kim](https://github.com/simnalamburt) fixed an issue with a double macro definition. +126. [Ben Berman](https://github.com/rivertam) made some error messages more understandable. +127. [zakalibit](https://github.com/zakalibit) fixed a compilation problem with the Intel C++ compiler. +128. [mandreyel](https://github.com/mandreyel) fixed a compilation problem. +129. [Kostiantyn Ponomarenko](https://github.com/koponomarenko) added version and license information to the Meson build file. +130. [Henry Schreiner](https://github.com/henryiii) added support for GCC 4.8. +131. [knilch](https://github.com/knilch0r) made sure the test suite does not stall when run in the wrong directory. +132. [Antonio Borondo](https://github.com/antonioborondo) fixed an MSVC 2017 warning. +133. [Dan Gendreau](https://github.com/dgendreau) implemented the `NLOHMANN_JSON_SERIALIZE_ENUM` macro to quickly define an enum/JSON mapping. +134. [efp](https://github.com/efp) added line and column information to parse errors. +135. [julian-becker](https://github.com/julian-becker) added BSON support. +136. [Pratik Chowdhury](https://github.com/pratikpc) added support for structured bindings. +137. [David Avedissian](https://github.com/davedissian) added support for Clang 5.0.1 (PS4 version). +138. [Jonathan Dumaresq](https://github.com/dumarjo) implemented an input adapter to read from `FILE*`. +139. [kjpus](https://github.com/kjpus) fixed a link in the documentation. +140. [Manvendra Singh](https://github.com/manu-chroma) fixed a typo in the documentation. +141. [ziggurat29](https://github.com/ziggurat29) fixed an MSVC warning. +142. [Sylvain Corlay](https://github.com/SylvainCorlay) added code to avoid an issue with MSVC. +143. [mefyl](https://github.com/mefyl) fixed a bug when JSON was parsed from an input stream. +144. [Millian Poquet](https://github.com/mpoquet) allowed to install the library via Meson. +145. [Michael Behrns-Miller](https://github.com/moodboom) found an issue with a missing namespace. +146. [Nasztanovics Ferenc](https://github.com/naszta) fixed a compilation issue with libc 2.12. +147. [Andreas Schwab](https://github.com/andreas-schwab) fixed the endian conversion. +148. [Mark-Dunning](https://github.com/Mark-Dunning) fixed a warning in MSVC. +149. [Gareth Sylvester-Bradley](https://github.com/garethsb-sony) added `operator/` for JSON Pointers. +150. [John-Mark](https://github.com/johnmarkwayve) noted a missing header. +151. [Vitaly Zaitsev](https://github.com/xvitaly) fixed compilation with GCC 9.0. +152. [Laurent Stacul](https://github.com/stac47) fixed compilation with GCC 9.0. +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. +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 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. +165. [Hani](https://github.com/hnkb) documented how to install the library with NuGet. +166. [Mark Beckwith](https://github.com/wythe) fixed a typo. +167. [yann-morin-1998](https://github.com/yann-morin-1998) helped to reduce the CMake requirement to version 3.1. +168. [Konstantin Podsvirov](https://github.com/podsvirov) maintains a package for the MSYS2 software distro. +169. [remyabel](https://github.com/remyabel) added GNUInstallDirs to the CMake files. +170. [Taylor Howard](https://github.com/taylorhoward92) fixed a unit test. +171. [Gabe Ron](https://github.com/Macr0Nerd) implemented the `to_string` method. +172. [Watal M. Iwasaki](https://github.com/heavywatal) fixed a Clang warning. +173. [Viktor Kirilov](https://github.com/onqtam) switched the unit tests from [Catch](https://github.com/philsquared/Catch) to [doctest](https://github.com/onqtam/doctest) +174. [Juncheng E](https://github.com/ejcjason) fixed a typo. +175. [tete17](https://github.com/tete17) fixed a bug in the `contains` function. +176. [Xav83](https://github.com/Xav83) fixed some cppcheck warnings. +177. [0xflotus](https://github.com/0xflotus) fixed some typos. +178. [Christian Deneke](https://github.com/chris0x44) added a const version of `json_pointer::back`. +179. [Julien Hamaide](https://github.com/crazyjul) made the `items()` function work with custom string types. +180. [Evan Nemerson](https://github.com/nemequ) updated fixed a bug in Hedley and updated this library accordingly. +181. [Florian Pigorsch](https://github.com/flopp) fixed a lot of typos. +182. [Camille Bégué](https://github.com/cbegue) fixed an issue in the conversion from `std::pair` and `std::tuple` to `json`. +183. [Anthony VH](https://github.com/AnthonyVH) fixed a compile error in an enum deserialization. +184. [Yuriy Vountesmery](https://github.com/ua-code-dragon) noted a subtle bug in a preprocessor check. +185. [Chen](https://github.com/dota17) fixed numerous issues in the library. +186. [Antony Kellermann](https://github.com/aokellermann) added a CI step for GCC 10.1. +187. [Alex](https://github.com/gistrec) fixed an MSVC warning. +188. [Rainer](https://github.com/rvjr) proposed an improvement in the floating-point serialization in CBOR. +189. [Francois Chabot](https://github.com/FrancoisChabot) made performance improvements in the input adapters. +190. [Arthur Sonzogni](https://github.com/ArthurSonzogni) documented how the library can be included via `FetchContent`. +191. [Rimas Misevičius](https://github.com/rmisev) fixed an error message. +192. [Alexander Myasnikov](https://github.com/alexandermyasnikov) fixed some examples and a link in the README. +193. [Hubert Chathi](https://github.com/uhoreg) made CMake's version config file architecture-independent. +194. [OmnipotentEntity](https://github.com/OmnipotentEntity) implemented the binary values for CBOR, MessagePack, BSON, and UBJSON. +195. [ArtemSarmini](https://github.com/ArtemSarmini) fixed a compilation issue with GCC 10 and fixed a leak. +196. [Evgenii Sopov](https://github.com/sea-kg) integrated the library to the wsjcpp package manager. +197. [Sergey Linev](https://github.com/linev) fixed a compiler warning. +198. [Miguel Magalhães](https://github.com/magamig) fixed the year in the copyright. +199. [Gareth Sylvester-Bradley](https://github.com/garethsb-sony) fixed a compilation issue with MSVC. +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 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. +207. [Carlos Gomes Martinho](https://github.com/gocarlos) updated the Conan package source. +208. [Konstantin Podsvirov](https://github.com/podsvirov) fixed the MSYS2 package documentation. +209. [Tridacnid](https://github.com/Tridacnid) improved the CMake tests. +210. [Michael](https://github.com/MBalszun) fixed MSVC warnings. +211. [Quentin Barbarat](https://github.com/quentin-dev) fixed an example in the documentation. +212. [XyFreak](https://github.com/XyFreak) fixed a compiler warning. +213. [TotalCaesar659](https://github.com/TotalCaesar659) fixed links in the README. +214. [Tanuj Garg](https://github.com/tanuj208) improved the fuzzer coverage for UBSAN input. +215. [AODQ](https://github.com/AODQ) fixed a compiler warning. +216. [jwittbrodt](https://github.com/jwittbrodt) made `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE` inline. +217. [pfeatherstone](https://github.com/pfeatherstone) improved the upper bound of arguments of the `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE`/`NLOHMANN_DEFINE_TYPE_INTRUSIVE` macros. +218. [Jan Procházka](https://github.com/jprochazk) fixed a bug in the CBOR parser for binary and string values. +219. [T0b1-iOS](https://github.com/T0b1-iOS) fixed a bug in the new hash implementation. +220. [Matthew Bauer](https://github.com/matthewbauer) adjusted the CBOR writer to create tags for binary subtypes. +221. [gatopeich](https://github.com/gatopeich) implemented an ordered map container for `nlohmann::ordered_json`. +222. [Érico Nogueira Rolim](https://github.com/ericonr) added support for pkg-config. +223. [KonanM](https://github.com/KonanM) proposed an implementation for the `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE`/`NLOHMANN_DEFINE_TYPE_INTRUSIVE` macros. +224. [Guillaume Racicot](https://github.com/gracicot) implemented `string_view` support and allowed C++20 support. +225. [Alex Reinking](https://github.com/alexreinking) improved CMake support for `FetchContent`. +226. [Hannes Domani](https://github.com/ssbssa) provided a GDB pretty printer. +227. Lars Wirzenius reviewed the README file. +228. [Jun Jie](https://github.com/ongjunjie) fixed a compiler path in the CMake scripts. +229. [Ronak Buch](https://github.com/rbuch) fixed typos in the documentation. +230. [Alexander Karzhenkov](https://github.com/karzhenkov) fixed a move constructor and the Travis builds. +231. [Leonardo Lima](https://github.com/leozz37) added CPM.Cmake support. +232. [Joseph Blackman](https://github.com/jbzdarkid) fixed a warning. +233. [Yaroslav](https://github.com/YarikTH) updated doctest and implemented unit tests. +234. [Martin Stump](https://github.com/globberwops) fixed a bug in the CMake files. +235. [Jaakko Moisio](https://github.com/jasujm) fixed a bug in the input adapters. +236. [bl-ue](https://github.com/bl-ue) fixed some Markdown issues in the README file. +237. [William A. Wieselquist](https://github.com/wawiesel) fixed an example from the README. +238. [abbaswasim](https://github.com/abbaswasim) fixed an example from the README. +239. [Remy Jette](https://github.com/remyjette) fixed a warning. +240. [Fraser](https://github.com/frasermarlow) fixed the documentation. +241. [Ben Beasley](https://github.com/musicinmybrain) updated doctest. +242. [Doron Behar](https://github.com/doronbehar) fixed pkg-config.pc. +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 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. +250. [Rafail Giavrimis](https://github.com/grafail) fixed the Google Benchmark default branch. +251. [Louis Dionne](https://github.com/ldionne) fixed a conversion operator. +252. [justanotheranonymoususer](https://github.com/justanotheranonymoususer) made the examples in the README more consistent. +253. [Finkman](https://github.com/Finkman) suppressed some `-Wfloat-equal` warnings. +254. [Ferry Huberts](https://github.com/fhuberts) fixed `-Wswitch-enum` warnings. +255. [Arseniy Terekhin](https://github.com/senyai) made the GDB pretty-printer robust against unset variable names. +256. [Amir Masoud Abdol](https://github.com/amirmasoudabdol) updated the Homebrew command as nlohmann/json is now in homebrew-core. +257. [Hallot](https://github.com/Hallot) fixed some `-Wextra-semi-stmt warnings`. +258. [Giovanni Cerretani](https://github.com/gcerretani) fixed `-Wunused` warnings on `JSON_DIAGNOSTICS`. +259. [Bogdan Popescu](https://github.com/Kapeli) hosts the [docset](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B) for offline documentation viewers. +260. [Carl Smedstad](https://github.com/carlsmedstad) fixed an assertion error when using `JSON_DIAGNOSTICS`. +261. [miikka75](https://github.com/miikka75) provided an important fix to compile C++17 code with Clang 9. +262. [Maarten Becker](https://github.com/kernie) fixed a warning for shadowed variables. +263. [Cristi Vîjdea](https://github.com/axnsan12) fixed typos in the `operator[]` documentation. +264. [Alex Beregszaszi](https://github.com/axic) fixed spelling mistakes in comments. +265. [Dirk Stolle](https://github.com/striezel) fixed typos in documentation. +266. [Daniel Albuschat](https://github.com/daniel-kun) corrected the parameter name in the `parse` documentation. +267. [Prince Mendiratta](https://github.com/Prince-Mendiratta) fixed a link to the FAQ. +268. [Florian Albrechtskirchinger](https://github.com/falbrechtskirchinger) implemented `std::string_view` support for object keys and made dozens of other improvements. +269. [Qianqian Fang](https://github.com/fangq) implemented the Binary JData (BJData) format. +270. [pketelsen](https://github.com/pketelsen) added macros `NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT` and `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT`. +271. [DarkZeros](https://github.com/DarkZeros) adjusted to code to not clash with Arduino defines. +272. [flagarde](https://github.com/flagarde) fixed the output of `meta()` for MSVC. +273. [Giovanni Cerretani](https://github.com/gcerretani) fixed a check for `std::filesystem`. +274. [Dimitris Apostolou](https://github.com/rex4539) fixed a typo. +275. [Ferry Huberts](https://github.com/fhuberts) fixed a typo. +276. [Michael Nosthoff](https://github.com/heinemml) fixed a typo. +277. [JungHoon Lee](https://github.com/jhnlee) fixed a typo. +278. [Faruk D.](https://github.com/fdiblen) fixed the CITATION.CFF file. +279. [Andrea Cocito](https://github.com/puffetto) added a clarification on macro usage to the documentation. +280. [Krzysiek Karbowiak](https://github.com/kkarbowiak) refactored the tests to use `CHECK_THROWS_WITH_AS`. +281. [Chaoqi Zhang](https://github.com/prncoprs) fixed a typo. +282. [ivanovmp](https://github.com/ivanovmp) fixed a whitespace error. +283. [KsaNL](https://github.com/KsaNL) fixed a build error when including ``. +284. [Andrea Pappacoda](https://github.com/Tachi107) moved `.pc` and `.cmake` files to `share` directory. +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 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. +292. [Alexander “weej” Jones](https://github.com/alexweej) fixed an example in the README. +293. [Eli Schwartz](https://github.com/eli-schwartz) added more files to the `include.zip` archive. +294. [Kevin Lu](https://github.com/kevinlul) fixed a compilation issue when typedefs with certain names were present. +295. [Trevor Hickey](https://github.com/luxe) improved the description of an example. +296. [Jef LeCompte](https://github.com/jef) updated the year in the README file. +297. [Alexandre Hamez](https://github.com/ahamez) fixed a warning. +298. [Maninderpal Badhan](https://github.com/mbadhan) fixed a typo. +299. [kevin--](https://github.com/kevin--) added a note to an example in the README file. +300. [I](https://github.com/wx257osn2) fixed a typo. +301. [Gregorio Litenstein](https://github.com/Lord-Kamina) fixed the Clang detection. +302. [Andreas Smas](https://github.com/andoma) added a Doozer badge. +303. [WanCW](https://github.com/wancw) fixed the string conversion with Clang. +304. [zhaohuaxishi](https://github.com/zhaohuaxishi) fixed a Doxygen error. +305. [emvivre](https://github.com/emvivre) removed an invalid parameter from CMake. +306. [Tobias Hermann](https://github.com/Dobiasd) fixed a link in the README file. +307. [Michael](https://github.com/traits) fixed a warning. +308. [Ryan Mulder](https://github.com/ryanjmulder) added `ensure_ascii` to the `dump` function. +309. [Muri Nicanor](https://github.com/murinicanor) fixed the `sed` discovery in the Makefile. +310. [David Avedissian](https://github.com/dgavedissian) implemented SFINAE-friendly `iterator_traits`. +311. [AQNOUCH Mohammed](https://github.com/aqnouch) fixed a typo in the README. +312. [Gareth Sylvester-Bradley](https://github.com/garethsb) added `operator/=` and `operator/` to construct JSON pointers. +313. [Michael Macnair](https://github.com/mykter) added support for afl-fuzz testing. +314. [Berkus Decker](https://github.com/berkus) fixed a typo in the README. +315. [Illia Polishchuk](https://github.com/effolkronium) improved the CMake testing. +316. [Ikko Ashimine](https://github.com/eltociear) fixed a typo. Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone. diff --git a/cmake/ci.cmake b/cmake/ci.cmake index 22cf090935..09c1c57d49 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake @@ -589,15 +589,22 @@ file(GLOB_RECURSE INDENT_FILES ${PROJECT_SOURCE_DIR}/docs/examples/*.cpp ) +set(include_dir ${PROJECT_SOURCE_DIR}/single_include/nlohmann) +set(tool_dir ${PROJECT_SOURCE_DIR}/tools/amalgamate) add_custom_target(ci_test_amalgamation - COMMAND rm -fr ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp~ - COMMAND cp ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp~ - COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/amalgamate/amalgamate.py -c ${PROJECT_SOURCE_DIR}/tools/amalgamate/config.json -s . - COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} --suffix=none --quiet ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp - COMMAND diff ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp~ ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp + COMMAND rm -fr ${include_dir}/json.hpp~ ${include_dir}/json_fwd.hpp~ + COMMAND cp ${include_dir}/json.hpp ${include_dir}/json.hpp~ + COMMAND cp ${include_dir}/json_fwd.hpp ${include_dir}/json_fwd.hpp~ + + COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json.json -s . + COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_fwd.json -s . + COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} --suffix=none --quiet ${include_dir}/json.hpp ${include_dir}/json_fwd.hpp + + COMMAND diff ${include_dir}/json.hpp~ ${include_dir}/json.hpp + COMMAND diff ${include_dir}/json_fwd.hpp~ ${include_dir}/json_fwd.hpp COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} ${INDENT_FILES} - COMMAND cd ${PROJECT_SOURCE_DIR} && for FILE in `find . -name '*.orig'`\; do false \; done + COMMAND for FILE in `find . -name '*.orig'`\; do false \; done WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Check amalgamation and indentation" @@ -953,12 +960,18 @@ add_custom_target(ci_icpc # test documentation ############################################################################### -add_custom_target(ci_test_documentation +add_custom_target(ci_test_examples COMMAND make CXX="${GCC_TOOL}" check_output_portable -j8 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs COMMENT "Check that all examples compile and create the desired output" ) +add_custom_target(ci_test_api_documentation + COMMAND ${Python3_EXECUTABLE} scripts/check_structure.py + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs/mkdocs + COMMENT "Lint the API documentation" +) + ############################################################################### # Clean up all generated files. ############################################################################### diff --git a/docs/avatars.png b/docs/avatars.png index 69e7da318c..0a25221872 100644 Binary files a/docs/avatars.png and b/docs/avatars.png differ diff --git a/docs/docset/Makefile b/docs/docset/Makefile index 6cdca4a03c..eb1cfd38c0 100644 --- a/docs/docset/Makefile +++ b/docs/docset/Makefile @@ -1,3 +1,4 @@ +SHELL=/usr/bin/env bash SED ?= $(shell which gsed 2>/dev/null || which sed) MKDOCS_PAGES=$(shell cd ../mkdocs/docs/ && find * -type f -name '*.md' | sort) diff --git a/docs/docset/docSet.sql b/docs/docset/docSet.sql index e076ea5758..f97647d97e 100644 --- a/docs/docset/docSet.sql +++ b/docs/docset/docSet.sql @@ -128,6 +128,8 @@ INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer', 'Class', 'api/ INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::back', 'Method', 'api/json_pointer/back/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::empty', 'Method', 'api/json_pointer/empty/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::json_pointer', 'Constructor', 'api/json_pointer/json_pointer/index.html'); +INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator==', 'Operator', 'api/json_pointer/operator_eq/index.html'); +INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator!=', 'Operator', 'api/json_pointer/operator_ne/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator/', 'Operator', 'api/json_pointer/operator_slash/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator/=', 'Operator', 'api/json_pointer/operator_slasheq/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator string_t', 'Operator', 'api/json_pointer/operator_string_t/index.html'); @@ -181,6 +183,7 @@ INSERT INTO searchIndex(name, type, path) VALUES ('Iterators', 'Guide', 'feature INSERT INTO searchIndex(name, type, path) VALUES ('JSON Merge Patch', 'Guide', 'features/merge_patch/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('JSON Patch and Diff', 'Guide', 'features/json_patch/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('JSON Pointer', 'Guide', 'features/json_pointer/index.html'); +INSERT INTO searchIndex(name, type, path) VALUES ('nlohmann Namespace', 'Guide', 'features/namespace/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('Types', 'Guide', 'features/types/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('Types: Number Handling', 'Guide', 'features/types/number_handling/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('Object Order', 'Guide', 'features/object_order/index.html'); @@ -223,6 +226,7 @@ INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_NON_INTR INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_NAMESPACE', 'Macro', 'api/macros/nlohmann_json_namespace/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_NAMESPACE_BEGIN', 'Macro', 'api/macros/nlohmann_json_namespace_begin/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_NAMESPACE_END', 'Macro', 'api/macros/nlohmann_json_namespace_begin/index.html'); +INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_NAMESPACE_NO_VERSION', 'Macro', 'api/macros/nlohmann_json_namespace_no_version/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_SERIALIZE_ENUM', 'Macro', 'api/macros/nlohmann_json_serialize_enum/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_VERSION_MAJOR', 'Macro', 'api/macros/nlohmann_json_version_major/index.html'); INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_VERSION_MINOR', 'Macro', 'api/macros/nlohmann_json_version_major/index.html'); diff --git a/docs/docset/docset.json b/docs/docset/docset.json index 8a08c03115..a11ceadfa8 100644 --- a/docs/docset/docset.json +++ b/docs/docset/docset.json @@ -1,6 +1,6 @@ { "name": "JSON for Modern C++", - "version": "3.11.1", + "version": "3.11.2", "archive": "JSON_for_Modern_C++.tgz", "author": { "name": "Niels Lohmann", diff --git a/docs/examples/basic_json__CompatibleType.output b/docs/examples/basic_json__CompatibleType.output index 10c4ed3fe8..2337e81fb0 100644 --- a/docs/examples/basic_json__CompatibleType.output +++ b/docs/examples/basic_json__CompatibleType.output @@ -2,7 +2,7 @@ {"one":1,"three":3,"two":2} {"one":1.2,"three":3.4,"two":2.3} {"one":true,"three":false,"two":true} -{"one":true,"three":true,"two":true} +{"one":true,"three":false,"two":true} ["one","two",3,4.5,false] [1,2,3,4] diff --git a/docs/examples/from_json__default_constructible.cpp b/docs/examples/from_json__default_constructible.cpp new file mode 100644 index 0000000000..17c0551c8c --- /dev/null +++ b/docs/examples/from_json__default_constructible.cpp @@ -0,0 +1,37 @@ +#include +#include + +using json = nlohmann::json; + +namespace ns +{ +// a simple struct to model a person +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 + +int main() +{ + json j; + j["name"] = "Ned Flanders"; + j["address"] = "744 Evergreen Terrace"; + j["age"] = 60; + + auto p = j.get(); + + std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl; +} diff --git a/docs/examples/from_json__default_constructible.output b/docs/examples/from_json__default_constructible.output new file mode 100644 index 0000000000..b92452326d --- /dev/null +++ b/docs/examples/from_json__default_constructible.output @@ -0,0 +1 @@ +Ned Flanders (60) lives in 744 Evergreen Terrace diff --git a/docs/examples/from_json__non_default_constructible.cpp b/docs/examples/from_json__non_default_constructible.cpp new file mode 100644 index 0000000000..6cb86153cc --- /dev/null +++ b/docs/examples/from_json__non_default_constructible.cpp @@ -0,0 +1,53 @@ +#include +#include + +using json = nlohmann::json; + +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; +}; +} // 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 + +int main() +{ + json j; + j["name"] = "Ned Flanders"; + j["address"] = "744 Evergreen Terrace"; + j["age"] = 60; + + auto p = j.get(); + + std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl; +} diff --git a/docs/examples/from_json__non_default_constructible.output b/docs/examples/from_json__non_default_constructible.output new file mode 100644 index 0000000000..b92452326d --- /dev/null +++ b/docs/examples/from_json__non_default_constructible.output @@ -0,0 +1 @@ +Ned Flanders (60) lives in 744 Evergreen Terrace diff --git a/docs/examples/json_pointer__operator__equal.cpp b/docs/examples/json_pointer__operator__equal.cpp new file mode 100644 index 0000000000..dce6df03c3 --- /dev/null +++ b/docs/examples/json_pointer__operator__equal.cpp @@ -0,0 +1,19 @@ +#include +#include + +using json = nlohmann::json; + +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; +} diff --git a/docs/examples/json_pointer__operator__equal.output b/docs/examples/json_pointer__operator__equal.output new file mode 100644 index 0000000000..9a76125808 --- /dev/null +++ b/docs/examples/json_pointer__operator__equal.output @@ -0,0 +1,4 @@ +"" == "": true +"" == "": true +"" == "/foo": false +"/foo" == "/foo": true diff --git a/docs/examples/json_pointer__operator__equal_stringtype.cpp b/docs/examples/json_pointer__operator__equal_stringtype.cpp new file mode 100644 index 0000000000..af8ec5a29c --- /dev/null +++ b/docs/examples/json_pointer__operator__equal_stringtype.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +using json = nlohmann::json; + +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"); + + // 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; + } +} diff --git a/docs/examples/json_pointer__operator__equal_stringtype.output b/docs/examples/json_pointer__operator__equal_stringtype.output new file mode 100644 index 0000000000..7fb299d3d8 --- /dev/null +++ b/docs/examples/json_pointer__operator__equal_stringtype.output @@ -0,0 +1,4 @@ +"" == "": true +"" == "": true +"/foo" == "/foo": true +"bar" == "/foo": [json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'bar' diff --git a/docs/examples/json_pointer__operator__notequal.cpp b/docs/examples/json_pointer__operator__notequal.cpp new file mode 100644 index 0000000000..9bbdd53107 --- /dev/null +++ b/docs/examples/json_pointer__operator__notequal.cpp @@ -0,0 +1,19 @@ +#include +#include + +using json = nlohmann::json; + +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; +} diff --git a/docs/examples/json_pointer__operator__notequal.output b/docs/examples/json_pointer__operator__notequal.output new file mode 100644 index 0000000000..de891f0c6d --- /dev/null +++ b/docs/examples/json_pointer__operator__notequal.output @@ -0,0 +1,4 @@ +"" != "": false +"" != "": false +"" != "/foo": true +"/foo" != "/foo": false diff --git a/docs/examples/json_pointer__operator__notequal_stringtype.cpp b/docs/examples/json_pointer__operator__notequal_stringtype.cpp new file mode 100644 index 0000000000..b9b8987282 --- /dev/null +++ b/docs/examples/json_pointer__operator__notequal_stringtype.cpp @@ -0,0 +1,32 @@ +#include +#include + +using json = nlohmann::json; + +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"); + + // 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; + } +} diff --git a/docs/examples/json_pointer__operator__notequal_stringtype.output b/docs/examples/json_pointer__operator__notequal_stringtype.output new file mode 100644 index 0000000000..61331b7524 --- /dev/null +++ b/docs/examples/json_pointer__operator__notequal_stringtype.output @@ -0,0 +1,4 @@ +"" != "": false +"" != "": false +"/foo" != "/foo": false +"bar" != "/foo": [json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'bar' diff --git a/docs/examples/meta.output b/docs/examples/meta.output index 43fe0a887d..9ceb5e201a 100644 --- a/docs/examples/meta.output +++ b/docs/examples/meta.output @@ -2,7 +2,7 @@ "compiler": { "c++": "201103", "family": "gcc", - "version": "11.3.0" + "version": "12.1.0" }, "copyright": "(C) 2013-2022 Niels Lohmann", "name": "JSON for Modern C++", @@ -11,7 +11,7 @@ "version": { "major": 3, "minor": 11, - "patch": 1, - "string": "3.11.1" + "patch": 2, + "string": "3.11.2" } } diff --git a/docs/examples/nlohmann_json_namespace.cpp b/docs/examples/nlohmann_json_namespace.cpp new file mode 100644 index 0000000000..4bad91f4be --- /dev/null +++ b/docs/examples/nlohmann_json_namespace.cpp @@ -0,0 +1,14 @@ +#include +#include + +// possible use case: use NLOHMANN_JSON_NAMESPACE instead of nlohmann +using json = NLOHMANN_JSON_NAMESPACE::json; + +// macro needed to output the NLOHMANN_JSON_NAMESPACE as string literal +#define Q(x) #x +#define QUOTE(x) Q(x) + +int main() +{ + std::cout << QUOTE(NLOHMANN_JSON_NAMESPACE) << std::endl; +} diff --git a/docs/examples/nlohmann_json_namespace.output b/docs/examples/nlohmann_json_namespace.output new file mode 100644 index 0000000000..1a1df5a3d2 --- /dev/null +++ b/docs/examples/nlohmann_json_namespace.output @@ -0,0 +1 @@ +nlohmann::json_abi_v3_11_2 diff --git a/docs/examples/nlohmann_json_namespace_begin.c++17.cpp b/docs/examples/nlohmann_json_namespace_begin.c++17.cpp new file mode 100644 index 0000000000..9385d593d5 --- /dev/null +++ b/docs/examples/nlohmann_json_namespace_begin.c++17.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +// 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; + } + } +}; +NLOHMANN_JSON_NAMESPACE_END + +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; +} diff --git a/docs/examples/nlohmann_json_namespace_begin.c++17.output b/docs/examples/nlohmann_json_namespace_begin.c++17.output new file mode 100644 index 0000000000..b29d3b93ca --- /dev/null +++ b/docs/examples/nlohmann_json_namespace_begin.c++17.output @@ -0,0 +1 @@ +[1,null] diff --git a/docs/examples/nlohmann_json_namespace_no_version.cpp b/docs/examples/nlohmann_json_namespace_no_version.cpp new file mode 100644 index 0000000000..97948dd7e1 --- /dev/null +++ b/docs/examples/nlohmann_json_namespace_no_version.cpp @@ -0,0 +1,13 @@ +#include + +#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 1 +#include + +// macro needed to output the NLOHMANN_JSON_NAMESPACE as string literal +#define Q(x) #x +#define QUOTE(x) Q(x) + +int main() +{ + std::cout << QUOTE(NLOHMANN_JSON_NAMESPACE) << std::endl; +} diff --git a/docs/examples/nlohmann_json_namespace_no_version.output b/docs/examples/nlohmann_json_namespace_no_version.output new file mode 100644 index 0000000000..1c8f3132bb --- /dev/null +++ b/docs/examples/nlohmann_json_namespace_no_version.output @@ -0,0 +1 @@ +nlohmann::json_abi diff --git a/docs/examples/nlohmann_json_version.output b/docs/examples/nlohmann_json_version.output index d45d2bd17c..043b9b234e 100644 --- a/docs/examples/nlohmann_json_version.output +++ b/docs/examples/nlohmann_json_version.output @@ -1 +1 @@ -JSON for Modern C++ version 3.11.1 +JSON for Modern C++ version 3.11.2 diff --git a/docs/examples/to_json.cpp b/docs/examples/to_json.cpp new file mode 100644 index 0000000000..1f82a4de4e --- /dev/null +++ b/docs/examples/to_json.cpp @@ -0,0 +1,32 @@ +#include +#include + +using json = nlohmann::json; + +namespace ns +{ +// a simple struct to model a person +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 + +int main() +{ + ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; + + json j = p; + + std::cout << j << std::endl; +} diff --git a/docs/examples/to_json.output b/docs/examples/to_json.output new file mode 100644 index 0000000000..e9c5bf381d --- /dev/null +++ b/docs/examples/to_json.output @@ -0,0 +1 @@ +{"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} diff --git a/docs/json.gif b/docs/json.gif index 7bbf1e6b0b..8219866317 100644 Binary files a/docs/json.gif and b/docs/json.gif differ diff --git a/docs/mkdocs/Makefile b/docs/mkdocs/Makefile index 3f894d0980..e4731bfd79 100644 --- a/docs/mkdocs/Makefile +++ b/docs/mkdocs/Makefile @@ -28,6 +28,7 @@ publish: prepare_files # install a Python virtual environment install_venv: requirements.txt python3 -mvenv venv + venv/bin/pip install --upgrade pip venv/bin/pip install wheel venv/bin/pip install -r requirements.txt diff --git a/docs/mkdocs/docs/api/adl_serializer/from_json.md b/docs/mkdocs/docs/api/adl_serializer/from_json.md index 7657855a36..ba932e9e77 100644 --- a/docs/mkdocs/docs/api/adl_serializer/from_json.md +++ b/docs/mkdocs/docs/api/adl_serializer/from_json.md @@ -14,8 +14,8 @@ noexcept(::nlohmann::from_json(std::forward(j), detail::identity_ -> decltype(::nlohmann::from_json(std::forward(j), detail::identity_tag {})) ``` -This function is usually called by the [`get()`](../basic_json/get.md) function of the -[basic_json](../basic_json) class (either explicit or via conversion operators). +This function is usually called by the [`get()`](../basic_json/get.md) function of the [basic_json](../basic_json) +class (either explicitly or via the conversion operators). 1. This function is chosen for default-constructible value types. 2. This function is chosen for value types which are not default-constructible. @@ -32,9 +32,41 @@ This function is usually called by the [`get()`](../basic_json/get.md) function Copy of the JSON value, converted to `ValueType` -!!! note +## Examples - This documentation page is a stub. +??? example "Example: (1) Default-constructible type" + + The example below shows how a `from_json` function can be implemented for a user-defined type. This function is + called by the `adl_serializer` when `get()` is called. + + ```cpp + --8<-- "examples/from_json__default_constructible.cpp" + ``` + + Output: + + ```json + --8<-- "examples/from_json__default_constructible.output" + ``` + +??? example "Example: (2) Non-default-constructible type" + + The example below shows how a `from_json` is implemented as part of a specialization of the `adl_serializer` to + realize the conversion of a non-default-constructible type. + + ```cpp + --8<-- "examples/from_json__non_default_constructible.cpp" + ``` + + Output: + + ```json + --8<-- "examples/from_json__non_default_constructible.output" + ``` + +## See also + +- [to_json](to_json.md) ## Version history diff --git a/docs/mkdocs/docs/api/adl_serializer/to_json.md b/docs/mkdocs/docs/api/adl_serializer/to_json.md index d39f72525a..f8419bd81f 100644 --- a/docs/mkdocs/docs/api/adl_serializer/to_json.md +++ b/docs/mkdocs/docs/api/adl_serializer/to_json.md @@ -17,9 +17,26 @@ This function is usually called by the constructors of the [basic_json](../basic `val` (in) : value to read from -!!! note - - This documentation page is a stub. +## Examples + +??? example + + The example below shows how a `to_json` function can be implemented for a user-defined type. This function is called + by the `adl_serializer` when the constructor `basic_json(ns::person)` is called. + + ```cpp + --8<-- "examples/to_json.cpp" + ``` + + Output: + + ```json + --8<-- "examples/to_json.output" + ``` + +## See also + +- [from_json](from_json.md) ## Version history diff --git a/docs/mkdocs/docs/api/basic_json/boolean_t.md b/docs/mkdocs/docs/api/basic_json/boolean_t.md index 3ca613148d..e3a7830270 100644 --- a/docs/mkdocs/docs/api/basic_json/boolean_t.md +++ b/docs/mkdocs/docs/api/basic_json/boolean_t.md @@ -6,8 +6,8 @@ using boolean_t = BooleanType; The type used to store JSON booleans. -[RFC 8259](https://tools.ietf.org/html/rfc8259) implicitly describes a boolean as a type which differentiates the two literals -`#!json true` and `#!json false`. +[RFC 8259](https://tools.ietf.org/html/rfc8259) implicitly describes a boolean as a type which differentiates the two +literals `#!json true` and `#!json false`. To store objects in C++, a type is defined by the template parameter `BooleanType` which chooses the type to use. diff --git a/docs/mkdocs/docs/api/basic_json/json_serializer.md b/docs/mkdocs/docs/api/basic_json/json_serializer.md index f091155671..b8b67c5cc7 100644 --- a/docs/mkdocs/docs/api/basic_json/json_serializer.md +++ b/docs/mkdocs/docs/api/basic_json/json_serializer.md @@ -19,6 +19,23 @@ using json_serializer = JSONSerializer; The default values for `json_serializer` is [`adl_serializer`](../adl_serializer). +## Examples + +??? example + + The example below shows how a conversion of a non-default-constructible type is implemented via a specialization of + the `adl_serializer`. + + ```cpp + --8<-- "examples/from_json__non_default_constructible.cpp" + ``` + + Output: + + ```json + --8<-- "examples/from_json__non_default_constructible.output" + ``` + ## Version history - Since version 2.0.0. diff --git a/docs/mkdocs/docs/api/basic_json/object_comparator_t.md b/docs/mkdocs/docs/api/basic_json/object_comparator_t.md index 496a56267e..d41b982297 100644 --- a/docs/mkdocs/docs/api/basic_json/object_comparator_t.md +++ b/docs/mkdocs/docs/api/basic_json/object_comparator_t.md @@ -28,4 +28,5 @@ and [`default_object_comparator_t`](default_object_comparator_t.md) otherwise. ## Version history - Added in version 3.0.0. -- Changed to be conditionally defined as `#!cpp typename object_t::key_compare` or `default_object_comparator_t` in version 3.11.0. +- Changed to be conditionally defined as `#!cpp typename object_t::key_compare` or `default_object_comparator_t` in + version 3.11.0. diff --git a/docs/mkdocs/docs/api/basic_json/object_t.md b/docs/mkdocs/docs/api/basic_json/object_t.md index 67b3bb78c8..39f68b0891 100644 --- a/docs/mkdocs/docs/api/basic_json/object_t.md +++ b/docs/mkdocs/docs/api/basic_json/object_t.md @@ -90,7 +90,8 @@ Objects are stored as pointers in a `basic_json` type. That is, for any access t The order name/value pairs are added to the object is *not* preserved by the library. Therefore, iterating an object may return name/value pairs in a different order than they were originally stored. In fact, keys will be traversed in alphabetical order as `std::map` with `std::less` is used by default. Please note this behavior conforms to -[RFC 8259](https://tools.ietf.org/html/rfc8259), because any order implements the specified "unordered" nature of JSON objects. +[RFC 8259](https://tools.ietf.org/html/rfc8259), because any order implements the specified "unordered" nature of JSON +objects. ## Examples diff --git a/docs/mkdocs/docs/api/basic_json/operator[].md b/docs/mkdocs/docs/api/basic_json/operator[].md index ebc737e4bc..51dd8588cb 100644 --- a/docs/mkdocs/docs/api/basic_json/operator[].md +++ b/docs/mkdocs/docs/api/basic_json/operator[].md @@ -21,7 +21,8 @@ const_reference operator[](const json_pointer& ptr) const; ``` 1. Returns a reference to the array element at specified location `idx`. -2. Returns a reference to the object element with specified key `key`. The non-const qualified overload takes the key by value. +2. Returns a reference to the object element with specified key `key`. The non-const qualified overload takes the key by + value. 3. See 2. This overload is only available if `KeyType` is comparable with `#!cpp typename object_t::key_type` and `#!cpp typename object_comparator_t::is_transparent` denotes a type. 4. Returns a reference to the element with specified JSON pointer `ptr`. @@ -234,6 +235,7 @@ Strong exception safety: if an exception occurs, the original value stays intact ## Version history 1. Added in version 1.0.0. -2. Added in version 1.0.0. Added overloads for `T* key` in version 1.1.0. Removed overloads for `T* key` (replaced by 3) in version 3.11.0. +2. Added in version 1.0.0. Added overloads for `T* key` in version 1.1.0. Removed overloads for `T* key` (replaced by 3) + in version 3.11.0. 3. Added in version 3.11.0. 4. Added in version 2.0.0. diff --git a/docs/mkdocs/docs/api/basic_json/operator_eq.md b/docs/mkdocs/docs/api/basic_json/operator_eq.md index b4d61b6371..a2ce6155c3 100644 --- a/docs/mkdocs/docs/api/basic_json/operator_eq.md +++ b/docs/mkdocs/docs/api/basic_json/operator_eq.md @@ -20,8 +20,8 @@ class basic_json { ``` 1. Compares two JSON values for equality according to the following rules: - - Two JSON values are equal if (1) neither value is discarded, or (2) they are of the same - type and their stored values are the same according to their respective `operator==`. + - Two JSON values are equal if (1) neither value is discarded, or (2) they are of the same type and their stored + values are the same according to their respective `operator==`. - Integer and floating-point numbers are automatically converted before comparison. 2. Compares a JSON value and a scalar or a scalar and a JSON value for equality by converting the diff --git a/docs/mkdocs/docs/api/basic_json/operator_ge.md b/docs/mkdocs/docs/api/basic_json/operator_ge.md index 847f6ca656..d4e2fb4a50 100644 --- a/docs/mkdocs/docs/api/basic_json/operator_ge.md +++ b/docs/mkdocs/docs/api/basic_json/operator_ge.md @@ -11,15 +11,14 @@ template bool operator>=(ScalarType lhs, const const_reference rhs) noexcept; // (2) ``` -1. Compares whether one JSON value `lhs` is greater than or equal to another JSON value `rhs` - according to the following rules: - - The comparison always yields `#!cpp false` if (1) either operand is discarded, or (2) either - operand is `NaN` and the other operand is either `NaN` or any other number. +1. Compares whether one JSON value `lhs` is greater than or equal to another JSON value `rhs` according to the following + rules: + - The comparison always yields `#!cpp false` if (1) either operand is discarded, or (2) either operand is `NaN` and + the other operand is either `NaN` or any other number. - Otherwise, returns the result of `#!cpp !(lhs < rhs)` (see [**operator<**](operator_lt.md)). -2. Compares wether a JSON value is greater than or equal to a scalar or a scalar is greater than or - equal to a JSON value by converting the scalar to a JSON value and comparing both JSON values - according to 1. +2. Compares whether a JSON value is greater than or equal to a scalar or a scalar is greater than or equal to a JSON + value by converting the scalar to a JSON value and comparing both JSON values according to 1. ## Template parameters diff --git a/docs/mkdocs/docs/api/basic_json/operator_ne.md b/docs/mkdocs/docs/api/basic_json/operator_ne.md index f5d989b506..982a06764d 100644 --- a/docs/mkdocs/docs/api/basic_json/operator_ne.md +++ b/docs/mkdocs/docs/api/basic_json/operator_ne.md @@ -20,13 +20,12 @@ class basic_json { ``` 1. Compares two JSON values for inequality according to the following rules: - - The comparison always yields `#!cpp false` if (1) either operand is discarded, or (2) either - operand is `NaN` and the other operand is either `NaN` or any other number. - - Otherwise, returns the result of `#!cpp !(lhs == rhs)` (until C++20) or - `#!cpp !(*this == rhs)` (since C++20). + - The comparison always yields `#!cpp false` if (1) either operand is discarded, or (2) either operand is `NaN` and + the other operand is either `NaN` or any other number. + - Otherwise, returns the result of `#!cpp !(lhs == rhs)` (until C++20) or `#!cpp !(*this == rhs)` (since C++20). -2. Compares a JSON value and a scalar or a scalar and a JSON value for inequality by converting the - scalar to a JSON value and comparing both JSON values according to 1. +2. Compares a JSON value and a scalar or a scalar and a JSON value for inequality by converting the scalar to a JSON + value and comparing both JSON values according to 1. ## Template parameters diff --git a/docs/mkdocs/docs/api/basic_json/operator_spaceship.md b/docs/mkdocs/docs/api/basic_json/operator_spaceship.md index f5bf1cf358..9e91d0d2da 100644 --- a/docs/mkdocs/docs/api/basic_json/operator_spaceship.md +++ b/docs/mkdocs/docs/api/basic_json/operator_spaceship.md @@ -12,16 +12,16 @@ class basic_json { 1. 3-way compares two JSON values producing a result of type `std::partial_ordering` according to the following rules: - Two JSON values compare with a result of `std::partial_ordering::unordered` if either value is discarded. - - If both JSON values are of the same type, the result is produced by 3-way comparing their stored values using their + - If both JSON values are of the same type, the result is produced by 3-way comparing their stored values using + their respective `operator<=>`. + - Integer and floating-point numbers are converted to their common type and then 3-way compared using their respective `operator<=>`. - - Integer and floating-point numbers are converted to their common type and then 3-way compared using their respective - `operator<=>`. - For instance, comparing an integer and a floating-point value will 3-way compare the first value convertered to + For instance, comparing an integer and a floating-point value will 3-way compare the first value converted to floating-point with the second value. - Otherwise, yields a result by comparing the type (see [`value_t`](value_t.md)). -2. 3-way compares a JSON value and a scalar or a scalar and a JSON value by converting the scalar to a JSON value and 3-way - comparing both JSON values (see 1). +2. 3-way compares a JSON value and a scalar or a scalar and a JSON value by converting the scalar to a JSON value and + 3-way comparing both JSON values (see 1). ## Template parameters diff --git a/docs/mkdocs/docs/api/basic_json/to_bjdata.md b/docs/mkdocs/docs/api/basic_json/to_bjdata.md index 1ea8505239..48598a5e61 100644 --- a/docs/mkdocs/docs/api/basic_json/to_bjdata.md +++ b/docs/mkdocs/docs/api/basic_json/to_bjdata.md @@ -13,8 +13,8 @@ static void to_bjdata(const basic_json& j, detail::output_adapter o, const bool use_size = false, const bool use_type = false); ``` -Serializes a given JSON value `j` to a byte vector using the BJData (Binary JData) serialization format. BJData -aims to be more compact than JSON itself, yet more efficient to parse. +Serializes a given JSON value `j` to a byte vector using the BJData (Binary JData) serialization format. BJData aims to +be more compact than JSON itself, yet more efficient to parse. 1. Returns a byte vector containing the BJData serialization. 2. Writes the BJData serialization to an output adapter. diff --git a/docs/mkdocs/docs/api/basic_json/value.md b/docs/mkdocs/docs/api/basic_json/value.md index b5fd14d1c7..edb5406ba6 100644 --- a/docs/mkdocs/docs/api/basic_json/value.md +++ b/docs/mkdocs/docs/api/basic_json/value.md @@ -7,7 +7,7 @@ ValueType value(const typename object_t::key_type& key, ValueType&& default_value) const; // (2) -template +template ValueType value(KeyType&& key, ValueType&& default_value) const; @@ -155,5 +155,5 @@ changes to any JSON value. ## Version history 1. Added in version 1.0.0. Changed parameter `default_value` type from `const ValueType&` to `ValueType&&` in version 3.11.0. -2. Added in version 3.11.0. +2. Added in version 3.11.0. Made `ValueType` the first template parameter in version 3.11.2. 3. Added in version 2.0.2. diff --git a/docs/mkdocs/docs/api/basic_json/value_t.md b/docs/mkdocs/docs/api/basic_json/value_t.md index f835740830..1505e02d08 100644 --- a/docs/mkdocs/docs/api/basic_json/value_t.md +++ b/docs/mkdocs/docs/api/basic_json/value_t.md @@ -52,10 +52,8 @@ functions [`is_null`](is_null.md), [`is_object`](is_object.md), [`is_array`](is_ `operator<` and `operator<=>` (since C++20) are overloaded and compare according to the ordering described above. Until C++20 all other relational and equality operators yield results according to the integer value of each - enumerator. - Since C++20 some compilers consider the _rewritten candidates_ generated from `operator<=>` during overload - resolution, while others do not. - For predictable and portable behavior use: + enumerator. Since C++20 some compilers consider the _rewritten candidates_ generated from `operator<=>` during + overload resolution, while others do not. For predictable and portable behavior use: - `operator<` or `operator<=>` when wanting to compare according to the order described above - `operator==` or `operator!=` when wanting to compare according to each enumerators integer value diff --git a/docs/mkdocs/docs/api/basic_json/~basic_json.md b/docs/mkdocs/docs/api/basic_json/~basic_json.md index c5c74a5257..64e9440063 100644 --- a/docs/mkdocs/docs/api/basic_json/~basic_json.md +++ b/docs/mkdocs/docs/api/basic_json/~basic_json.md @@ -14,6 +14,8 @@ No-throw guarantee: this member function never throws exceptions. Linear. + + ## Version history - Added in version 1.0.0. diff --git a/docs/mkdocs/docs/api/json_pointer/index.md b/docs/mkdocs/docs/api/json_pointer/index.md index 75b536c1c5..22e2464053 100644 --- a/docs/mkdocs/docs/api/json_pointer/index.md +++ b/docs/mkdocs/docs/api/json_pointer/index.md @@ -29,6 +29,8 @@ are the base for JSON patches. - [(constructor)](json_pointer.md) - [**to_string**](to_string.md) - return a string representation of the JSON pointer - [**operator string_t**](operator_string_t.md) - return a string representation of the JSON pointer +- [**operator==**](operator_eq.md) - compare: equal +- [**operator!=**](operator_ne.md) - compare: not equal - [**operator/=**](operator_slasheq.md) - append to the end of the JSON pointer - [**operator/**](operator_slash.md) - create JSON Pointer by appending - [**parent_pointer**](parent_pointer.md) - returns the parent of this JSON pointer diff --git a/docs/mkdocs/docs/api/json_pointer/operator_eq.md b/docs/mkdocs/docs/api/json_pointer/operator_eq.md new file mode 100644 index 0000000000..807ae1d0ce --- /dev/null +++ b/docs/mkdocs/docs/api/json_pointer/operator_eq.md @@ -0,0 +1,113 @@ +# nlohmann::json_pointer::operator== + +```cpp +// until C++20 +template +bool operator==( + const json_pointer& lhs, + const json_pointer& rhs) noexcept; // (1) + +template +bool operator==( + const json_pointer& lhs, + const StringType& rhs); // (2) + +template +bool operator==( + const StringType& lhs, + const json_pointer& rhs); // (2) + +// since C++20 +class json_pointer { + template + bool operator==( + const json_pointer& rhs) const noexcept; // (1) + + bool operator==(const string_t& rhs) const; // (2) +}; +``` + +1. Compares two JSON pointers for equality by comparing their reference tokens. + +2. Compares a JSON pointer and a string or a string and a JSON pointer for equality by converting the string to a JSON + pointer and comparing the JSON pointers according to 1. + +## Template parameters + +`RefStringTypeLhs`, `RefStringTypeRhs` +: the string type of the left-hand side or right-hand side JSON pointer, respectively + +`StringType` +: the string type derived from the `json_pointer` operand ([`json_pointer::string_t`](string_t.md)) + +## Parameters + +`lhs` (in) +: first value to consider + +`rhs` (in) +: second value to consider + +## Return value + +whether the values `lhs`/`*this` and `rhs` are equal + +## Exception safety + +1. No-throw guarantee: this function never throws exceptions. +2. Strong exception safety: if an exception occurs, the original value stays intact. + +## Exceptions + +1. (none) +2. The function can throw the following exceptions: + - Throws [parse_error.107](../../home/exceptions.md#jsonexceptionparse_error107) if the given JSON pointer `s` is + nonempty and does not begin with a slash (`/`); see example below. + - Throws [parse_error.108](../../home/exceptions.md#jsonexceptionparse_error108) if a tilde (`~`) in the given JSON + pointer `s` is not followed by `0` (representing `~`) or `1` (representing `/`); see example below. + +## Complexity + +Constant if `lhs` and `rhs` differ in the number of reference tokens, otherwise linear in the number of reference +tokens. + +## Notes + +!!! warning "Deprecation" + + Overload 2 is deprecated and will be removed in a future major version release. + +## Examples + +??? example "Example: (1) Comparing JSON pointers" + + The example demonstrates comparing JSON pointers. + + ```cpp + --8<-- "examples/json_pointer__operator__equal.cpp" + ``` + + Output: + + ``` + --8<-- "examples/json_pointer__operator__equal.output" + ``` + +??? example "Example: (2) Comparing JSON pointers and strings" + + The example demonstrates comparing JSON pointers and strings, and when doing so may raise an exception. + + ```cpp + --8<-- "examples/json_pointer__operator__equal_stringtype.cpp" + ``` + + Output: + + ``` + --8<-- "examples/json_pointer__operator__equal_stringtype.output" + ``` + +## Version history + +1. Added in version 2.1.0. Added C++20 member functions in version 3.11.2. +2. Added for backward compatibility and deprecated in version 3.11.2. diff --git a/docs/mkdocs/docs/api/json_pointer/operator_ne.md b/docs/mkdocs/docs/api/json_pointer/operator_ne.md new file mode 100644 index 0000000000..1f3e3247e0 --- /dev/null +++ b/docs/mkdocs/docs/api/json_pointer/operator_ne.md @@ -0,0 +1,109 @@ +# nlohmann::json_pointer::operator!= + +```cpp +// until C++20 +template +bool operator!=( + const json_pointer& lhs, + const json_pointer& rhs) noexcept; // (1) + +template +bool operator!=( + const json_pointer& lhs, + const StringType& rhs); // (2) + +template +bool operator!=( + const StringType& lhs, + const json_pointer& rhs); // (2) +``` + +1. Compares two JSON pointers for inequality by comparing their reference tokens. + +2. Compares a JSON pointer and a string or a string and a JSON pointer for inequality by converting the string to a + JSON pointer and comparing the JSON pointers according to 1. + +## Template parameters + +`RefStringTypeLhs`, `RefStringTypeRhs` +: the string type of the left-hand side or right-hand side JSON pointer, respectively + +`StringType` +: the string type derived from the `json_pointer` operand ([`json_pointer::string_t`](string_t.md)) + +## Parameters + +`lhs` (in) +: first value to consider + +`rhs` (in) +: second value to consider + +## Return value + +whether the values `lhs`/`*this` and `rhs` are not equal + +## Exception safety + +1. No-throw guarantee: this function never throws exceptions. +2. Strong exception safety: if an exception occurs, the original value stays intact. + +## Exceptions + +1. (none) +2. The function can throw the following exceptions: + - Throws [parse_error.107](../../home/exceptions.md#jsonexceptionparse_error107) if the given JSON pointer `s` is + nonempty and does not begin with a slash (`/`); see example below. + - Throws [parse_error.108](../../home/exceptions.md#jsonexceptionparse_error108) if a tilde (`~`) in the given JSON + pointer `s` is not followed by `0` (representing `~`) or `1` (representing `/`); see example below. + +## Complexity + +Constant if `lhs` and `rhs` differ in the number of reference tokens, otherwise linear in the number of reference +tokens. + +## Notes + +!!! note "Operator overload resolution" + + Since C++20 overload resolution will consider the _rewritten candidate_ generated from + [`operator==`](operator_eq.md). + +!!! warning "Deprecation" + + Overload 2 is deprecated and will be removed in a future major version release. + +## Examples + +??? example "Example: (1) Comparing JSON pointers" + + The example demonstrates comparing JSON pointers. + + ```cpp + --8<-- "examples/json_pointer__operator__notequal.cpp" + ``` + + Output: + + ``` + --8<-- "examples/json_pointer__operator__notequal.output" + ``` + +??? example "Example: (2) Comparing JSON pointers and strings" + + The example demonstrates comparing JSON pointers and strings, and when doing so may raise an exception. + + ```cpp + --8<-- "examples/json_pointer__operator__notequal_stringtype.cpp" + ``` + + Output: + + ``` + --8<-- "examples/json_pointer__operator__notequal_stringtype.output" + ``` + +## Version history + +1. Added in version 2.1.0. +2. Added for backward compatibility and deprecated in version 3.11.2. diff --git a/docs/mkdocs/docs/api/json_sax/binary.md b/docs/mkdocs/docs/api/json_sax/binary.md index 753e99c00c..fc0980e20b 100644 --- a/docs/mkdocs/docs/api/json_sax/binary.md +++ b/docs/mkdocs/docs/api/json_sax/binary.md @@ -23,7 +23,7 @@ It is safe to move the passed binary value. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse__binary.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/boolean.md b/docs/mkdocs/docs/api/json_sax/boolean.md index 78163b331a..fdf2945622 100644 --- a/docs/mkdocs/docs/api/json_sax/boolean.md +++ b/docs/mkdocs/docs/api/json_sax/boolean.md @@ -19,7 +19,7 @@ Whether parsing should proceed. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/end_array.md b/docs/mkdocs/docs/api/json_sax/end_array.md index 46b4c7a4bb..9c12e40a5e 100644 --- a/docs/mkdocs/docs/api/json_sax/end_array.md +++ b/docs/mkdocs/docs/api/json_sax/end_array.md @@ -14,7 +14,7 @@ Whether parsing should proceed. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/end_object.md b/docs/mkdocs/docs/api/json_sax/end_object.md index 8df0ab4e1a..601c94a4ab 100644 --- a/docs/mkdocs/docs/api/json_sax/end_object.md +++ b/docs/mkdocs/docs/api/json_sax/end_object.md @@ -14,7 +14,7 @@ Whether parsing should proceed. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/key.md b/docs/mkdocs/docs/api/json_sax/key.md index ebd3ae2b23..31fd6c1d12 100644 --- a/docs/mkdocs/docs/api/json_sax/key.md +++ b/docs/mkdocs/docs/api/json_sax/key.md @@ -23,7 +23,7 @@ It is safe to move the passed object key value. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/null.md b/docs/mkdocs/docs/api/json_sax/null.md index 71b2a458a1..9354ede6ca 100644 --- a/docs/mkdocs/docs/api/json_sax/null.md +++ b/docs/mkdocs/docs/api/json_sax/null.md @@ -14,7 +14,7 @@ Whether parsing should proceed. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/number_float.md b/docs/mkdocs/docs/api/json_sax/number_float.md index e1b3fb60f2..17799401ee 100644 --- a/docs/mkdocs/docs/api/json_sax/number_float.md +++ b/docs/mkdocs/docs/api/json_sax/number_float.md @@ -22,7 +22,7 @@ Whether parsing should proceed. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/number_integer.md b/docs/mkdocs/docs/api/json_sax/number_integer.md index 8628a655c6..5c3cb4f316 100644 --- a/docs/mkdocs/docs/api/json_sax/number_integer.md +++ b/docs/mkdocs/docs/api/json_sax/number_integer.md @@ -19,7 +19,7 @@ Whether parsing should proceed. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/number_unsigned.md b/docs/mkdocs/docs/api/json_sax/number_unsigned.md index 7b59748238..0ac2500373 100644 --- a/docs/mkdocs/docs/api/json_sax/number_unsigned.md +++ b/docs/mkdocs/docs/api/json_sax/number_unsigned.md @@ -19,7 +19,7 @@ Whether parsing should proceed. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/parse_error.md b/docs/mkdocs/docs/api/json_sax/parse_error.md index d4405d09e5..e41cb67ff2 100644 --- a/docs/mkdocs/docs/api/json_sax/parse_error.md +++ b/docs/mkdocs/docs/api/json_sax/parse_error.md @@ -27,7 +27,7 @@ Whether parsing should proceed (**must return `#!cpp false`**). ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/start_array.md b/docs/mkdocs/docs/api/json_sax/start_array.md index 8ef10a4ab7..cf2b8cf565 100644 --- a/docs/mkdocs/docs/api/json_sax/start_array.md +++ b/docs/mkdocs/docs/api/json_sax/start_array.md @@ -23,7 +23,7 @@ Binary formats may report the number of elements. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/start_object.md b/docs/mkdocs/docs/api/json_sax/start_object.md index 24fedffc3e..491815deb3 100644 --- a/docs/mkdocs/docs/api/json_sax/start_object.md +++ b/docs/mkdocs/docs/api/json_sax/start_object.md @@ -23,7 +23,7 @@ Binary formats may report the number of elements. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/json_sax/string.md b/docs/mkdocs/docs/api/json_sax/string.md index 1cb6014ac0..dcffb5f612 100644 --- a/docs/mkdocs/docs/api/json_sax/string.md +++ b/docs/mkdocs/docs/api/json_sax/string.md @@ -23,7 +23,7 @@ It is safe to move the passed string value. ??? example - .The example below shows how the SAX interface is used. + The example below shows how the SAX interface is used. ```cpp --8<-- "examples/sax_parse.cpp" diff --git a/docs/mkdocs/docs/api/macros/index.md b/docs/mkdocs/docs/api/macros/index.md index 8e118b03fe..099dfa6712 100644 --- a/docs/mkdocs/docs/api/macros/index.md +++ b/docs/mkdocs/docs/api/macros/index.md @@ -32,7 +32,10 @@ header. See also the [macro overview page](../../features/macros.md). ## Library namespace - [**NLOHMANN_JSON_NAMESPACE**](nlohmann_json_namespace.md) - full name of the `nlohmann` namespace -- [**NLOHMANN_JSON_NAMESPACE_BEGIN**
**NLOHMANN_JSON_NAMESPACE_END**](nlohmann_json_namespace_begin.md) - open and close the library namespace +- [**NLOHMANN_JSON_NAMESPACE_BEGIN**
**NLOHMANN_JSON_NAMESPACE_END**](nlohmann_json_namespace_begin.md) - open and + close the library namespace +- [**NLOHMANN_JSON_NAMESPACE_NO_VERSION**](nlohmann_json_namespace_no_version.md) - disable the version component of + the inline namespace ## Type conversions diff --git a/docs/mkdocs/docs/api/macros/json_use_global_udls.md b/docs/mkdocs/docs/api/macros/json_use_global_udls.md index dc9b55f624..69db9e77c3 100644 --- a/docs/mkdocs/docs/api/macros/json_use_global_udls.md +++ b/docs/mkdocs/docs/api/macros/json_use_global_udls.md @@ -21,8 +21,7 @@ When the macro is not defined, the library will define it to its default value. !!! info "Future behavior change" - The user-defined string literals will be removed from the global namespace in the next major release of the - library. + The user-defined string literals will be removed from the global namespace in the next major release of the library. To prepare existing code, define `JSON_USE_GLOBAL_UDLS` to `0` and bring the string literals into scope where needed. Refer to any of the [string literals](#see-also) for details. @@ -30,8 +29,8 @@ When the macro is not defined, the library will define it to its default value. !!! hint "CMake option" The placement of user-defined string literals can also be controlled with the CMake option - [`JSON_GlobalUDLs`](../../integration/cmake.md#json_globaludls) (`OFF` by default) - which defines `JSON_USE_GLOBAL_UDLS` accordingly. + [`JSON_GlobalUDLs`](../../integration/cmake.md#json_globaludls) (`ON` by default) which defines + `JSON_USE_GLOBAL_UDLS` accordingly. ## Examples diff --git a/docs/mkdocs/docs/api/macros/json_use_legacy_discarded_value_comparison.md b/docs/mkdocs/docs/api/macros/json_use_legacy_discarded_value_comparison.md index bdb0a4607b..bc1d1434a7 100644 --- a/docs/mkdocs/docs/api/macros/json_use_legacy_discarded_value_comparison.md +++ b/docs/mkdocs/docs/api/macros/json_use_legacy_discarded_value_comparison.md @@ -4,8 +4,8 @@ #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON /* value */ ``` -This macro enables the (incorrect) legacy comparison behavior of discarded JSON values. -Possible values are `1` to enable or `0` to disable (default). +This macro enables the (incorrect) legacy comparison behavior of discarded JSON values. Possible values are `1` to +enable or `0` to disable (default). When enabled, comparisons involving at least one discarded JSON value yield results as follows: @@ -42,19 +42,16 @@ When the macro is not defined, the library will define it to its default value. `JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON`. - Overloads for the equality and relational operators emulate the legacy behavior. - Code outside your control may use either 3-way comparison or the equality and - relational operators, resulting in inconsistent and unpredictable behavior. + Code outside your control may use either 3-way comparison or the equality and relational operators, resulting in + inconsistent and unpredictable behavior. - See [`operator<=>`](../basic_json/operator_spaceship.md) for more information on 3-way - comparison. + See [`operator<=>`](../basic_json/operator_spaceship.md) for more information on 3-way comparison. !!! warning "Deprecation" - The legacy comparison behavior is deprecated and may be removed in a future major - version release. + The legacy comparison behavior is deprecated and may be removed in a future major version release. - New code should not depend on it and existing code should try to remove or rewrite - expressions relying on it. + New code should not depend on it and existing code should try to remove or rewrite expressions relying on it. !!! hint "CMake option" diff --git a/docs/mkdocs/docs/api/macros/nlohmann_define_type_intrusive.md b/docs/mkdocs/docs/api/macros/nlohmann_define_type_intrusive.md index 9a14ad7231..afd09c6db3 100644 --- a/docs/mkdocs/docs/api/macros/nlohmann_define_type_intrusive.md +++ b/docs/mkdocs/docs/api/macros/nlohmann_define_type_intrusive.md @@ -7,9 +7,9 @@ These macros can be used to simplify the serialization/deserialization of types if you want to use a JSON object as serialization and want to use the member variable names as object keys in that object. The macro is to be defined -**inside** the class/struct to create code for. -Unlike [`NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE`](nlohmann_define_type_non_intrusive.md), it can access private members. -The first parameter is the name of the class/struct, and all remaining parameters name the members. +**inside** the class/struct to create code for. Unlike +[`NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE`](nlohmann_define_type_non_intrusive.md), it can access private members. The first +parameter is the name of the class/struct, and all remaining parameters name the members. 1. Will use [`at`](../basic_json/at.md) during deserialization and will throw [`out_of_range.403`](../../home/exceptions.md#jsonexceptionout_of_range403) if a key is missing in the JSON object. @@ -40,8 +40,8 @@ See examples below for the concrete generated code. !!! info "Prerequisites" - 1. The type `type` must be default constructible. See [How can I use `get()` for non-default constructible/non-copyable types?][GetNonDefNonCopy] - for how to overcome this limitation. + 1. The type `type` must be default constructible. See [How can I use `get()` for non-default + constructible/non-copyable types?][GetNonDefNonCopy] for how to overcome this limitation. 2. The macro must be used inside the type (class/struct). [GetNonDefNonCopy]: ../../features/arbitrary_types.md#how-can-i-use-get-for-non-default-constructiblenon-copyable-types diff --git a/docs/mkdocs/docs/api/macros/nlohmann_define_type_non_intrusive.md b/docs/mkdocs/docs/api/macros/nlohmann_define_type_non_intrusive.md index 28b3589525..70cf934fcc 100644 --- a/docs/mkdocs/docs/api/macros/nlohmann_define_type_non_intrusive.md +++ b/docs/mkdocs/docs/api/macros/nlohmann_define_type_non_intrusive.md @@ -7,9 +7,9 @@ These macros can be used to simplify the serialization/deserialization of types if you want to use a JSON object as serialization and want to use the member variable names as object keys in that object. The macro is to be defined -**outside** the class/struct to create code for, but **inside** its namespace. -Unlike [`NLOHMANN_DEFINE_TYPE_INTRUSIVE`](nlohmann_define_type_intrusive.md), it **cannot** access private members. -The first parameter is the name of the class/struct, and all remaining parameters name the members. +**outside** the class/struct to create code for, but **inside** its namespace. Unlike +[`NLOHMANN_DEFINE_TYPE_INTRUSIVE`](nlohmann_define_type_intrusive.md), it **cannot** access private members. The first +parameter is the name of the class/struct, and all remaining parameters name the members. 1. Will use [`at`](../basic_json/at.md) during deserialization and will throw [`out_of_range.403`](../../home/exceptions.md#jsonexceptionout_of_range403) if a key is missing in the JSON object. @@ -103,7 +103,8 @@ See examples below for the concrete generated code. - `ns::person` is default-constructible. This is a requirement for using the macro. - `ns::person` has only public member variables. This makes `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT` applicable. - - The macro `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT` is used _outside_ the class, but _inside_ its namespace `ns`. + - The macro `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT` is used _outside_ the class, but _inside_ its + namespace `ns`. - A missing key "age" in the deserialization does not yield an exception. Instead, the default value `-1` is used. The macro is equivalent to: diff --git a/docs/mkdocs/docs/api/macros/nlohmann_json_namespace.md b/docs/mkdocs/docs/api/macros/nlohmann_json_namespace.md index d76bffb812..5c54dba52e 100644 --- a/docs/mkdocs/docs/api/macros/nlohmann_json_namespace.md +++ b/docs/mkdocs/docs/api/macros/nlohmann_json_namespace.md @@ -1,26 +1,41 @@ # NLOHMANN_JSON_NAMESPACE ```cpp -#define NLOHMANN_JSON_NAMESPACE +#define NLOHMANN_JSON_NAMESPACE /* value */ ``` -This macro evaluates to the full name of the `nlohmann` namespace, including -the name of a versioned and ABI-tagged inline namespace. Use this macro to -unambiguously refer to the `nlohmann` namespace. +This macro evaluates to the full name of the `nlohmann` namespace. ## Default definition -The default value consists of a prefix, a version string, and optional ABI tags -depending on whether ABI-affecting macros are defined (e.g., -[`JSON_DIAGNOSTICS`](json_diagnostics.md), and -[`JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON`](json_use_legacy_discarded_value_comparison.md)). +The default value consists of the root namespace (`nlohmann`) and an inline ABI namespace. See +[`nlohmann` Namespace](../../features/namespace.md#structure) for details. -When the macro is not defined, the library will define it to its default value. +When the macro is not defined, the library will define it to its default value. Overriding this value has no effect on +the library. + +## Examples + +??? example + + The example shows how to use `NLOHMANN_JSON_NAMESPACE` instead of just `nlohmann`, as well as how to output the value + of `NLOHMANN_JSON_NAMESPACE`. + + ```cpp + --8<-- "examples/nlohmann_json_namespace.cpp" + ``` + + Output: + + ```json + --8<-- "examples/nlohmann_json_namespace.output" + ``` ## See also - [`NLOHMANN_JSON_NAMESPACE_BEGIN, NLOHMANN_JSON_NAMESPACE_END`](nlohmann_json_namespace_begin.md) +- [`NLOHMANN_JSON_NAMESPACE_NO_VERSION`](nlohmann_json_namespace_no_version.md) ## Version history -- Added in version 3.11.0. +- Added in version 3.11.0. Changed inline namespace name in version 3.11.2. diff --git a/docs/mkdocs/docs/api/macros/nlohmann_json_namespace_begin.md b/docs/mkdocs/docs/api/macros/nlohmann_json_namespace_begin.md index 83844b502c..1374264a3b 100644 --- a/docs/mkdocs/docs/api/macros/nlohmann_json_namespace_begin.md +++ b/docs/mkdocs/docs/api/macros/nlohmann_json_namespace_begin.md @@ -1,40 +1,61 @@ # NLOHMANN_JSON_NAMESPACE_BEGIN, NLOHMANN_JSON_NAMESPACE_END ```cpp -#define NLOHMANN_JSON_NAMESPACE_BEGIN // (1) -#define NLOHMANN_JSON_NAMESPACE_END // (2) +#define NLOHMANN_JSON_NAMESPACE_BEGIN /* value */ // (1) +#define NLOHMANN_JSON_NAMESPACE_END /* value */ // (2) ``` -These macros can be used to open and close the `nlohmann` namespace. They -include an inline namespace used to differentiate symbols when linking multiple -versions (including different ABI-affecting macros) of this library. +These macros can be used to open and close the `nlohmann` namespace. See +[`nlohmann` Namespace](../../features/namespace.md#structure) for details. 1. Opens the namespace. +2. Closes the namespace. + +## Default definition + +The default definitions open and close the `nlohmann` namespace. The precise definition of +[`NLOHMANN_JSON_NAMESPACE_BEGIN`] varies as described [here](../../features/namespace.md#structure). + +1. Default definition of `NLOHMANN_JSON_NAMESPACE_BEGIN`: + ```cpp namespace nlohmann { - inline namespace json_v3_11_0 + inline namespace json_abi_v3_11_2 { ``` -2. Closes the namespace. +2. Default definition of `NLOHMANN_JSON_NAMESPACE_END`: ```cpp + } // namespace json_abi_v3_11_2 } // namespace nlohmann - } // json_v3_11_0 ``` -## Default definition +When these macros are not defined, the library will define them to their default definitions. + +## Examples + +??? example -The default definitions open and close the `nlohmann` as well as an inline -namespace. + The example shows how to use `NLOHMANN_JSON_NAMESPACE_BEGIN`/`NLOHMANN_JSON_NAMESPACE_END` from the + [How do I convert third-party types?](../../features/arbitrary_types.md#how-do-i-convert-third-party-types) page. -When these macros are not defined, the library will define them to their -default definitions. + ```cpp + --8<-- "examples/nlohmann_json_namespace_begin.c++17.cpp" + ``` + + Output: + + ```json + --8<-- "examples/nlohmann_json_namespace_begin.c++17.output" + ``` ## See also +- [`nlohmann` Namespace](../../features/namespace.md) - [NLOHMANN_JSON_NAMESPACE](nlohmann_json_namespace.md) +- [`NLOHMANN_JSON_NAMESPACE_NO_VERSION`](nlohmann_json_namespace_no_version.md) ## Version history -- Added in version 3.11.0. +- Added in version 3.11.0. Changed inline namespace name in version 3.11.2. diff --git a/docs/mkdocs/docs/api/macros/nlohmann_json_namespace_no_version.md b/docs/mkdocs/docs/api/macros/nlohmann_json_namespace_no_version.md new file mode 100644 index 0000000000..9e2a52d042 --- /dev/null +++ b/docs/mkdocs/docs/api/macros/nlohmann_json_namespace_no_version.md @@ -0,0 +1,45 @@ +# NLOHMANN_JSON_NAMESPACE_NO_VERSION + +```cpp +#define NLOHMANN_JSON_NAMESPACE_NO_VERSION /* value */ +``` + +If defined to `1`, the version component is omitted from the inline namespace. See +[`nlohmann` Namespace](../../features/namespace.md#structure) for details. + +## Default definition + +The default value is `0`. + +```cpp +#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 +``` + +When the macro is not defined, the library will define it to its default value. + +## Examples + +??? example + + The example shows how to use `NLOHMANN_JSON_NAMESPACE_NO_VERSION` to disable the version component of the inline + namespace. + + ```cpp + --8<-- "examples/nlohmann_json_namespace_no_version.cpp" + ``` + + Output: + + ```json + --8<-- "examples/nlohmann_json_namespace_no_version.output" + ``` + +## See also + +- [`nlohmann` Namespace](../../features/namespace.md) +- [`NLOHMANN_JSON_NAMESPACE`](nlohmann_json_namespace.md) +- [`NLOHMANN_JSON_NAMESPACE_BEGIN, NLOHMANN_JSON_NAMESPACE_END`](nlohmann_json_namespace_begin.md) + +## Version history + +- Added in version 3.11.2. diff --git a/docs/mkdocs/docs/api/operator_gtgt.md b/docs/mkdocs/docs/api/operator_gtgt.md index 98d575add4..e76cc0db7f 100644 --- a/docs/mkdocs/docs/api/operator_gtgt.md +++ b/docs/mkdocs/docs/api/operator_gtgt.md @@ -21,8 +21,7 @@ the stream `i` ## Exceptions - Throws [`parse_error.101`](../home/exceptions.md#jsonexceptionparse_error101) in case of an unexpected token. -- Throws [`parse_error.102`](../home/exceptions.md#jsonexceptionparse_error102) if to_unicode fails or surrogate - error. +- Throws [`parse_error.102`](../home/exceptions.md#jsonexceptionparse_error102) if to_unicode fails or surrogate error. - Throws [`parse_error.103`](../home/exceptions.md#jsonexceptionparse_error103) if to_unicode fails. ## Complexity diff --git a/docs/mkdocs/docs/api/operator_literal_json.md b/docs/mkdocs/docs/api/operator_literal_json.md index 6775a3e1bc..cda00215c5 100644 --- a/docs/mkdocs/docs/api/operator_literal_json.md +++ b/docs/mkdocs/docs/api/operator_literal_json.md @@ -15,8 +15,9 @@ using namespace nlohmann::json_literals; using namespace nlohmann::literals::json_literals; using namespace nlohmann; ``` -This is suggested to ease migration to the next major version release of the library. -See ['JSON_USE_GLOBAL_UDLS`](macros/json_use_global_udls.md#notes) for details. + +This is suggested to ease migration to the next major version release of the library. See +['JSON_USE_GLOBAL_UDLS`](macros/json_use_global_udls.md#notes) for details. ## Parameters diff --git a/docs/mkdocs/docs/api/operator_literal_json_pointer.md b/docs/mkdocs/docs/api/operator_literal_json_pointer.md index 9b79697dc1..14d5378bcb 100644 --- a/docs/mkdocs/docs/api/operator_literal_json_pointer.md +++ b/docs/mkdocs/docs/api/operator_literal_json_pointer.md @@ -15,8 +15,8 @@ using namespace nlohmann::json_literals; using namespace nlohmann::literals::json_literals; using namespace nlohmann; ``` -This is suggested to ease migration to the next major version release of the library. -See ['JSON_USE_GLOBAL_UDLS`](macros/json_use_global_udls.md#notes) for details. +This is suggested to ease migration to the next major version release of the library. See +['JSON_USE_GLOBAL_UDLS`](macros/json_use_global_udls.md#notes) for details. ## Parameters diff --git a/docs/mkdocs/docs/api/operator_ltlt.md b/docs/mkdocs/docs/api/operator_ltlt.md index ea857718b7..1718b3c9e8 100644 --- a/docs/mkdocs/docs/api/operator_ltlt.md +++ b/docs/mkdocs/docs/api/operator_ltlt.md @@ -35,7 +35,8 @@ the stream `o` ## Exceptions 1. Throws [`type_error.316`](../home/exceptions.md#jsonexceptiontype_error316) if a string stored inside the JSON - value is not UTF-8 encoded. Note that unlike the [`dump`](basic_json/dump.md) member functions, no `error_handler` can be set. + value is not UTF-8 encoded. Note that unlike the [`dump`](basic_json/dump.md) member functions, no `error_handler` + can be set. 2. None. ## Complexity diff --git a/docs/mkdocs/docs/features/arbitrary_types.md b/docs/mkdocs/docs/features/arbitrary_types.md index 2d2e6f28bc..046a597a31 100644 --- a/docs/mkdocs/docs/features/arbitrary_types.md +++ b/docs/mkdocs/docs/features/arbitrary_types.md @@ -10,7 +10,7 @@ namespace ns { std::string address; int age; }; -} +} // namespace ns ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; diff --git a/docs/mkdocs/docs/features/binary_formats/bjdata.md b/docs/mkdocs/docs/features/binary_formats/bjdata.md index 74b4499e98..a89a228858 100644 --- a/docs/mkdocs/docs/features/binary_formats/bjdata.md +++ b/docs/mkdocs/docs/features/binary_formats/bjdata.md @@ -1,24 +1,21 @@ # BJData The [BJData format](https://neurojson.org) was derived from and improved upon -[Universal Binary JSON(UBJSON)](https://ubjson.org) specification (Draft 12). -Specifically, it introduces an optimized array container for efficient storage -of N-dimensional packed arrays (**ND-arrays**); it also adds 4 new type markers - -`[u] - uint16`, `[m] - uint32`, `[M] - uint64` and `[h] - float16` - to -unambigiously map common binary numeric types; furthermore, it uses little-endian -(LE) to store all numerics instead of big-endian (BE) as in UBJSON to avoid +[Universal Binary JSON(UBJSON)](https://ubjson.org) specification (Draft 12). Specifically, it introduces an optimized +array container for efficient storage of N-dimensional packed arrays (**ND-arrays**); it also adds 4 new type markers - +`[u] - uint16`, `[m] - uint32`, `[M] - uint64` and `[h] - float16` - to unambiguously map common binary numeric types; +furthermore, it uses little-endian (LE) to store all numerics instead of big-endian (BE) as in UBJSON to avoid unnecessary conversions on commonly available platforms. -Compared to other binary JSON-like formats such as MessagePack and CBOR, both BJData and -UBJSON demonstrate a rare combination of being both binary and **quasi-human-readable**. This -is because all semantic elements in BJData and UBJSON, including the data-type markers -and name/string types are directly human-readable. Data stored in the BJData/UBJSON format -are not only compact in size, fast to read/write, but also can be directly searched -or read using simple processing. +Compared to other binary JSON-like formats such as MessagePack and CBOR, both BJData and UBJSON demonstrate a rare +combination of being both binary and **quasi-human-readable**. This is because all semantic elements in BJData and +UBJSON, including the data-type markers and name/string types are directly human-readable. Data stored in the +BJData/UBJSON format are not only compact in size, fast to read/write, but also can be directly searched or read using +simple processing. !!! abstract "References" - - [BJData Specification](https://neurojson.org/bjdata/draft2) + - [BJData Specification](https://neurojson.org/bjdata/draft2) ## Serialization @@ -55,67 +52,59 @@ The library uses the following mapping from JSON values types to BJData types ac !!! success "Complete mapping" - The mapping is **complete** in the sense that any JSON value type can be converted to a BJData value. + The mapping is **complete** in the sense that any JSON value type can be converted to a BJData value. - Any BJData output created by `to_bjdata` can be successfully parsed by `from_bjdata`. + Any BJData output created by `to_bjdata` can be successfully parsed by `from_bjdata`. !!! warning "Size constraints" - The following values can **not** be converted to a BJData value: + The following values can **not** be converted to a BJData value: - strings with more than 18446744073709551615 bytes, i.e., $2^{64}-1$ bytes (theoretical) !!! info "Unused BJData markers" - The following markers are not used in the conversion: + The following markers are not used in the conversion: - `Z`: no-op values are not created. - `C`: single-byte strings are serialized with `S` markers. !!! info "NaN/infinity handling" - If NaN or Infinity are stored inside a JSON number, they are - serialized properly. This behavior differs from the `dump()` - function which serializes NaN or Infinity to `null`. - + If NaN or Infinity are stored inside a JSON number, they are serialized properly. This behavior differs from the + `dump()` function which serializes NaN or Infinity to `#!json null`. !!! info "Endianness" - A breaking difference between BJData and UBJSON is the endianness - of numerical values. In BJData, all numerical data types (integers - `UiuImlML` and floating-point values `hdD`) are stored in the little-endian (LE) - byte order as opposed to big-endian as used by UBJSON. Adopting LE - to store numeric records avoids unnecessary byte swapping on most modern - computers where LE is used as the default byte order. + A breaking difference between BJData and UBJSON is the endianness of numerical values. In BJData, all numerical data + types (integers `UiuImlML` and floating-point values `hdD`) are stored in the little-endian (LE) byte order as + opposed to big-endian as used by UBJSON. Adopting LE to store numeric records avoids unnecessary byte swapping on + most modern computers where LE is used as the default byte order. !!! info "Optimized formats" - Optimized formats for containers are supported via two parameters of + Optimized formats for containers are supported via two parameters of [`to_bjdata`](../../api/basic_json/to_bjdata.md): - - Parameter `use_size` adds size information to the beginning of a container and - removes the closing marker. - - Parameter `use_type` further checks whether all elements of a container have the - same type and adds the type marker to the beginning of the container. - The `use_type` parameter must only be used together with `use_size = true`. + - Parameter `use_size` adds size information to the beginning of a container and removes the closing marker. + - Parameter `use_type` further checks whether all elements of a container have the same type and adds the type + marker to the beginning of the container. The `use_type` parameter must only be used together with + `use_size = true`. - Note that `use_size = true` alone may result in larger representations - - the benefit of this parameter is that the receiving side is - immediately informed of the number of elements in the container. + Note that `use_size = true` alone may result in larger representations - the benefit of this parameter is that the + receiving side is immediately informed of the number of elements in the container. !!! info "ND-array optimized format" - BJData extends UBJSON's optimized array **size** marker to support ND-arrays of - uniform numerical data types (referred to as *packed arrays*). - For example, the 2-D `uint8` integer array `[[1,2],[3,4],[5,6]]`, stored - as nested optimized array in UBJSON `[ [$U#i2 1 2 [$U#i2 3 4 [$U#i2 5 6 ]`, - can be further compressed in BJData to `[$U#[$i#i2 2 3 1 2 3 4 5 6` - or `[$U#[i2 i3] 1 2 3 4 5 6`. + BJData extends UBJSON's optimized array **size** marker to support ND-arrays of uniform numerical data types + (referred to as *packed arrays*). For example, the 2-D `uint8` integer array `[[1,2],[3,4],[5,6]]`, stored as nested + optimized array in UBJSON `[ [$U#i2 1 2 [$U#i2 3 4 [$U#i2 5 6 ]`, can be further compressed in BJData to + `[$U#[$i#i2 2 3 1 2 3 4 5 6` or `[$U#[i2 i3] 1 2 3 4 5 6`. - To maintina type and size information, ND-arrays are converted to JSON objects following the - **annotated array format** (defined in the [JData specification (Draft 3)][JDataAAFmt]), - when parsed using [`from_bjdata`](../../api/basic_json/from_bjdata.md). - For example, the above 2-D `uint8` array can be parsed and accessed as + To maintain type and size information, ND-arrays are converted to JSON objects following the **annotated array + format** (defined in the [JData specification (Draft 3)][JDataAAFmt]), when parsed using + [`from_bjdata`](../../api/basic_json/from_bjdata.md). For example, the above 2-D `uint8` array can be parsed and + accessed as ```json { @@ -126,34 +115,28 @@ The library uses the following mapping from JSON values types to BJData types ac ``` Likewise, when a JSON object in the above form is serialzed using - [`to_bjdata`](../../api/basic_json/to_bjdata.md), it is automatically converted - into a compact BJData ND-array. The only exception is, that when the 1-dimensional - vector stored in `"_ArraySize_"` contains a single integer or two integers with one - being 1, a regular 1-D optimized array is generated. + [`to_bjdata`](../../api/basic_json/to_bjdata.md), it is automatically converted into a compact BJData ND-array. The + only exception is, that when the 1-dimensional vector stored in `"_ArraySize_"` contains a single integer or two + integers with one being 1, a regular 1-D optimized array is generated. - The current version of this library does not yet support automatic detection of and - conversion from a nested JSON array input to a BJData ND-array. + The current version of this library does not yet support automatic detection of and conversion from a nested JSON + array input to a BJData ND-array. [JDataAAFmt]: https://github.com/NeuroJSON/jdata/blob/master/JData_specification.md#annotated-storage-of-n-d-arrays) !!! info "Restrictions in optimized data types for arrays and objects" - Due to diminished space saving, hampered readability, and increased - security risks, in BJData, the allowed data types following the `$` marker - in an optimized array and object container are restricted to - **non-zero-fixed-length** data types. Therefore, the valid optimized - type markers can only be one of `UiuImlMLhdDC`. This also means other - variable (`[{SH`) or zero-length types (`TFN`) can not be used in an - optimized array or object in BJData. + Due to diminished space saving, hampered readability, and increased security risks, in BJData, the allowed data + types following the `$` marker in an optimized array and object container are restricted to + **non-zero-fixed-length** data types. Therefore, the valid optimized type markers can only be one of `UiuImlMLhdDC`. + This also means other variable (`[{SH`) or zero-length types (`TFN`) can not be used in an optimized array or object + in BJData. !!! info "Binary values" - If the JSON data contains the binary type, the value stored is a list - of integers, as suggested by the BJData documentation. In particular, - this means that the serialization and the deserialization of JSON - containing binary values into BJData and back will result in a - different JSON object. - + If the JSON data contains the binary type, the value stored is a list of integers, as suggested by the BJData + documentation. In particular, this means that the serialization and the deserialization of JSON containing binary + values into BJData and back will result in a different JSON object. ??? example @@ -196,8 +179,7 @@ The library maps BJData types to JSON value types as follows: !!! success "Complete mapping" - The mapping is **complete** in the sense that any BJData value can be converted to a JSON value. - + The mapping is **complete** in the sense that any BJData value can be converted to a JSON value. ??? example diff --git a/docs/mkdocs/docs/features/binary_formats/bson.md b/docs/mkdocs/docs/features/binary_formats/bson.md index 8c7716d9b6..f3b8cf18d0 100644 --- a/docs/mkdocs/docs/features/binary_formats/bson.md +++ b/docs/mkdocs/docs/features/binary_formats/bson.md @@ -6,8 +6,8 @@ representation of data types that are not part of the JSON spec. For example, BS !!! abstract "References" - - [BSON Website](http://bsonspec.org) - the main source on BSON - - [BSON Specification](http://bsonspec.org/spec.html) - the specification + - [BSON Website](http://bsonspec.org) - the main source on BSON + - [BSON Specification](http://bsonspec.org/spec.html) - the specification ## Serialization diff --git a/docs/mkdocs/docs/features/binary_formats/cbor.md b/docs/mkdocs/docs/features/binary_formats/cbor.md index 280bf577f4..2d0a1dae10 100644 --- a/docs/mkdocs/docs/features/binary_formats/cbor.md +++ b/docs/mkdocs/docs/features/binary_formats/cbor.md @@ -5,13 +5,14 @@ small code size, fairly small message size, and extensibility without the need f !!! abstract "References" - - [CBOR Website](http://cbor.io) - the main source on CBOR + - [CBOR Website](http://cbor.io) - the main source on CBOR - [CBOR Playground](http://cbor.me) - an interactive webpage to translate between JSON and CBOR - [RFC 7049](https://tools.ietf.org/html/rfc7049) - the CBOR specification ## Serialization -The library uses the following mapping from JSON values types to CBOR types according to the CBOR specification (RFC 7049): +The library uses the following mapping from JSON values types to CBOR types according to the CBOR specification +([RFC 7049](https://www.rfc-editor.org/rfc/rfc7049.html)): | JSON value type | value/range | CBOR type | first byte | |-----------------|--------------------------------------------|-----------------------------------|------------| @@ -61,15 +62,15 @@ see "binary" cells in the table above. !!! success "Complete mapping" - The mapping is **complete** in the sense that any JSON value type can be converted to a CBOR value. + The mapping is **complete** in the sense that any JSON value type can be converted to a CBOR value. !!! info "NaN/infinity handling" - If NaN or Infinity are stored inside a JSON number, they are serialized properly. This behavior differs from the normal JSON serialization which serializes NaN or Infinity to `null`. + If NaN or Infinity are stored inside a JSON number, they are serialized properly. This behavior differs from the normal JSON serialization which serializes NaN or Infinity to `null`. !!! info "Unused CBOR types" - The following CBOR types are not used in the conversion: + The following CBOR types are not used in the conversion: - UTF-8 strings terminated by "break" (0x7F) - arrays terminated by "break" (0x9F) @@ -149,7 +150,7 @@ The library maps CBOR types to JSON value types as follows: !!! warning "Incomplete mapping" - The mapping is **incomplete** in the sense that not all CBOR types can be converted to a JSON value. The following CBOR types are not supported and will yield parse errors: + The mapping is **incomplete** in the sense that not all CBOR types can be converted to a JSON value. The following CBOR types are not supported and will yield parse errors: - date/time (0xC0..0xC1) - bignum (0xC2..0xC3) @@ -161,7 +162,7 @@ The library maps CBOR types to JSON value types as follows: !!! warning "Object keys" - CBOR allows map keys of any type, whereas JSON only allows strings as keys in object values. Therefore, CBOR maps with keys other than UTF-8 strings are rejected. + CBOR allows map keys of any type, whereas JSON only allows strings as keys in object values. Therefore, CBOR maps with keys other than UTF-8 strings are rejected. !!! warning "Tagged items" diff --git a/docs/mkdocs/docs/features/binary_formats/messagepack.md b/docs/mkdocs/docs/features/binary_formats/messagepack.md index b0139b40c9..b2f69f174d 100644 --- a/docs/mkdocs/docs/features/binary_formats/messagepack.md +++ b/docs/mkdocs/docs/features/binary_formats/messagepack.md @@ -1,15 +1,18 @@ # MessagePack -MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves. +MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. +But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one +extra byte in addition to the strings themselves. !!! abstract "References" - - [MessagePack website](https://msgpack.org) - - [MessagePack specification](https://github.com/msgpack/msgpack/blob/master/spec.md) + - [MessagePack website](https://msgpack.org) + - [MessagePack specification](https://github.com/msgpack/msgpack/blob/master/spec.md) ## Serialization -The library uses the following mapping from JSON values types to MessagePack types according to the MessagePack specification: +The library uses the following mapping from JSON values types to MessagePack types according to the MessagePack +specification: | JSON value type | value/range | MessagePack type | first byte | |-----------------|------------------------------------------|------------------|------------| @@ -49,22 +52,23 @@ The library uses the following mapping from JSON values types to MessagePack typ !!! success "Complete mapping" - The mapping is **complete** in the sense that any JSON value type can be converted to a MessagePack value. + The mapping is **complete** in the sense that any JSON value type can be converted to a MessagePack value. - Any MessagePack output created by `to_msgpack` can be successfully parsed by `from_msgpack`. + Any MessagePack output created by `to_msgpack` can be successfully parsed by `from_msgpack`. !!! warning "Size constraints" - The following values can **not** be converted to a MessagePack value: + The following values can **not** be converted to a MessagePack value: - - strings with more than 4294967295 bytes - - byte strings with more than 4294967295 bytes - - arrays with more than 4294967295 elements - - objects with more than 4294967295 elements + - strings with more than 4294967295 bytes + - byte strings with more than 4294967295 bytes + - arrays with more than 4294967295 elements + - objects with more than 4294967295 elements !!! info "NaN/infinity handling" - If NaN or Infinity are stored inside a JSON number, they are serialized properly. function which serializes NaN or Infinity to `null`. + If NaN or Infinity are stored inside a JSON number, they are serialized properly in contrast to the + [dump](../../api/basic_json/dump.md) function which serializes NaN or Infinity to `null`. ??? example @@ -123,7 +127,7 @@ The library maps MessagePack types to JSON value types as follows: !!! info - Any MessagePack output created by `to_msgpack` can be successfully parsed by `from_msgpack`. + Any MessagePack output created by `to_msgpack` can be successfully parsed by `from_msgpack`. ??? example diff --git a/docs/mkdocs/docs/features/binary_formats/ubjson.md b/docs/mkdocs/docs/features/binary_formats/ubjson.md index 509d9f577b..76956d60a7 100644 --- a/docs/mkdocs/docs/features/binary_formats/ubjson.md +++ b/docs/mkdocs/docs/features/binary_formats/ubjson.md @@ -1,10 +1,11 @@ # UBJSON -Universal Binary JSON (UBJSON) is a binary form directly imitating JSON, but requiring fewer bytes of data. It aims to achieve the generality of JSON, combined with being much easier to process than JSON. +Universal Binary JSON (UBJSON) is a binary form directly imitating JSON, but requiring fewer bytes of data. It aims to +achieve the generality of JSON, combined with being much easier to process than JSON. !!! abstract "References" - - [UBJSON Website](http://ubjson.org) + - [UBJSON Website](http://ubjson.org) ## Serialization @@ -36,50 +37,43 @@ The library uses the following mapping from JSON values types to UBJSON types ac !!! success "Complete mapping" - The mapping is **complete** in the sense that any JSON value type can be converted to a UBJSON value. + The mapping is **complete** in the sense that any JSON value type can be converted to a UBJSON value. - Any UBJSON output created by `to_ubjson` can be successfully parsed by `from_ubjson`. + Any UBJSON output created by `to_ubjson` can be successfully parsed by `from_ubjson`. !!! warning "Size constraints" - The following values can **not** be converted to a UBJSON value: + The following values can **not** be converted to a UBJSON value: - strings with more than 9223372036854775807 bytes (theoretical) !!! info "Unused UBJSON markers" - The following markers are not used in the conversion: + The following markers are not used in the conversion: - `Z`: no-op values are not created. - `C`: single-byte strings are serialized with `S` markers. !!! info "NaN/infinity handling" - If NaN or Infinity are stored inside a JSON number, they are - serialized properly. This behavior differs from the `dump()` - function which serializes NaN or Infinity to `null`. + If NaN or Infinity are stored inside a JSON number, they are serialized properly. This behavior differs from the + `dump()` function which serializes NaN or Infinity to `null`. !!! info "Optimized formats" - The optimized formats for containers are supported: Parameter - `use_size` adds size information to the beginning of a container and - removes the closing marker. Parameter `use_type` further checks - whether all elements of a container have the same type and adds the - type marker to the beginning of the container. The `use_type` - parameter must only be used together with `use_size = true`. + The optimized formats for containers are supported: Parameter `use_size` adds size information to the beginning of a + container and removes the closing marker. Parameter `use_type` further checks whether all elements of a container + have the same type and adds the type marker to the beginning of the container. The `use_type` parameter must only be + used together with `use_size = true`. - Note that `use_size = true` alone may result in larger representations - - the benefit of this parameter is that the receiving side is - immediately informed on the number of elements of the container. + Note that `use_size = true` alone may result in larger representations - the benefit of this parameter is that the + receiving side is immediately informed on the number of elements of the container. !!! info "Binary values" - If the JSON data contains the binary type, the value stored is a list - of integers, as suggested by the UBJSON documentation. In particular, - this means that serialization and the deserialization of a JSON - containing binary values into UBJSON and back will result in a - different JSON object. - + If the JSON data contains the binary type, the value stored is a list of integers, as suggested by the UBJSON + documentation. In particular, this means that serialization and the deserialization of a JSON containing binary + values into UBJSON and back will result in a different JSON object. ??? example @@ -117,8 +111,7 @@ The library maps UBJSON types to JSON value types as follows: !!! success "Complete mapping" - The mapping is **complete** in the sense that any UBJSON value can be converted to a JSON value. - + The mapping is **complete** in the sense that any UBJSON value can be converted to a JSON value. ??? example diff --git a/docs/mkdocs/docs/features/comments.md b/docs/mkdocs/docs/features/comments.md index c5874c9f18..61266d9caf 100644 --- a/docs/mkdocs/docs/features/comments.md +++ b/docs/mkdocs/docs/features/comments.md @@ -5,9 +5,9 @@ This library does not support comments *by default*. It does so for three reason 1. Comments are not part of the [JSON specification](https://tools.ietf.org/html/rfc8259). You may argue that `//` or `/* */` are allowed in JavaScript, but JSON is not JavaScript. 2. This was not an oversight: Douglas Crockford [wrote on this](https://plus.google.com/118095276221607585885/posts/RK8qyGVaGSr) in May 2012: - > I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability. I know that the lack of comments makes some people sad, but it shouldn't. + > I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability. I know that the lack of comments makes some people sad, but it shouldn't. - > Suppose you are using JSON to keep configuration files, which you would like to annotate. Go ahead and insert all the comments you like. Then pipe it through JSMin before handing it to your JSON parser. + > Suppose you are using JSON to keep configuration files, which you would like to annotate. Go ahead and insert all the comments you like. Then pipe it through JSMin before handing it to your JSON parser. 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. diff --git a/docs/mkdocs/docs/features/element_access/unchecked_access.md b/docs/mkdocs/docs/features/element_access/unchecked_access.md index 1bdea94e70..39f06dc9f2 100644 --- a/docs/mkdocs/docs/features/element_access/unchecked_access.md +++ b/docs/mkdocs/docs/features/element_access/unchecked_access.md @@ -99,7 +99,8 @@ that the passed index is the new maximal index. Intermediate values are filled w !!! failure "Exceptions" - `operator[]` can only be used with objects (with a string argument) or with arrays (with a numeric argument). For other types, a [`basic_json::type_error`](../../home/exceptions.md#jsonexceptiontype_error305) is thrown. + `operator[]` can only be used with objects (with a string argument) or with arrays (with a numeric argument). For + other types, a [`basic_json::type_error`](../../home/exceptions.md#jsonexceptiontype_error305) is thrown. ## Summary diff --git a/docs/mkdocs/docs/features/json_pointer.md b/docs/mkdocs/docs/features/json_pointer.md index a3980b4c6c..04aeca504d 100644 --- a/docs/mkdocs/docs/features/json_pointer.md +++ b/docs/mkdocs/docs/features/json_pointer.md @@ -3,7 +3,7 @@ ## Introduction The library supports **JSON Pointer** ([RFC 6901](https://tools.ietf.org/html/rfc6901)) as alternative means to address -structured values. A JSON Pointer is a string that identifies a specific value withing a JSON document. +structured values. A JSON Pointer is a string that identifies a specific value within a JSON document. Consider the following JSON document diff --git a/docs/mkdocs/docs/features/namespace.md b/docs/mkdocs/docs/features/namespace.md new file mode 100644 index 0000000000..8cee2ccfe7 --- /dev/null +++ b/docs/mkdocs/docs/features/namespace.md @@ -0,0 +1,93 @@ +# `nlohmann` Namespace + +The 3.11.0 release introduced an +[inline namespace](https://en.cppreference.com/w/cpp/language/namespace#Inline_namespaces) to allow different parts of +a codebase to safely use different versions of the JSON library as long as they never exchange instances of library +types. + +## Structure + +The complete default namespace name is derived as follows: + +- The root namespace is always `nlohmann`. +- The inline namespace starts with `json_abi` and is followed by serveral optional ABI tags according to the value of + these ABI-affecting macros, in order: + - [`JSON_DIAGNOSTICS`](../api/macros/json_diagnostics.md) defined non-zero appends `_diag`. + - [`JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON`](../api/macros/json_use_legacy_discarded_value_comparison.md) + defined non-zero appends `_ldvcmp`. +- The inline namespace ends with the suffix `_v` followed by the 3 components of the version number separated by + underscores. To omit the version component, see [Disabling the version component](#disabling-the-version-component) + below. + +For example, the namespace name for version 3.11.2 with `JSON_DIAGNOSTICS` defined to `1` is: + +```cpp +nlohmann::json_abi_diag_v3_11_2 +``` + +## Purpose + +Several incompatibilities have been observed. Amongst the most common ones is linking code compiled with different +definitions of [`JSON_DIAGNOSTICS`](../api/macros/json_diagnostics.md). This is illustrated in the diagram below. + +```plantuml +[**nlohmann_json (v3.10.5)**\nJSON_DIAGNOSTICS=0] as [json] +[**nlohmann_json (v3.10.5)**\nJSON_DIAGNOSTICS=1] as [json_diag] +[**some_library**] as [library] +[**application**] as [app] + +[library] ..|> [json] +[app] ..|> [json_diag] +[app] ..|>[library] +``` + +In releases prior to 3.11.0, mixing any version of the JSON library with different `JSON_DIAGNOSTICS` settings would +result in a crashing application. If `some_library` never passes instances of JSON library types to the application, +this scenario became safe in version 3.11.0 and above due to the inline namespace yielding distinct symbol names. + +## Limitations + +Neither the compiler nor the linker will issue as much as a warning when translation units – intended to be linked +together and that include different versions and/or configurations of the JSON library – exchange and use library +types. + +There is an exception when forward declarations are used (i.e., when including `json_fwd.hpp`) in which case the linker +may complain about undefined references. + +## Disabling the version component + +Different versions are not necessarily ABI-incompatible, but the project does not actively track changes in the ABI and +recommends that all parts of a codebase exchanging library types be built with the same version. Users can, **at their +own risk**, disable the version component of the linline namespace, allowing different versions – but not +configurations – to be used in cases where the linker would otherwise output undefined reference errors. + +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 +section to emulate the effect of the `NLOHMANN_JSON_NAMESPACE_NO_VERSION` macro. + +!!! danger "Use at your own risk" + + Disabling the namespace version component and mixing ABI-incompatible versions will result in crashes or incorrect + behavior. You have been warned! +## Disabling the inline namespace completely + +When interoperability with code using a pre-3.11.0 version of the library is required, users can, **at their own risk** +restore the old namespace layout by redefining +[`NLOHMANN_JSON_NAMESPACE_BEGIN, NLOHMANN_JSON_NAMESPACE_END`](../api/macros/nlohmann_json_namespace_begin.md) as +follows: + +```cpp +#define NLOHMANN_JSON_NAMESPACE_BEGIN namespace nlohmann { +#define NLOHMANN_JSON_NAMESPACE_END } +``` + +!!! danger "Use at your own risk" + + Overriding the namespace and mixing ABI-incompatible versions will result in crashes or incorrect behavior. You + have been warned! + +## Version history + +- Introduced inline namespace (`json_v3_11_0[_abi-tag]*`) in version 3.11.0. +- Changed structure of inline namespace in version 3.11.2. diff --git a/docs/mkdocs/docs/features/parsing/parse_exceptions.md b/docs/mkdocs/docs/features/parsing/parse_exceptions.md index 879dab0d32..61c0ff2902 100644 --- a/docs/mkdocs/docs/features/parsing/parse_exceptions.md +++ b/docs/mkdocs/docs/features/parsing/parse_exceptions.md @@ -1,6 +1,10 @@ # Parsing and Exceptions -When the input is not valid JSON, an exception of type [`parse_error`](../../home/exceptions.md#parse-errors) is thrown. This exception contains the position in the input where the error occurred, together with a diagnostic message and the last read input token. The exceptions page contains a [list of examples for parse error exceptions](../../home/exceptions.md#parse-errors). In case you process untrusted input, always enclose your code with a `#!cpp try`/`#!cpp catch` block, like +When the input is not valid JSON, an exception of type [`parse_error`](../../home/exceptions.md#parse-errors) is thrown. +This exception contains the position in the input where the error occurred, together with a diagnostic message and the +last read input token. The exceptions page contains a +[list of examples for parse error exceptions](../../home/exceptions.md#parse-errors). In case you process untrusted +input, always enclose your code with a `#!cpp try`/`#!cpp catch` block, like ```cpp json j; @@ -19,7 +23,9 @@ In case exceptions are undesired or not supported by the environment, there are ## Switch off exceptions -The `parse()` function accepts as last parameter a `#!cpp bool` variable `allow_exceptions` which controls whether an exception is thrown when a parse error occurs (`#!cpp true`, default) or whether a discarded value should be returned (`#!cpp false`). +The `parse()` function accepts a `#!cpp bool` parameter `allow_exceptions` which controls whether an exception is +thrown when a parse error occurs (`#!cpp true`, default) or whether a discarded value should be returned +(`#!cpp false`). ```cpp json j = json::parse(my_input, nullptr, false); @@ -33,7 +39,8 @@ Note there is no diagnostic information available in this scenario. ## Use accept() function -Alternatively, function `accept()` can be used which does not return a `json` value, but a `#!cpp bool` indicating whether the input is valid JSON. +Alternatively, function `accept()` can be used which does not return a `json` value, but a `#!cpp bool` indicating +whether the input is valid JSON. ```cpp if (!json::accept(my_input)) diff --git a/docs/mkdocs/docs/features/parsing/parser_callbacks.md b/docs/mkdocs/docs/features/parsing/parser_callbacks.md index 12136f57c7..ef076d126c 100644 --- a/docs/mkdocs/docs/features/parsing/parser_callbacks.md +++ b/docs/mkdocs/docs/features/parsing/parser_callbacks.md @@ -2,9 +2,10 @@ ## Overview -With a parser callback function, the result of parsing a JSON text can be influenced. When passed to `parse`, it is called on certain events -(passed as `parse_event_t` via parameter `event`) with a set recursion depth `depth` and context JSON value `parsed`. The return value of the -callback function is a boolean indicating whether the element that emitted the callback shall be kept or not. +With a parser callback function, the result of parsing a JSON text can be influenced. When passed to `parse`, it is +called on certain events (passed as `parse_event_t` via parameter `event`) with a set recursion depth `depth` and +context JSON value `parsed`. The return value of the callback function is a boolean indicating whether the element that +emitted the callback shall be kept or not. The type of the callback function is: @@ -17,8 +18,8 @@ using parser_callback_t = ## Callback event types -We distinguish six scenarios (determined by the event type) in which the callback function can be called. The following table describes the values -of the parameters `depth`, `event`, and `parsed`. +We distinguish six scenarios (determined by the event type) in which the callback function can be called. The following +table describes the values of the parameters `depth`, `event`, and `parsed`. | parameter `event` | description | parameter `depth` | parameter `parsed` | |-------------------------------|-----------------------------------------------------------|-------------------------------------------|----------------------------------| @@ -59,10 +60,13 @@ of the parameters `depth`, `event`, and `parsed`. ## Return value -Discarding a value (i.e., returning `#!c false`) has different effects depending on the context in which function was called: +Discarding a value (i.e., returning `#!c false`) has different effects depending on the context in which the function +was called: -- Discarded values in structured types are skipped. That is, the parser will behave as if the discarded value was never read. -- In case a value outside a structured type is skipped, it is replaced with `#!json null`. This case happens if the top-level element is skipped. +- Discarded values in structured types are skipped. That is, the parser will behave as if the discarded value was never + read. +- In case a value outside a structured type is skipped, it is replaced with `#!json null`. This case happens if the + top-level element is skipped. ??? example diff --git a/docs/mkdocs/docs/home/faq.md b/docs/mkdocs/docs/home/faq.md index 878b8a64e3..dd426e073f 100644 --- a/docs/mkdocs/docs/home/faq.md +++ b/docs/mkdocs/docs/home/faq.md @@ -44,7 +44,7 @@ for objects. !!! question - Can you add an option to ignore trailing commas? + Can you add an option to ignore trailing commas? This library does not support any feature which would jeopardize interoperability. @@ -53,9 +53,9 @@ This library does not support any feature which would jeopardize interoperabilit !!! question "Questions" - - Why is the parser complaining about a Chinese character? - - Does the library support Unicode? - - I get an exception `[json.exception.parse_error.101] parse error at line 1, column 53: syntax error while parsing value - invalid string: ill-formed UTF-8 byte; last read: '"Testé$')"` + - Why is the parser complaining about a Chinese character? + - Does the library support Unicode? + - I get an exception `[json.exception.parse_error.101] parse error at line 1, column 53: syntax error while parsing value - invalid string: ill-formed UTF-8 byte; last read: '"Testé$')"` The library supports **Unicode input** as follows: @@ -124,7 +124,7 @@ Yes, see [Parsing and exceptions](../features/parsing/parse_exceptions.md). !!! question - Can I get the key of the object item that caused an exception? + Can I get the key of the object item that caused an exception? Yes, you can. Please define the symbol [`JSON_DIAGNOSTICS`](../api/macros/json_diagnostics.md) to get [extended diagnostics messages](exceptions.md#extended-diagnostic-messages). @@ -136,18 +136,18 @@ Yes, you can. Please define the symbol [`JSON_DIAGNOSTICS`](../api/macros/json_d !!! question - - It seems that precision is lost when serializing a double. - - Can I change the precision for floating-point serialization? + - It seems that precision is lost when serializing a double. + - Can I change the precision for floating-point serialization? The library uses `std::numeric_limits::digits10` (15 for IEEE `double`s) digits for serialization. This value is sufficient to guarantee roundtripping. If one uses more than this number of digits of precision, then string -> value -> string is not guaranteed to round-trip. !!! quote "[cppreference.com](https://en.cppreference.com/w/cpp/types/numeric_limits/digits10)" - The value of `std::numeric_limits::digits10` is the number of base-10 digits that can be represented by the type T without change, that is, any number with this many significant decimal digits can be converted to a value of type T and back to decimal form, without change due to rounding or overflow. + The value of `std::numeric_limits::digits10` is the number of base-10 digits that can be represented by the type T without change, that is, any number with this many significant decimal digits can be converted to a value of type T and back to decimal form, without change due to rounding or overflow. !!! tip - The website https://float.exposed gives a good insight into the internal storage of floating-point numbers. + The website https://float.exposed gives a good insight into the internal storage of floating-point numbers. See [this section](../features/types/number_handling.md#number-serialization) on the library's number handling for more information. @@ -157,7 +157,7 @@ See [this section](../features/types/number_handling.md#number-serialization) on !!! question - Why does the code not compile with Android SDK? + Why does the code not compile with Android SDK? Android defaults to using very old compilers and C++ libraries. To fix this, add the following to your `Application.mk`. This will switch to the LLVM C++ library, the Clang compiler, and enable C++11 and other features disabled by default. @@ -174,7 +174,7 @@ The code compiles successfully with [Android NDK](https://developer.android.com/ !!! question "Questions" - - Why do I get a compilation error `'to_string' is not a member of 'std'` (or similarly, for `strtod` or `strtof`)? - - Why does the code not compile with MinGW or Android SDK? + - Why do I get a compilation error `'to_string' is not a member of 'std'` (or similarly, for `strtod` or `strtof`)? + - Why does the code not compile with MinGW or Android SDK? 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](http://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). diff --git a/docs/mkdocs/docs/home/releases.md b/docs/mkdocs/docs/home/releases.md index 2cf5b3c66c..5237c42592 100644 --- a/docs/mkdocs/docs/home/releases.md +++ b/docs/mkdocs/docs/home/releases.md @@ -252,18 +252,18 @@ http://nlohmann.github.io/json/doxygen/classnlohmann_1_1basic__json_a0a45fc74063 - Fixed documentation of parse function. #1473 - Suppressed warning that cannot be fixed inside the library. #1401 #1468 - Imroved package manager suppert: - - Updated Buckaroo instructions. #1495 - - Improved Meson support. #1463 - - Added Conda package manager documentation. #1430 - - Added NuGet package manager documentation. #1132 + - Updated Buckaroo instructions. #1495 + - Improved Meson support. #1463 + - Added Conda package manager documentation. #1430 + - Added NuGet package manager documentation. #1132 - Continuous Integration - - Removed unstable or deprecated Travis builders (Xcode 6.4 - 8.2) and added Xcode 10.1 builder. - - Added Clang 7 to Travis CI. - - Fixed AppVeyor x64 builds. #1374 #1414 + - Removed unstable or deprecated Travis builders (Xcode 6.4 - 8.2) and added Xcode 10.1 builder. + - Added Clang 7 to Travis CI. + - Fixed AppVeyor x64 builds. #1374 #1414 - Updated thirdparty libraries: - - Catch 1.12.0 -> 1.12.2 - - Google Benchmark 1.3.0 -> 1.4.1 - - Doxygen 1.8.15 -> 1.8.16 + - Catch 1.12.0 -> 1.12.2 + - Google Benchmark 1.3.0 -> 1.4.1 + - Doxygen 1.8.15 -> 1.8.16 ### :fire: Deprecated functions diff --git a/docs/mkdocs/docs/integration/cmake.md b/docs/mkdocs/docs/integration/cmake.md index 831e35ab93..c8f9883ea5 100644 --- a/docs/mkdocs/docs/integration/cmake.md +++ b/docs/mkdocs/docs/integration/cmake.md @@ -18,7 +18,7 @@ and use the namespaced imported target from the generated package configuration: cmake_minimum_required(VERSION 3.1) project(ExampleProject LANGUAGES CXX) - find_package(nlohmann_json 3.11.1 REQUIRED) + find_package(nlohmann_json 3.11.2 REQUIRED) add_executable(example example.cpp) target_link_libraries(example PRIVATE nlohmann_json::nlohmann_json) @@ -77,7 +77,7 @@ to the following. ```cmake title="thirdparty/CMakeLists.txt" if(EXAMPLE_USE_EXTERNAL_JSON) - find_package(nlohmann_json 3.11.1 REQUIRED) + find_package(nlohmann_json 3.11.2 REQUIRED) else() set(JSON_BuildTests OFF CACHE INTERNAL "") add_subdirectory(nlohmann_json) @@ -100,7 +100,7 @@ automatically download a release as a dependency at configure type. include(FetchContent) - FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.1/json.tar.xz) + FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz) FetchContent_MakeAvailable(json) add_executable(example example.cpp) @@ -115,11 +115,11 @@ automatically download a release as a dependency at configure type. ```cmake FetchContent_Declare(json GIT_REPOSITORY https://github.com/nlohmann/json - GIT_TAG v3.11.1 + GIT_TAG v3.11.2 ) ``` - However, the repository download size is quite large. You might want to depend on + However, the repository download size is quite large. You might want to depend on a smaller repository. For instance, you might want to replace the URL in the example by . diff --git a/docs/mkdocs/docs/integration/index.md b/docs/mkdocs/docs/integration/index.md index bfa94ae8a2..2bbaa86041 100644 --- a/docs/mkdocs/docs/integration/index.md +++ b/docs/mkdocs/docs/integration/index.md @@ -13,6 +13,6 @@ 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 +[`single_include/nlohmann/json_fwd.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json_fwd.hpp) +for forward declarations. diff --git a/docs/mkdocs/docs/integration/package_managers.md b/docs/mkdocs/docs/integration/package_managers.md index c2fb1a7f40..b9ebf075f1 100644 --- a/docs/mkdocs/docs/integration/package_managers.md +++ b/docs/mkdocs/docs/integration/package_managers.md @@ -30,29 +30,29 @@ instead. See [nlohmann-json](https://formulae.brew.sh/formula/nlohmann-json) for ??? example - 1. Create the following file: + 1. Create the following file: ```cpp title="example.cpp" --8<-- "integration/example.cpp" ``` - 2. Install the package + 2. Install the package - ```sh - brew install nlohmann-json - ``` + ```sh + brew install nlohmann-json + ``` - 3. Determine the include path, which defaults to `/usr/local/Cellar/nlohmann-json/$version/include`, where `$version` is the version of the library, e.g. `3.7.3`. The path of the library can be determined with + 3. Determine the include path, which defaults to `/usr/local/Cellar/nlohmann-json/$version/include`, where `$version` is the version of the library, e.g. `3.7.3`. The path of the library can be determined with - ```sh - brew list nlohmann-json - ``` + ```sh + brew list nlohmann-json + ``` - 4. Compile the code. For instance, the code can be compiled using Clang with + 4. Compile the code. For instance, the code can be compiled using Clang with - ```sh - clang++ example.cpp -I/usr/local/Cellar/nlohmann-json/3.7.3/include -std=c++11 -o example - ``` + ```sh + clang++ example.cpp -I/usr/local/Cellar/nlohmann-json/3.7.3/include -std=c++11 -o example + ``` :material-update: The [formula](https://formulae.brew.sh/formula/nlohmann-json) is updated automatically. @@ -68,7 +68,7 @@ If you are using [Conan](https://www.conan.io/) to manage your dependencies, mer ??? example - 1. Create the following files: + 1. Create the following files: ```ini title="Conanfile.txt" --8<-- "integration/conan/Conanfile.txt" @@ -82,15 +82,15 @@ If you are using [Conan](https://www.conan.io/) to manage your dependencies, mer --8<-- "integration/conan/example.cpp" ``` - 2. Build: + 2. Build: - ```sh - mkdir build - cd build - conan install .. - cmake .. - cmake --build . - ``` + ```sh + mkdir build + cd build + conan install .. + cmake .. + cmake --build . + ``` :material-update: The [package](https://conan.io/center/nlohmann_json) is updated automatically. @@ -112,7 +112,7 @@ If you are using [vcpkg](https://github.com/Microsoft/vcpkg/) on your project fo ??? example - 1. Create the following files: + 1. Create the following files: ```cmake title="CMakeLists.txt" --8<-- "integration/vcpkg/CMakeLists.txt" @@ -128,14 +128,14 @@ If you are using [vcpkg](https://github.com/Microsoft/vcpkg/) on your project fo vcpkg install nlohmann-json ``` - 3. Build: + 3. Build: - ```sh - mkdir build - cd build - cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake - cmake --build . - ``` + ```sh + mkdir build + cd build + cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake + cmake --build . + ``` Note you need to adjust `/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake` to your system. diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index 65182adbf4..545584a922 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -58,6 +58,7 @@ nav: - features/json_pointer.md - features/json_patch.md - features/merge_patch.md + - 'nlohmann Namespace': features/namespace.md - features/object_order.md - Parsing: - features/parsing/index.md @@ -209,6 +210,8 @@ nav: - '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 @@ -268,6 +271,7 @@ nav: - 'NLOHMANN_JSON_NAMESPACE': api/macros/nlohmann_json_namespace.md - 'NLOHMANN_JSON_NAMESPACE_BEGIN': api/macros/nlohmann_json_namespace_begin.md - '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': api/macros/nlohmann_json_version_major.md - 'NLOHMANN_JSON_VERSION_MINOR': api/macros/nlohmann_json_version_major.md diff --git a/docs/mkdocs/requirements.txt b/docs/mkdocs/requirements.txt index 51fceb5d3d..c1b232cf93 100644 --- a/docs/mkdocs/requirements.txt +++ b/docs/mkdocs/requirements.txt @@ -1,49 +1,49 @@ -Babel==2.10.1 -certifi==2021.10.8 -charset-normalizer==2.0.12 -click==8.1.2 +Babel==2.10.3 +certifi==2022.6.15 +charset-normalizer==2.1.0 +click==8.1.3 csscompressor==0.9.5 future==0.18.2 -ghp-import==2.0.2 +ghp-import==2.1.0 gitdb==4.0.9 GitPython==3.1.27 htmlmin==0.1.12 httplib2==0.20.4 idna==3.3 -importlib-metadata==4.11.3 -Jinja2==3.1.1 +importlib-metadata==4.12.0 +Jinja2==3.1.2 joblib==1.1.0 jsmin==3.0.1 livereload==2.6.3 lunr==0.6.2 -Markdown==3.3.6 -markdown-include==0.6.0 +Markdown==3.3.0 # pinned due to version conflict with markdown-include and mkdocs +markdown-include==0.7.0 MarkupSafe==2.1.1 mergedeep==1.3.4 -mkdocs==1.3.0 -mkdocs-git-revision-date-localized-plugin==1.0.1 -mkdocs-material==8.2.10 +mkdocs==1.3.1 +mkdocs-git-revision-date-localized-plugin==1.1.0 +mkdocs-material==8.3.9 mkdocs-material-extensions==1.0.3 mkdocs-minify-plugin==0.5.0 -mkdocs-redirects==1.0.4 +mkdocs-redirects==1.0.5 mkdocs-simple-hooks==0.1.5 nltk==3.7 packaging==21.3 plantuml==0.3.0 -plantuml-markdown==3.5.2 -Pygments==2.11.0 -pymdown-extensions==9.3 -pyparsing==3.0.8 +plantuml-markdown==3.6.3 +Pygments==2.12.0 +pymdown-extensions==9.5 +pyparsing==3.0.9 python-dateutil==2.8.2 pytz==2022.1 PyYAML==6.0 pyyaml_env_tag==0.1 -regex==2022.4.24 -requests==2.27.1 +regex==2022.7.25 +requests==2.28.1 six==1.16.0 smmap==5.0.0 -tornado==6.1 +tornado==6.2 tqdm==4.64.0 -urllib3==1.26.9 -watchdog==2.1.7 -zipp==3.8.0 +urllib3==1.26.11 +watchdog==2.1.9 +zipp==3.8.1 diff --git a/docs/mkdocs/scripts/check_structure.py b/docs/mkdocs/scripts/check_structure.py index 37c4ce3567..643482af24 100755 --- a/docs/mkdocs/scripts/check_structure.py +++ b/docs/mkdocs/scripts/check_structure.py @@ -3,6 +3,7 @@ import glob import os.path import re +import sys warnings = 0 @@ -75,6 +76,12 @@ def check_structure(): if len(line) > 160 and '|' not in line: report('whitespace/line_length', f'{file}:{lineno+1} ({current_section})', f'line is too long ({len(line)} vs. 160 chars)') + # sections in `` comments are treated as present + if line.startswith('') + existing_sections.append(current_section) + # check if sections are correct if line.startswith('## '): # before starting a new section, check if the previous one documented all overloads @@ -167,3 +174,6 @@ def check_examples(): check_structure() check_examples() print(120 * '-') + + if warnings > 0: + sys.exit(1) diff --git a/include/nlohmann/adl_serializer.hpp b/include/nlohmann/adl_serializer.hpp index 1f3f20b6b2..f77f94473e 100644 --- a/include/nlohmann/adl_serializer.hpp +++ b/include/nlohmann/adl_serializer.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/byte_container_with_subtype.hpp b/include/nlohmann/byte_container_with_subtype.hpp index 401063806d..1031cdcfea 100644 --- a/include/nlohmann/byte_container_with_subtype.hpp +++ b/include/nlohmann/byte_container_with_subtype.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/abi_macros.hpp b/include/nlohmann/detail/abi_macros.hpp index dac3c58e62..0d3108d166 100644 --- a/include/nlohmann/detail/abi_macros.hpp +++ b/include/nlohmann/detail/abi_macros.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -12,7 +12,7 @@ #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) - #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 1 + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 2 #warning "Already included a different version of the library!" #endif #endif @@ -20,7 +20,7 @@ #define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) #define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) -#define NLOHMANN_JSON_VERSION_PATCH 1 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_PATCH 2 // NOLINT(modernize-macro-to-enum) #ifndef JSON_DIAGNOSTICS #define JSON_DIAGNOSTICS 0 @@ -42,38 +42,59 @@ #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON #endif -#define NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) \ - json_v ## major ## _ ## minor ## _ ## patch -#define NLOHMANN_JSON_ABI_PREFIX(major, minor, patch) \ - NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) - -#define NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) a ## b ## c -#define NLOHMANN_JSON_ABI_CONCAT(a, b, c) \ - NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) - -#define NLOHMANN_JSON_ABI_STRING \ - NLOHMANN_JSON_ABI_CONCAT( \ - NLOHMANN_JSON_ABI_PREFIX( \ - NLOHMANN_JSON_VERSION_MAJOR, \ - NLOHMANN_JSON_VERSION_MINOR, \ - NLOHMANN_JSON_VERSION_PATCH), \ - NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ +#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION + #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 +#endif + +// Construct the namespace ABI tags component +#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b +#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ + NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) + +#define NLOHMANN_JSON_ABI_TAGS \ + NLOHMANN_JSON_ABI_TAGS_CONCAT( \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) +// Construct the namespace version component +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ + _v ## major ## _ ## minor ## _ ## patch +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) + +#if NLOHMANN_JSON_NAMESPACE_NO_VERSION +#define NLOHMANN_JSON_NAMESPACE_VERSION +#else +#define NLOHMANN_JSON_NAMESPACE_VERSION \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH) +#endif + +// Combine namespace components +#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b +#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ + NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) + #ifndef NLOHMANN_JSON_NAMESPACE - #define NLOHMANN_JSON_NAMESPACE nlohmann::NLOHMANN_JSON_ABI_STRING +#define NLOHMANN_JSON_NAMESPACE \ + nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) #endif #ifndef NLOHMANN_JSON_NAMESPACE_BEGIN -#define NLOHMANN_JSON_NAMESPACE_BEGIN \ - namespace nlohmann \ - { \ - inline namespace NLOHMANN_JSON_ABI_STRING \ +#define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann \ + { \ + inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) \ { #endif #ifndef NLOHMANN_JSON_NAMESPACE_END -#define NLOHMANN_JSON_NAMESPACE_END \ - } /* namespace (abi_string) */ \ - } /* namespace nlohmann */ +#define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ + } // namespace nlohmann #endif diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index a72ae1744b..c6299aa0b2 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index 5f01e6c76e..febef93271 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2009 Florian Loitsch diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index ba24c118d0..b33d726b48 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -267,9 +267,15 @@ inline void to_json(BasicJsonType& j, T b) noexcept external_constructor::construct(j, b); } -template::reference&, typename BasicJsonType::boolean_t>::value, int> = 0> -inline void to_json(BasicJsonType& j, const std::vector::reference& b) noexcept +template < typename BasicJsonType, typename BoolRef, + enable_if_t < + ((std::is_same::reference, BoolRef>::value + && !std::is_same ::reference, typename BasicJsonType::boolean_t&>::value) + || (std::is_same::const_reference, BoolRef>::value + && !std::is_same ::const_reference>, + typename BasicJsonType::boolean_t >::value)) + && std::is_convertible::value, int > = 0 > +inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept { external_constructor::construct(j, static_cast(b)); } diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index 3a7af6adf3..96d7e01040 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/hash.hpp b/include/nlohmann/detail/hash.hpp index 2f57badc25..3f05af8308 100644 --- a/include/nlohmann/detail/hash.hpp +++ b/include/nlohmann/detail/hash.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index f4134efdc4..634615d35e 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -20,7 +20,6 @@ #include // char_traits, string #include // make_pair, move #include // vector -#include // map #include #include @@ -1953,7 +1952,7 @@ class binary_reader return false; } - if (size_and_type.first != string_t::npos) + if (size_and_type.first != npos) { if (size_and_type.second != 0) { @@ -2186,7 +2185,7 @@ class binary_reader for (auto i : dim) { result *= i; - if (result == 0 || result == string_t::npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be string_t::npos as it is used to initialize size in get_ubjson_size_type() + 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)); } @@ -2232,7 +2231,7 @@ class binary_reader */ bool get_ubjson_size_type(std::pair& result, bool inside_ndarray = false) { - result.first = string_t::npos; // size + result.first = npos; // size result.second = 0; // type bool is_ndarray = false; @@ -2240,10 +2239,9 @@ class binary_reader if (current == '$') { - std::vector bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type - result.second = get(); // must not ignore 'N', because 'N' maybe the type - if (JSON_HEDLEY_UNLIKELY( input_format == input_format_t::bjdata && std::find(bjdx.begin(), bjdx.end(), result.second) != bjdx.end() )) + if (input_format == input_format_t::bjdata + && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second))) { auto last_token = get_token_string(); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, @@ -2492,23 +2490,23 @@ class binary_reader // if bit-8 of size_and_type.second is set to 1, encode bjdata ndarray as an object in JData annotated array format (https://github.com/NeuroJSON/jdata): // {"_ArrayType_" : "typeid", "_ArraySize_" : [n1, n2, ...], "_ArrayData_" : [v1, v2, ...]} - if (input_format == input_format_t::bjdata && size_and_type.first != string_t::npos && (size_and_type.second & (1 << 8)) != 0) + if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) { - std::map bjdtype = {{'U', "uint8"}, {'i', "int8"}, {'u', "uint16"}, {'I', "int16"}, - {'m', "uint32"}, {'l', "int32"}, {'M', "uint64"}, {'L', "int64"}, {'d', "single"}, {'D', "double"}, {'C', "char"} - }; - size_and_type.second &= ~(static_cast(1) << 8); // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker - + auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type & p, char_int_type t) + { + return p.first < t; + }); string_t key = "_ArrayType_"; - if (JSON_HEDLEY_UNLIKELY(bjdtype.count(size_and_type.second) == 0)) + if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second)) { auto last_token = get_token_string(); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr)); } - if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(bjdtype[size_and_type.second]) )) + string_t type = it->second; // sax->string() takes a reference + if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type))) { return false; } @@ -2535,7 +2533,7 @@ class binary_reader return (sax->end_array() && sax->end_object()); } - if (size_and_type.first != string_t::npos) + if (size_and_type.first != npos) { if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first))) { @@ -2598,7 +2596,7 @@ class binary_reader } // do not accept ND-array size in objects in BJData - if (input_format == input_format_t::bjdata && size_and_type.first != string_t::npos && (size_and_type.second & (1 << 8)) != 0) + if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) { auto last_token = get_token_string(); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, @@ -2606,7 +2604,7 @@ class binary_reader } string_t key; - if (size_and_type.first != string_t::npos) + if (size_and_type.first != npos) { if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first))) { @@ -2950,6 +2948,8 @@ class binary_reader } private: + static JSON_INLINE_VARIABLE constexpr std::size_t npos = static_cast(-1); + /// input adapter InputAdapterType ia; @@ -2967,7 +2967,44 @@ class binary_reader /// the SAX parser json_sax_t* sax = nullptr; + + // excluded markers in bjdata optimized type +#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \ + make_array('F', 'H', 'N', 'S', 'T', 'Z', '[', '{') + +#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \ + make_array( \ + bjd_type{'C', "char"}, \ + bjd_type{'D', "double"}, \ + bjd_type{'I', "int16"}, \ + bjd_type{'L', "int64"}, \ + bjd_type{'M', "uint64"}, \ + bjd_type{'U', "uint8"}, \ + bjd_type{'d', "single"}, \ + bjd_type{'i', "int8"}, \ + bjd_type{'l', "int32"}, \ + bjd_type{'m', "uint32"}, \ + bjd_type{'u', "uint16"}) + + JSON_PRIVATE_UNLESS_TESTED: + // lookup tables + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = + JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_; + + using bjd_type = std::pair; + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map = + JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_; + +#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ +#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ }; +#ifndef JSON_HAS_CPP_17 + template + constexpr std::size_t binary_reader::npos; +#endif + } // namespace detail NLOHMANN_JSON_NAMESPACE_END diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index fb528ca576..cf53b1d572 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 36d9c22c40..5bd5c51c02 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index bd6eb45f7d..72e9951081 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/input/parser.hpp b/include/nlohmann/detail/input/parser.hpp index fb493a8d2e..8acbd4fcad 100644 --- a/include/nlohmann/detail/input/parser.hpp +++ b/include/nlohmann/detail/input/parser.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/input/position_t.hpp b/include/nlohmann/detail/input/position_t.hpp index f67875045c..396db0e16b 100644 --- a/include/nlohmann/detail/input/position_t.hpp +++ b/include/nlohmann/detail/input/position_t.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/iterators/internal_iterator.hpp b/include/nlohmann/detail/iterators/internal_iterator.hpp index b456884448..13a212c8d9 100644 --- a/include/nlohmann/detail/iterators/internal_iterator.hpp +++ b/include/nlohmann/detail/iterators/internal_iterator.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/iterators/iter_impl.hpp b/include/nlohmann/detail/iterators/iter_impl.hpp index 18729da82d..3f5a9901ca 100644 --- a/include/nlohmann/detail/iterators/iter_impl.hpp +++ b/include/nlohmann/detail/iterators/iter_impl.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/iterators/iteration_proxy.hpp b/include/nlohmann/detail/iterators/iteration_proxy.hpp index de8c6590f4..659cd06f29 100644 --- a/include/nlohmann/detail/iterators/iteration_proxy.hpp +++ b/include/nlohmann/detail/iterators/iteration_proxy.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/iterators/iterator_traits.hpp b/include/nlohmann/detail/iterators/iterator_traits.hpp index 9f33979b5f..34a20eee85 100644 --- a/include/nlohmann/detail/iterators/iterator_traits.hpp +++ b/include/nlohmann/detail/iterators/iterator_traits.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/iterators/json_reverse_iterator.hpp b/include/nlohmann/detail/iterators/json_reverse_iterator.hpp index 5d9e45b2fc..eb450e986e 100644 --- a/include/nlohmann/detail/iterators/json_reverse_iterator.hpp +++ b/include/nlohmann/detail/iterators/json_reverse_iterator.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/iterators/primitive_iterator.hpp b/include/nlohmann/detail/iterators/primitive_iterator.hpp index 49222e77ce..0bc3ca804e 100644 --- a/include/nlohmann/detail/iterators/primitive_iterator.hpp +++ b/include/nlohmann/detail/iterators/primitive_iterator.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 5b76326766..3f69bcdf10 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -846,55 +846,143 @@ class json_pointer return result; } - /*! - @brief compares two JSON pointers for equality - - @param[in] lhs JSON pointer to compare - @param[in] rhs JSON pointer to compare - @return whether @a lhs is equal to @a rhs + public: +#if JSON_HAS_THREE_WAY_COMPARISON + /// @brief compares two JSON pointers for equality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ + template + bool operator==(const json_pointer& rhs) const noexcept + { + return reference_tokens == rhs.reference_tokens; + } - @complexity Linear in the length of the JSON pointer + /// @brief compares JSON pointer and string for equality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ + JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer)) + bool operator==(const string_t& rhs) const + { + return *this == json_pointer(rhs); + } - @exceptionsafety No-throw guarantee: this function never throws exceptions. - */ + /// @brief 3-way compares two JSON pointers + template + std::strong_ordering operator<=>(const json_pointer& rhs) const noexcept // *NOPAD* + { + return reference_tokens <=> rhs.reference_tokens; // *NOPAD* + } +#else + /// @brief compares two JSON pointers for equality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ template // NOLINTNEXTLINE(readability-redundant-declaration) - friend bool operator==(json_pointer const& lhs, - json_pointer const& rhs) noexcept; + friend bool operator==(const json_pointer& lhs, + const json_pointer& rhs) noexcept; - /*! - @brief compares two JSON pointers for inequality + /// @brief compares JSON pointer and string for equality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator==(const json_pointer& lhs, + const StringType& rhs); - @param[in] lhs JSON pointer to compare - @param[in] rhs JSON pointer to compare - @return whether @a lhs is not equal @a rhs + /// @brief compares string and JSON pointer for equality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator==(const StringType& lhs, + const json_pointer& rhs); - @complexity Linear in the length of the JSON pointer + /// @brief compares two JSON pointers for inequality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/ + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator!=(const json_pointer& lhs, + const json_pointer& rhs) noexcept; - @exceptionsafety No-throw guarantee: this function never throws exceptions. - */ + /// @brief compares JSON pointer and string for inequality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/ + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator!=(const json_pointer& lhs, + const StringType& rhs); + + /// @brief compares string and JSON pointer for inequality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/ + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator!=(const StringType& lhs, + const json_pointer& rhs); + + /// @brief compares two JSON pointer for less-than template // NOLINTNEXTLINE(readability-redundant-declaration) - friend bool operator!=(json_pointer const& lhs, - json_pointer const& rhs) noexcept; + friend bool operator<(const json_pointer& lhs, + const json_pointer& rhs) noexcept; +#endif + private: /// the reference tokens std::vector reference_tokens; }; +#if !JSON_HAS_THREE_WAY_COMPARISON // functions cannot be defined inside class due to ODR violations template -inline bool operator==(json_pointer const& lhs, - json_pointer const& rhs) noexcept +inline bool operator==(const json_pointer& lhs, + const json_pointer& rhs) noexcept { return lhs.reference_tokens == rhs.reference_tokens; } +template::string_t> +JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer)) +inline bool operator==(const json_pointer& lhs, + const StringType& rhs) +{ + return lhs == json_pointer(rhs); +} + +template::string_t> +JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer)) +inline bool operator==(const StringType& lhs, + const json_pointer& rhs) +{ + return json_pointer(lhs) == rhs; +} + template -inline bool operator!=(json_pointer const& lhs, - json_pointer const& rhs) noexcept +inline bool operator!=(const json_pointer& lhs, + const json_pointer& rhs) noexcept +{ + return !(lhs == rhs); +} + +template::string_t> +JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer)) +inline bool operator!=(const json_pointer& lhs, + const StringType& rhs) +{ + return !(lhs == rhs); +} + +template::string_t> +JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer)) +inline bool operator!=(const StringType& lhs, + const json_pointer& rhs) { return !(lhs == rhs); } +template +inline bool operator<(const json_pointer& lhs, + const json_pointer& rhs) noexcept +{ + return lhs.reference_tokens < rhs.reference_tokens; +} +#endif + NLOHMANN_JSON_NAMESPACE_END diff --git a/include/nlohmann/detail/json_ref.hpp b/include/nlohmann/detail/json_ref.hpp index bc72ca1b7a..47911fb552 100644 --- a/include/nlohmann/detail/json_ref.hpp +++ b/include/nlohmann/detail/json_ref.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index ff739f5d51..6248bea130 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/macro_unscope.hpp b/include/nlohmann/detail/macro_unscope.hpp index 85865be2c8..4a871f0c24 100644 --- a/include/nlohmann/detail/macro_unscope.hpp +++ b/include/nlohmann/detail/macro_unscope.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/meta/call_std/begin.hpp b/include/nlohmann/detail/meta/call_std/begin.hpp index 91342ec02a..27d36c66a0 100644 --- a/include/nlohmann/detail/meta/call_std/begin.hpp +++ b/include/nlohmann/detail/meta/call_std/begin.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/meta/call_std/end.hpp b/include/nlohmann/detail/meta/call_std/end.hpp index c5a9b94981..d10bf8333c 100644 --- a/include/nlohmann/detail/meta/call_std/end.hpp +++ b/include/nlohmann/detail/meta/call_std/end.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/meta/cpp_future.hpp b/include/nlohmann/detail/meta/cpp_future.hpp index d04ec8e05c..22f25140da 100644 --- a/include/nlohmann/detail/meta/cpp_future.hpp +++ b/include/nlohmann/detail/meta/cpp_future.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -9,6 +9,7 @@ #pragma once +#include // array #include // size_t #include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type #include // index_sequence, make_index_sequence, index_sequence_for @@ -152,15 +153,19 @@ template<> struct priority_tag<0> {}; template struct static_const { - static constexpr T value{}; + static JSON_INLINE_VARIABLE constexpr T value{}; }; #ifndef JSON_HAS_CPP_17 - template - constexpr T static_const::value; // NOLINT(readability-redundant-declaration) - + constexpr T static_const::value; #endif +template +inline constexpr std::array make_array(Args&& ... args) +{ + return std::array {{static_cast(std::forward(args))...}}; +} + } // namespace detail NLOHMANN_JSON_NAMESPACE_END diff --git a/include/nlohmann/detail/meta/detected.hpp b/include/nlohmann/detail/meta/detected.hpp index 6b5c816392..b2f6db9fc4 100644 --- a/include/nlohmann/detail/meta/detected.hpp +++ b/include/nlohmann/detail/meta/detected.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/meta/identity_tag.hpp b/include/nlohmann/detail/meta/identity_tag.hpp index 3df2d20129..71164f281b 100644 --- a/include/nlohmann/detail/meta/identity_tag.hpp +++ b/include/nlohmann/detail/meta/identity_tag.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/meta/is_sax.hpp b/include/nlohmann/detail/meta/is_sax.hpp index 052bddde31..2150089632 100644 --- a/include/nlohmann/detail/meta/is_sax.hpp +++ b/include/nlohmann/detail/meta/is_sax.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/meta/std_fs.hpp b/include/nlohmann/detail/meta/std_fs.hpp index bbebd7010a..c0961580ef 100644 --- a/include/nlohmann/detail/meta/std_fs.hpp +++ b/include/nlohmann/detail/meta/std_fs.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 2ec9d39a50..cfc7e5ad31 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -684,5 +684,57 @@ inline constexpr bool value_in_range_of(T val) return value_in_range_of_impl1::test(val); } +template +using bool_constant = std::integral_constant; + +/////////////////////////////////////////////////////////////////////////////// +// is_c_string +/////////////////////////////////////////////////////////////////////////////// + +namespace impl +{ + +template +inline constexpr bool is_c_string() +{ + using TUnExt = typename std::remove_extent::type; + using TUnCVExt = typename std::remove_cv::type; + using TUnPtr = typename std::remove_pointer::type; + using TUnCVPtr = typename std::remove_cv::type; + return + (std::is_array::value && std::is_same::value) + || (std::is_pointer::value && std::is_same::value); +} + +} // namespace impl + +// checks whether T is a [cv] char */[cv] char[] C string +template +struct is_c_string : bool_constant()> {}; + +template +using is_c_string_uncvref = is_c_string>; + +/////////////////////////////////////////////////////////////////////////////// +// is_transparent +/////////////////////////////////////////////////////////////////////////////// + +namespace impl +{ + +template +inline constexpr bool is_transparent() +{ + return is_detected::value; +} + +} // namespace impl + +// checks whether T has a member named is_transparent +template +struct is_transparent : bool_constant()> {}; + +/////////////////////////////////////////////////////////////////////////////// + } // namespace detail NLOHMANN_JSON_NAMESPACE_END diff --git a/include/nlohmann/detail/meta/void_t.hpp b/include/nlohmann/detail/meta/void_t.hpp index 261d957b5b..29154020d5 100644 --- a/include/nlohmann/detail/meta/void_t.hpp +++ b/include/nlohmann/detail/meta/void_t.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 25755f0155..9423635f01 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/output/output_adapters.hpp b/include/nlohmann/detail/output/output_adapters.hpp index 2935fe7a65..630bd8f73f 100644 --- a/include/nlohmann/detail/output/output_adapters.hpp +++ b/include/nlohmann/detail/output/output_adapters.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index d73692dd9b..500fc55ec5 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2008-2009 Björn Hoehrmann diff --git a/include/nlohmann/detail/string_concat.hpp b/include/nlohmann/detail/string_concat.hpp index 2529e4f658..59725ca825 100644 --- a/include/nlohmann/detail/string_concat.hpp +++ b/include/nlohmann/detail/string_concat.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/string_escape.hpp b/include/nlohmann/detail/string_escape.hpp index d417b4eb93..f20461910d 100644 --- a/include/nlohmann/detail/string_escape.hpp +++ b/include/nlohmann/detail/string_escape.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/detail/value_t.hpp b/include/nlohmann/detail/value_t.hpp index 3b20dd8cd0..0e79fd6698 100644 --- a/include/nlohmann/detail/value_t.hpp +++ b/include/nlohmann/detail/value_t.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 49188b314f..18a7c87577 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -514,7 +514,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec object = nullptr; // silence warning, see #821 if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) { - JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.1", nullptr)); // LCOV_EXCL_LINE + JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.2", nullptr)); // LCOV_EXCL_LINE } break; } @@ -2194,14 +2194,24 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this)); } + private: + template + using is_comparable_with_object_key = detail::is_comparable < + object_comparator_t, const typename object_t::key_type&, KeyType >; + + template + using value_return_type = std::conditional < + detail::is_c_string_uncvref::value, + string_t, typename std::decay::type >; + + public: /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - // this is the value(const typename object_t::key_type&) overload - template < class KeyType, class ValueType, detail::enable_if_t < - std::is_same::value + template < class ValueType, detail::enable_if_t < + !detail::is_transparent::value && detail::is_getable::value - && !std::is_same::value, int > = 0 > - typename std::decay::type value(const KeyType& key, ValueType && default_value) const + && !std::is_same>::value, int > = 0 > + ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -2210,10 +2220,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec const auto it = find(key); if (it != end()) { - return it->template get::type>(); + return it->template get(); } - return std::forward(default_value); + return default_value; } JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); @@ -2221,36 +2231,38 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - /// overload for a default value of type const char* - string_t value(const typename object_t::key_type& key, const char* default_value) const + template < class ValueType, class ReturnType = typename value_return_type::type, + detail::enable_if_t < + !detail::is_transparent::value + && detail::is_getable::value + && !std::is_same>::value, int > = 0 > + ReturnType value(const typename object_t::key_type& key, ValueType && default_value) const { - return value(key, string_t(default_value)); - } + // value only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + // if key is found, return value and given default value otherwise + const auto it = find(key); + if (it != end()) + { + return it->template get(); + } - // these two functions, in conjunction with value(const KeyType &, ValueType &&), - // resolve an ambiguity that would otherwise occur between the json_pointer and - // typename object_t::key_type & overloads - template < class ValueType, detail::enable_if_t < - detail::is_getable::value - && !std::is_same::value, int > = 0 > - typename std::decay::type value(const char* key, ValueType && default_value) const - { - return value(typename object_t::key_type(key), std::forward(default_value)); - } + return std::forward(default_value); + } - string_t value(const char* key, const char* default_value) const - { - return value(typename object_t::key_type(key), string_t(default_value)); + JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); } /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - /// using std::is_convertible in a std::enable_if will fail when using explicit conversions - template < class KeyType, class ValueType, detail::enable_if_t < - detail::is_getable::value - && !std::is_same::value - && detail::is_usable_as_basic_json_key_type::value, int > = 0 > - typename std::decay::type value(KeyType && key, ValueType && default_value) const + template < class ValueType, class KeyType, detail::enable_if_t < + detail::is_transparent::value + && !detail::is_json_pointer::value + && is_comparable_with_object_key::value + && detail::is_getable::value + && !std::is_same>::value, int > = 0 > + ValueType value(KeyType && key, const ValueType& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -2259,29 +2271,47 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec const auto it = find(std::forward(key)); if (it != end()) { - return it->template get::type>(); + return it->template get(); } - return std::forward(default_value); + return default_value; } JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); } - /// @brief access specified object element with default value + /// @brief access specified object element via JSON Pointer with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - /// overload for a default value of type const char* - template < class KeyType, detail::enable_if_t < - !detail::is_json_pointer::value, int > = 0 > - string_t value(KeyType && key, const char* default_value) const + template < class ValueType, class KeyType, class ReturnType = typename value_return_type::type, + detail::enable_if_t < + detail::is_transparent::value + && !detail::is_json_pointer::value + && is_comparable_with_object_key::value + && detail::is_getable::value + && !std::is_same>::value, int > = 0 > + ReturnType value(KeyType && key, ValueType && default_value) const { - return value(std::forward(key), string_t(default_value)); + // value only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + // if key is found, return value and given default value otherwise + const auto it = find(std::forward(key)); + if (it != end()) + { + return it->template get(); + } + + return std::forward(default_value); + } + + JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); } /// @brief access specified object element via JSON Pointer with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ template < class ValueType, detail::enable_if_t < - detail::is_getable::value, int> = 0 > + detail::is_getable::value + && !std::is_same>::value, int > = 0 > ValueType value(const json_pointer& ptr, const ValueType& default_value) const { // value only works for objects @@ -2301,29 +2331,50 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); } + /// @brief access specified object element via JSON Pointer with default value + /// @sa https://json.nlohmann.me/api/basic_json/value/ + template < class ValueType, class ReturnType = typename value_return_type::type, + detail::enable_if_t < + detail::is_getable::value + && !std::is_same>::value, int > = 0 > + ReturnType value(const json_pointer& ptr, ValueType && default_value) const + { + // value only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + // if pointer resolves a value, return it or use default value + JSON_TRY + { + return ptr.get_checked(this).template get(); + } + JSON_INTERNAL_CATCH (out_of_range&) + { + return std::forward(default_value); + } + } + + JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); + } + template < class ValueType, class BasicJsonType, detail::enable_if_t < - detail::is_getable::value, int> = 0 > + detail::is_basic_json::value + && detail::is_getable::value + && !std::is_same>::value, int > = 0 > JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) ValueType value(const ::nlohmann::json_pointer& ptr, const ValueType& default_value) const { return value(ptr.convert(), default_value); } - /// @brief access specified object element via JSON Pointer with default value - /// @sa https://json.nlohmann.me/api/basic_json/value/ - /// overload for a default value of type const char* - JSON_HEDLEY_NON_NULL(3) - string_t value(const json_pointer& ptr, const char* default_value) const - { - return value(ptr, string_t(default_value)); - } - - template + template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type::type, + detail::enable_if_t < + detail::is_basic_json::value + && detail::is_getable::value + && !std::is_same>::value, int > = 0 > JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) - JSON_HEDLEY_NON_NULL(3) - string_t value(const typename ::nlohmann::json_pointer& ptr, const char* default_value) const + ReturnType value(const ::nlohmann::json_pointer& ptr, ValueType && default_value) const { - return value(ptr.convert(), default_value); + return value(ptr.convert(), std::forward(default_value)); } /// @brief access the first element @@ -2685,9 +2736,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return ptr.contains(this); } - template + template::value, int> = 0> JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) - bool contains(const typename ::nlohmann::json_pointer ptr) const + bool contains(const typename ::nlohmann::json_pointer& ptr) const { return ptr.contains(this); } @@ -4566,7 +4617,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return ptr.get_checked(this); } - template + template::value, int> = 0> JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) reference at(const ::nlohmann::json_pointer& ptr) { @@ -4580,7 +4631,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return ptr.get_checked(this); } - template + template::value, int> = 0> JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) const_reference at(const ::nlohmann::json_pointer& ptr) const { diff --git a/include/nlohmann/json_fwd.hpp b/include/nlohmann/json_fwd.hpp index c7ad236602..67172b14f5 100644 --- a/include/nlohmann/json_fwd.hpp +++ b/include/nlohmann/json_fwd.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -51,7 +51,7 @@ class basic_json; /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document /// @sa https://json.nlohmann.me/api/json_pointer/ -template +template class json_pointer; /*! diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index cf67761b23..55c630d90d 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/thirdparty/hedley/hedley.hpp b/include/nlohmann/thirdparty/hedley/hedley.hpp index 3f9c41efd4..f1377f1e45 100644 --- a/include/nlohmann/thirdparty/hedley/hedley.hpp +++ b/include/nlohmann/thirdparty/hedley/hedley.hpp @@ -2,7 +2,7 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/include/nlohmann/thirdparty/hedley/hedley_undef.hpp b/include/nlohmann/thirdparty/hedley/hedley_undef.hpp index f2c2015c6e..d0c58ff843 100644 --- a/include/nlohmann/thirdparty/hedley/hedley_undef.hpp +++ b/include/nlohmann/thirdparty/hedley/hedley_undef.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/meson.build b/meson.build index 005e98ef20..e2fb86f465 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('nlohmann_json', 'cpp', - version : '3.11.1', + version : '3.11.2', license : 'MIT', ) @@ -14,6 +14,7 @@ nlohmann_json_multiple_headers = declare_dependency( if not meson.is_subproject() install_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann') +install_headers('single_include/nlohmann/json_fwd.hpp', subdir: 'nlohmann') pkgc = import('pkgconfig') pkgc.generate(name: 'nlohmann_json', diff --git a/nlohmann_json.natvis b/nlohmann_json.natvis index 557717663b..b101771e6f 100644 --- a/nlohmann_json.natvis +++ b/nlohmann_json.natvis @@ -1,5 +1,9 @@ + + + + null {*(m_value.object)} @@ -20,8 +24,8 @@ - + {second} @@ -29,4 +33,244 @@ + + + null + {*(m_value.object)} + {*(m_value.array)} + {*(m_value.string)} + {m_value.boolean} + {m_value.number_integer} + {m_value.number_unsigned} + {m_value.number_float} + discarded + + + *(m_value.object),view(simple) + + + *(m_value.array),view(simple) + + + + + + + {second} + + second + + + + + + null + {*(m_value.object)} + {*(m_value.array)} + {*(m_value.string)} + {m_value.boolean} + {m_value.number_integer} + {m_value.number_unsigned} + {m_value.number_float} + discarded + + + *(m_value.object),view(simple) + + + *(m_value.array),view(simple) + + + + + + + {second} + + second + + + + + + null + {*(m_value.object)} + {*(m_value.array)} + {*(m_value.string)} + {m_value.boolean} + {m_value.number_integer} + {m_value.number_unsigned} + {m_value.number_float} + discarded + + + *(m_value.object),view(simple) + + + *(m_value.array),view(simple) + + + + + + + {second} + + second + + + + + + null + {*(m_value.object)} + {*(m_value.array)} + {*(m_value.string)} + {m_value.boolean} + {m_value.number_integer} + {m_value.number_unsigned} + {m_value.number_float} + discarded + + + *(m_value.object),view(simple) + + + *(m_value.array),view(simple) + + + + + + + {second} + + second + + + + + + null + {*(m_value.object)} + {*(m_value.array)} + {*(m_value.string)} + {m_value.boolean} + {m_value.number_integer} + {m_value.number_unsigned} + {m_value.number_float} + discarded + + + *(m_value.object),view(simple) + + + *(m_value.array),view(simple) + + + + + + + {second} + + second + + + + + + null + {*(m_value.object)} + {*(m_value.array)} + {*(m_value.string)} + {m_value.boolean} + {m_value.number_integer} + {m_value.number_unsigned} + {m_value.number_float} + discarded + + + *(m_value.object),view(simple) + + + *(m_value.array),view(simple) + + + + + + + {second} + + second + + + + + + null + {*(m_value.object)} + {*(m_value.array)} + {*(m_value.string)} + {m_value.boolean} + {m_value.number_integer} + {m_value.number_unsigned} + {m_value.number_float} + discarded + + + *(m_value.object),view(simple) + + + *(m_value.array),view(simple) + + + + + + + {second} + + second + + + + + + null + {*(m_value.object)} + {*(m_value.array)} + {*(m_value.string)} + {m_value.boolean} + {m_value.number_integer} + {m_value.number_unsigned} + {m_value.number_float} + discarded + + + *(m_value.object),view(simple) + + + *(m_value.array),view(simple) + + + + + + + {second} + + second + + + diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index e9bf47551f..4d1a37ad7c 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -35,7 +35,7 @@ // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -48,7 +48,7 @@ // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -60,7 +60,7 @@ #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) - #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 1 + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 2 #warning "Already included a different version of the library!" #endif #endif @@ -68,7 +68,7 @@ #define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) #define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) -#define NLOHMANN_JSON_VERSION_PATCH 1 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_PATCH 2 // NOLINT(modernize-macro-to-enum) #ifndef JSON_DIAGNOSTICS #define JSON_DIAGNOSTICS 0 @@ -90,46 +90,67 @@ #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON #endif -#define NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) \ - json_v ## major ## _ ## minor ## _ ## patch -#define NLOHMANN_JSON_ABI_PREFIX(major, minor, patch) \ - NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) +#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION + #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 +#endif -#define NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) a ## b ## c -#define NLOHMANN_JSON_ABI_CONCAT(a, b, c) \ - NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) +// Construct the namespace ABI tags component +#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b +#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ + NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) -#define NLOHMANN_JSON_ABI_STRING \ - NLOHMANN_JSON_ABI_CONCAT( \ - NLOHMANN_JSON_ABI_PREFIX( \ - NLOHMANN_JSON_VERSION_MAJOR, \ - NLOHMANN_JSON_VERSION_MINOR, \ - NLOHMANN_JSON_VERSION_PATCH), \ - NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ +#define NLOHMANN_JSON_ABI_TAGS \ + NLOHMANN_JSON_ABI_TAGS_CONCAT( \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) +// Construct the namespace version component +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ + _v ## major ## _ ## minor ## _ ## patch +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) + +#if NLOHMANN_JSON_NAMESPACE_NO_VERSION +#define NLOHMANN_JSON_NAMESPACE_VERSION +#else +#define NLOHMANN_JSON_NAMESPACE_VERSION \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH) +#endif + +// Combine namespace components +#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b +#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ + NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) + #ifndef NLOHMANN_JSON_NAMESPACE - #define NLOHMANN_JSON_NAMESPACE nlohmann::NLOHMANN_JSON_ABI_STRING +#define NLOHMANN_JSON_NAMESPACE \ + nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) #endif #ifndef NLOHMANN_JSON_NAMESPACE_BEGIN -#define NLOHMANN_JSON_NAMESPACE_BEGIN \ - namespace nlohmann \ - { \ - inline namespace NLOHMANN_JSON_ABI_STRING \ +#define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann \ + { \ + inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) \ { #endif #ifndef NLOHMANN_JSON_NAMESPACE_END -#define NLOHMANN_JSON_NAMESPACE_END \ - } /* namespace (abi_string) */ \ - } /* namespace nlohmann */ +#define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ + } // namespace nlohmann #endif // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -152,7 +173,7 @@ // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -169,7 +190,7 @@ // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -185,7 +206,7 @@ // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -197,7 +218,7 @@ // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -210,7 +231,7 @@ // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -297,7 +318,7 @@ NLOHMANN_JSON_NAMESPACE_END // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -2902,7 +2923,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -2977,7 +2998,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -3019,7 +3040,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -3028,6 +3049,7 @@ NLOHMANN_JSON_NAMESPACE_END +#include // array #include // size_t #include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type #include // index_sequence, make_index_sequence, index_sequence_for @@ -3172,23 +3194,27 @@ template<> struct priority_tag<0> {}; template struct static_const { - static constexpr T value{}; + static JSON_INLINE_VARIABLE constexpr T value{}; }; #ifndef JSON_HAS_CPP_17 - template - constexpr T static_const::value; // NOLINT(readability-redundant-declaration) - + constexpr T static_const::value; #endif +template +inline constexpr std::array make_array(Args&& ... args) +{ + return std::array {{static_cast(std::forward(args))...}}; +} + } // namespace detail NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -3204,7 +3230,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -3272,7 +3298,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -3292,7 +3318,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -3316,7 +3342,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -3368,7 +3394,7 @@ NLOHMANN_JSON_NAMESPACE_END /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document /// @sa https://json.nlohmann.me/api/json_pointer/ - template + template class json_pointer; /*! @@ -4054,13 +4080,65 @@ inline constexpr bool value_in_range_of(T val) return value_in_range_of_impl1::test(val); } +template +using bool_constant = std::integral_constant; + +/////////////////////////////////////////////////////////////////////////////// +// is_c_string +/////////////////////////////////////////////////////////////////////////////// + +namespace impl +{ + +template +inline constexpr bool is_c_string() +{ + using TUnExt = typename std::remove_extent::type; + using TUnCVExt = typename std::remove_cv::type; + using TUnPtr = typename std::remove_pointer::type; + using TUnCVPtr = typename std::remove_cv::type; + return + (std::is_array::value && std::is_same::value) + || (std::is_pointer::value && std::is_same::value); +} + +} // namespace impl + +// checks whether T is a [cv] char */[cv] char[] C string +template +struct is_c_string : bool_constant()> {}; + +template +using is_c_string_uncvref = is_c_string>; + +/////////////////////////////////////////////////////////////////////////////// +// is_transparent +/////////////////////////////////////////////////////////////////////////////// + +namespace impl +{ + +template +inline constexpr bool is_transparent() +{ + return is_detected::value; +} + +} // namespace impl + +// checks whether T has a member named is_transparent +template +struct is_transparent : bool_constant()> {}; + +/////////////////////////////////////////////////////////////////////////////// + } // namespace detail NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -4447,7 +4525,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -4471,7 +4549,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -4977,7 +5055,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -4997,7 +5075,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -5495,9 +5573,15 @@ inline void to_json(BasicJsonType& j, T b) noexcept external_constructor::construct(j, b); } -template::reference&, typename BasicJsonType::boolean_t>::value, int> = 0> -inline void to_json(BasicJsonType& j, const std::vector::reference& b) noexcept +template < typename BasicJsonType, typename BoolRef, + enable_if_t < + ((std::is_same::reference, BoolRef>::value + && !std::is_same ::reference, typename BasicJsonType::boolean_t&>::value) + || (std::is_same::const_reference, BoolRef>::value + && !std::is_same ::const_reference>, + typename BasicJsonType::boolean_t >::value)) + && std::is_convertible::value, int > = 0 > +inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept { external_constructor::construct(j, static_cast(b)); } @@ -5712,7 +5796,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -5824,7 +5908,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -5957,7 +6041,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -5977,14 +6061,13 @@ NLOHMANN_JSON_NAMESPACE_END #include // char_traits, string #include // make_pair, move #include // vector -#include // map // #include // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -6482,7 +6565,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -7215,7 +7298,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -8854,7 +8937,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -10943,7 +11026,7 @@ class binary_reader return false; } - if (size_and_type.first != string_t::npos) + if (size_and_type.first != npos) { if (size_and_type.second != 0) { @@ -11176,7 +11259,7 @@ class binary_reader for (auto i : dim) { result *= i; - if (result == 0 || result == string_t::npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be string_t::npos as it is used to initialize size in get_ubjson_size_type() + 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)); } @@ -11222,7 +11305,7 @@ class binary_reader */ bool get_ubjson_size_type(std::pair& result, bool inside_ndarray = false) { - result.first = string_t::npos; // size + result.first = npos; // size result.second = 0; // type bool is_ndarray = false; @@ -11230,10 +11313,9 @@ class binary_reader if (current == '$') { - std::vector bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type - result.second = get(); // must not ignore 'N', because 'N' maybe the type - if (JSON_HEDLEY_UNLIKELY( input_format == input_format_t::bjdata && std::find(bjdx.begin(), bjdx.end(), result.second) != bjdx.end() )) + if (input_format == input_format_t::bjdata + && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second))) { auto last_token = get_token_string(); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, @@ -11482,23 +11564,23 @@ class binary_reader // if bit-8 of size_and_type.second is set to 1, encode bjdata ndarray as an object in JData annotated array format (https://github.com/NeuroJSON/jdata): // {"_ArrayType_" : "typeid", "_ArraySize_" : [n1, n2, ...], "_ArrayData_" : [v1, v2, ...]} - if (input_format == input_format_t::bjdata && size_and_type.first != string_t::npos && (size_and_type.second & (1 << 8)) != 0) + if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) { - std::map bjdtype = {{'U', "uint8"}, {'i', "int8"}, {'u', "uint16"}, {'I', "int16"}, - {'m', "uint32"}, {'l', "int32"}, {'M', "uint64"}, {'L', "int64"}, {'d', "single"}, {'D', "double"}, {'C', "char"} - }; - size_and_type.second &= ~(static_cast(1) << 8); // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker - + auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type & p, char_int_type t) + { + return p.first < t; + }); string_t key = "_ArrayType_"; - if (JSON_HEDLEY_UNLIKELY(bjdtype.count(size_and_type.second) == 0)) + if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second)) { auto last_token = get_token_string(); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr)); } - if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(bjdtype[size_and_type.second]) )) + string_t type = it->second; // sax->string() takes a reference + if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type))) { return false; } @@ -11525,7 +11607,7 @@ class binary_reader return (sax->end_array() && sax->end_object()); } - if (size_and_type.first != string_t::npos) + if (size_and_type.first != npos) { if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first))) { @@ -11588,7 +11670,7 @@ class binary_reader } // do not accept ND-array size in objects in BJData - if (input_format == input_format_t::bjdata && size_and_type.first != string_t::npos && (size_and_type.second & (1 << 8)) != 0) + if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) { auto last_token = get_token_string(); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, @@ -11596,7 +11678,7 @@ class binary_reader } string_t key; - if (size_and_type.first != string_t::npos) + if (size_and_type.first != npos) { if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first))) { @@ -11940,6 +12022,8 @@ class binary_reader } private: + static JSON_INLINE_VARIABLE constexpr std::size_t npos = static_cast(-1); + /// input adapter InputAdapterType ia; @@ -11957,8 +12041,45 @@ class binary_reader /// the SAX parser json_sax_t* sax = nullptr; + + // excluded markers in bjdata optimized type +#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \ + make_array('F', 'H', 'N', 'S', 'T', 'Z', '[', '{') + +#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \ + make_array( \ + bjd_type{'C', "char"}, \ + bjd_type{'D', "double"}, \ + bjd_type{'I', "int16"}, \ + bjd_type{'L', "int64"}, \ + bjd_type{'M', "uint64"}, \ + bjd_type{'U', "uint8"}, \ + bjd_type{'d', "single"}, \ + bjd_type{'i', "int8"}, \ + bjd_type{'l', "int32"}, \ + bjd_type{'m', "uint32"}, \ + bjd_type{'u', "uint16"}) + + JSON_PRIVATE_UNLESS_TESTED: + // lookup tables + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = + JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_; + + using bjd_type = std::pair; + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map = + JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_; + +#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ +#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ }; +#ifndef JSON_HAS_CPP_17 + template + constexpr std::size_t binary_reader::npos; +#endif + } // namespace detail NLOHMANN_JSON_NAMESPACE_END @@ -11969,7 +12090,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -12486,7 +12607,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -12499,7 +12620,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -12658,7 +12779,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -13420,7 +13541,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -13555,7 +13676,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -14406,63 +14527,151 @@ class json_pointer return result; } - /*! - @brief compares two JSON pointers for equality - - @param[in] lhs JSON pointer to compare - @param[in] rhs JSON pointer to compare - @return whether @a lhs is equal to @a rhs + public: +#if JSON_HAS_THREE_WAY_COMPARISON + /// @brief compares two JSON pointers for equality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ + template + bool operator==(const json_pointer& rhs) const noexcept + { + return reference_tokens == rhs.reference_tokens; + } - @complexity Linear in the length of the JSON pointer + /// @brief compares JSON pointer and string for equality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ + JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer)) + bool operator==(const string_t& rhs) const + { + return *this == json_pointer(rhs); + } - @exceptionsafety No-throw guarantee: this function never throws exceptions. - */ + /// @brief 3-way compares two JSON pointers + template + std::strong_ordering operator<=>(const json_pointer& rhs) const noexcept // *NOPAD* + { + return reference_tokens <=> rhs.reference_tokens; // *NOPAD* + } +#else + /// @brief compares two JSON pointers for equality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ template // NOLINTNEXTLINE(readability-redundant-declaration) - friend bool operator==(json_pointer const& lhs, - json_pointer const& rhs) noexcept; + friend bool operator==(const json_pointer& lhs, + const json_pointer& rhs) noexcept; - /*! - @brief compares two JSON pointers for inequality + /// @brief compares JSON pointer and string for equality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator==(const json_pointer& lhs, + const StringType& rhs); - @param[in] lhs JSON pointer to compare - @param[in] rhs JSON pointer to compare - @return whether @a lhs is not equal @a rhs + /// @brief compares string and JSON pointer for equality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator==(const StringType& lhs, + const json_pointer& rhs); - @complexity Linear in the length of the JSON pointer + /// @brief compares two JSON pointers for inequality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/ + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator!=(const json_pointer& lhs, + const json_pointer& rhs) noexcept; - @exceptionsafety No-throw guarantee: this function never throws exceptions. - */ + /// @brief compares JSON pointer and string for inequality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/ + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator!=(const json_pointer& lhs, + const StringType& rhs); + + /// @brief compares string and JSON pointer for inequality + /// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/ + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator!=(const StringType& lhs, + const json_pointer& rhs); + + /// @brief compares two JSON pointer for less-than template // NOLINTNEXTLINE(readability-redundant-declaration) - friend bool operator!=(json_pointer const& lhs, - json_pointer const& rhs) noexcept; + friend bool operator<(const json_pointer& lhs, + const json_pointer& rhs) noexcept; +#endif + private: /// the reference tokens std::vector reference_tokens; }; +#if !JSON_HAS_THREE_WAY_COMPARISON // functions cannot be defined inside class due to ODR violations template -inline bool operator==(json_pointer const& lhs, - json_pointer const& rhs) noexcept +inline bool operator==(const json_pointer& lhs, + const json_pointer& rhs) noexcept { return lhs.reference_tokens == rhs.reference_tokens; } +template::string_t> +JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer)) +inline bool operator==(const json_pointer& lhs, + const StringType& rhs) +{ + return lhs == json_pointer(rhs); +} + +template::string_t> +JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer)) +inline bool operator==(const StringType& lhs, + const json_pointer& rhs) +{ + return json_pointer(lhs) == rhs; +} + template -inline bool operator!=(json_pointer const& lhs, - json_pointer const& rhs) noexcept +inline bool operator!=(const json_pointer& lhs, + const json_pointer& rhs) noexcept +{ + return !(lhs == rhs); +} + +template::string_t> +JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer)) +inline bool operator!=(const json_pointer& lhs, + const StringType& rhs) +{ + return !(lhs == rhs); +} + +template::string_t> +JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer)) +inline bool operator!=(const StringType& lhs, + const json_pointer& rhs) { return !(lhs == rhs); } +template +inline bool operator<(const json_pointer& lhs, + const json_pointer& rhs) noexcept +{ + return lhs.reference_tokens < rhs.reference_tokens; +} +#endif + NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -14554,7 +14763,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -14580,7 +14789,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -16548,7 +16757,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2008-2009 Björn Hoehrmann @@ -16573,7 +16782,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2009 Florian Loitsch @@ -18669,7 +18878,7 @@ NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -19483,7 +19692,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec object = nullptr; // silence warning, see #821 if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) { - JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.1", nullptr)); // LCOV_EXCL_LINE + JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.2", nullptr)); // LCOV_EXCL_LINE } break; } @@ -21163,14 +21372,24 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this)); } + private: + template + using is_comparable_with_object_key = detail::is_comparable < + object_comparator_t, const typename object_t::key_type&, KeyType >; + + template + using value_return_type = std::conditional < + detail::is_c_string_uncvref::value, + string_t, typename std::decay::type >; + + public: /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - // this is the value(const typename object_t::key_type&) overload - template < class KeyType, class ValueType, detail::enable_if_t < - std::is_same::value + template < class ValueType, detail::enable_if_t < + !detail::is_transparent::value && detail::is_getable::value - && !std::is_same::value, int > = 0 > - typename std::decay::type value(const KeyType& key, ValueType && default_value) const + && !std::is_same>::value, int > = 0 > + ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -21179,10 +21398,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec const auto it = find(key); if (it != end()) { - return it->template get::type>(); + return it->template get(); } - return std::forward(default_value); + return default_value; } JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); @@ -21190,36 +21409,38 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - /// overload for a default value of type const char* - string_t value(const typename object_t::key_type& key, const char* default_value) const + template < class ValueType, class ReturnType = typename value_return_type::type, + detail::enable_if_t < + !detail::is_transparent::value + && detail::is_getable::value + && !std::is_same>::value, int > = 0 > + ReturnType value(const typename object_t::key_type& key, ValueType && default_value) const { - return value(key, string_t(default_value)); - } + // value only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + // if key is found, return value and given default value otherwise + const auto it = find(key); + if (it != end()) + { + return it->template get(); + } - // these two functions, in conjunction with value(const KeyType &, ValueType &&), - // resolve an ambiguity that would otherwise occur between the json_pointer and - // typename object_t::key_type & overloads - template < class ValueType, detail::enable_if_t < - detail::is_getable::value - && !std::is_same::value, int > = 0 > - typename std::decay::type value(const char* key, ValueType && default_value) const - { - return value(typename object_t::key_type(key), std::forward(default_value)); - } + return std::forward(default_value); + } - string_t value(const char* key, const char* default_value) const - { - return value(typename object_t::key_type(key), string_t(default_value)); + JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); } /// @brief access specified object element with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - /// using std::is_convertible in a std::enable_if will fail when using explicit conversions - template < class KeyType, class ValueType, detail::enable_if_t < - detail::is_getable::value - && !std::is_same::value - && detail::is_usable_as_basic_json_key_type::value, int > = 0 > - typename std::decay::type value(KeyType && key, ValueType && default_value) const + template < class ValueType, class KeyType, detail::enable_if_t < + detail::is_transparent::value + && !detail::is_json_pointer::value + && is_comparable_with_object_key::value + && detail::is_getable::value + && !std::is_same>::value, int > = 0 > + ValueType value(KeyType && key, const ValueType& default_value) const { // value only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -21228,29 +21449,47 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec const auto it = find(std::forward(key)); if (it != end()) { - return it->template get::type>(); + return it->template get(); } - return std::forward(default_value); + return default_value; } JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); } - /// @brief access specified object element with default value + /// @brief access specified object element via JSON Pointer with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ - /// overload for a default value of type const char* - template < class KeyType, detail::enable_if_t < - !detail::is_json_pointer::value, int > = 0 > - string_t value(KeyType && key, const char* default_value) const + template < class ValueType, class KeyType, class ReturnType = typename value_return_type::type, + detail::enable_if_t < + detail::is_transparent::value + && !detail::is_json_pointer::value + && is_comparable_with_object_key::value + && detail::is_getable::value + && !std::is_same>::value, int > = 0 > + ReturnType value(KeyType && key, ValueType && default_value) const { - return value(std::forward(key), string_t(default_value)); + // value only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + // if key is found, return value and given default value otherwise + const auto it = find(std::forward(key)); + if (it != end()) + { + return it->template get(); + } + + return std::forward(default_value); + } + + JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); } /// @brief access specified object element via JSON Pointer with default value /// @sa https://json.nlohmann.me/api/basic_json/value/ template < class ValueType, detail::enable_if_t < - detail::is_getable::value, int> = 0 > + detail::is_getable::value + && !std::is_same>::value, int > = 0 > ValueType value(const json_pointer& ptr, const ValueType& default_value) const { // value only works for objects @@ -21270,29 +21509,50 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); } + /// @brief access specified object element via JSON Pointer with default value + /// @sa https://json.nlohmann.me/api/basic_json/value/ + template < class ValueType, class ReturnType = typename value_return_type::type, + detail::enable_if_t < + detail::is_getable::value + && !std::is_same>::value, int > = 0 > + ReturnType value(const json_pointer& ptr, ValueType && default_value) const + { + // value only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + // if pointer resolves a value, return it or use default value + JSON_TRY + { + return ptr.get_checked(this).template get(); + } + JSON_INTERNAL_CATCH (out_of_range&) + { + return std::forward(default_value); + } + } + + JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); + } + template < class ValueType, class BasicJsonType, detail::enable_if_t < - detail::is_getable::value, int> = 0 > + detail::is_basic_json::value + && detail::is_getable::value + && !std::is_same>::value, int > = 0 > JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) ValueType value(const ::nlohmann::json_pointer& ptr, const ValueType& default_value) const { return value(ptr.convert(), default_value); } - /// @brief access specified object element via JSON Pointer with default value - /// @sa https://json.nlohmann.me/api/basic_json/value/ - /// overload for a default value of type const char* - JSON_HEDLEY_NON_NULL(3) - string_t value(const json_pointer& ptr, const char* default_value) const - { - return value(ptr, string_t(default_value)); - } - - template + template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type::type, + detail::enable_if_t < + detail::is_basic_json::value + && detail::is_getable::value + && !std::is_same>::value, int > = 0 > JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) - JSON_HEDLEY_NON_NULL(3) - string_t value(const typename ::nlohmann::json_pointer& ptr, const char* default_value) const + ReturnType value(const ::nlohmann::json_pointer& ptr, ValueType && default_value) const { - return value(ptr.convert(), default_value); + return value(ptr.convert(), std::forward(default_value)); } /// @brief access the first element @@ -21654,9 +21914,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return ptr.contains(this); } - template + template::value, int> = 0> JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) - bool contains(const typename ::nlohmann::json_pointer ptr) const + bool contains(const typename ::nlohmann::json_pointer& ptr) const { return ptr.contains(this); } @@ -23535,7 +23795,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return ptr.get_checked(this); } - template + template::value, int> = 0> JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) reference at(const ::nlohmann::json_pointer& ptr) { @@ -23549,7 +23809,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return ptr.get_checked(this); } - template + template::value, int> = 0> JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) const_reference at(const ::nlohmann::json_pointer& ptr) const { @@ -24130,7 +24390,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -24174,7 +24434,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/single_include/nlohmann/json_fwd.hpp b/single_include/nlohmann/json_fwd.hpp new file mode 100644 index 0000000000..83c21f857b --- /dev/null +++ b/single_include/nlohmann/json_fwd.hpp @@ -0,0 +1,175 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + +#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ +#define INCLUDE_NLOHMANN_JSON_FWD_HPP_ + +#include // int64_t, uint64_t +#include // map +#include // allocator +#include // string +#include // vector + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// This file contains all macro definitions affecting or depending on the ABI + +#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK + #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 2 + #warning "Already included a different version of the library!" + #endif + #endif +#endif + +#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_PATCH 2 // NOLINT(modernize-macro-to-enum) + +#ifndef JSON_DIAGNOSTICS + #define JSON_DIAGNOSTICS 0 +#endif + +#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0 +#endif + +#if JSON_DIAGNOSTICS + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag +#else + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS +#endif + +#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp +#else + #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION + #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 +#endif + +// Construct the namespace ABI tags component +#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b +#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ + NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) + +#define NLOHMANN_JSON_ABI_TAGS \ + NLOHMANN_JSON_ABI_TAGS_CONCAT( \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) + +// Construct the namespace version component +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ + _v ## major ## _ ## minor ## _ ## patch +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) + +#if NLOHMANN_JSON_NAMESPACE_NO_VERSION +#define NLOHMANN_JSON_NAMESPACE_VERSION +#else +#define NLOHMANN_JSON_NAMESPACE_VERSION \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH) +#endif + +// Combine namespace components +#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b +#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ + NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) + +#ifndef NLOHMANN_JSON_NAMESPACE +#define NLOHMANN_JSON_NAMESPACE \ + nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN +#define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann \ + { \ + inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) \ + { +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_END +#define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ + } // namespace nlohmann +#endif + + +/*! +@brief namespace for Niels Lohmann +@see https://github.com/nlohmann +@since version 1.0.0 +*/ +NLOHMANN_JSON_NAMESPACE_BEGIN + +/*! +@brief default JSONSerializer template argument + +This serializer ignores the template arguments and uses ADL +([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) +for serialization. +*/ +template +struct adl_serializer; + +/// a class to store JSON values +/// @sa https://json.nlohmann.me/api/basic_json/ +template class ObjectType = + std::map, + template class ArrayType = std::vector, + class StringType = std::string, class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template class AllocatorType = std::allocator, + template class JSONSerializer = + adl_serializer, + class BinaryType = std::vector> +class basic_json; + +/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document +/// @sa https://json.nlohmann.me/api/json_pointer/ +template +class json_pointer; + +/*! +@brief default specialization +@sa https://json.nlohmann.me/api/json/ +*/ +using json = basic_json<>; + +/// @brief a minimal map-like container that preserves insertion order +/// @sa https://json.nlohmann.me/api/ordered_map/ +template +struct ordered_map; + +/// @brief specialization that maintains the insertion order of object keys +/// @sa https://json.nlohmann.me/api/ordered_json/ +using ordered_json = basic_json; + +NLOHMANN_JSON_NAMESPACE_END + +#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 65b610f0e4..1afb000aed 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,7 +37,8 @@ endif() add_library(test_main OBJECT src/unit.cpp) target_compile_definitions(test_main PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS - JSON_TEST_KEEP_MACROS) + JSON_TEST_KEEP_MACROS + JSON_TEST_USING_MULTIPLE_HEADERS=$) target_compile_features(test_main PRIVATE cxx_std_11) target_compile_options(test_main PUBLIC $<$:/EHsc;$<$:/Od>> diff --git a/tests/abi/CMakeLists.txt b/tests/abi/CMakeLists.txt index c1ae5430a4..ba90837cb0 100644 --- a/tests/abi/CMakeLists.txt +++ b/tests/abi/CMakeLists.txt @@ -25,5 +25,6 @@ add_library(abi_compat_main STATIC main.cpp) target_link_libraries(abi_compat_main PUBLIC abi_compat_common) # add individual tests +add_subdirectory(config) add_subdirectory(diag) add_subdirectory(inline_ns) diff --git a/tests/abi/config/CMakeLists.txt b/tests/abi/config/CMakeLists.txt new file mode 100644 index 0000000000..3a83676903 --- /dev/null +++ b/tests/abi/config/CMakeLists.txt @@ -0,0 +1,22 @@ +# test the different options to change the namespace + +# test default namespace +add_executable(abi_config_default default.cpp) +target_link_libraries(abi_config_default PRIVATE abi_compat_main) +add_test( + NAME test-abi_config_default + COMMAND abi_config_default ${DOCTEST_TEST_FILTER}) + +# test no version namespace +add_executable(abi_config_noversion noversion.cpp) +target_link_libraries(abi_config_noversion PRIVATE abi_compat_main) +add_test( + NAME test-abi_config_noversion + COMMAND abi_config_noversion ${DOCTEST_TEST_FILTER}) + +# test custom namespace +add_executable(abi_config_custom custom.cpp) +target_link_libraries(abi_config_custom PRIVATE abi_compat_main) +add_test( + NAME test-abi_config_custom + COMMAND abi_config_custom ${DOCTEST_TEST_FILTER}) diff --git a/tests/abi/config/config.hpp b/tests/abi/config/config.hpp new file mode 100644 index 0000000000..57ea4e389d --- /dev/null +++ b/tests/abi/config/config.hpp @@ -0,0 +1,35 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + +#pragma once + +#include "doctest.h" + +#include +#include +#include + +#define STRINGIZE_EX(x) #x +#define STRINGIZE(x) STRINGIZE_EX(x) + +template +std::string namespace_name(std::string ns, T* /*unused*/ = nullptr) // NOLINT(performance-unnecessary-value-param) +{ +#if DOCTEST_MSVC && !DOCTEST_CLANG + ns = __FUNCSIG__; +#elif !DOCTEST_CLANG + ns = __PRETTY_FUNCTION__; +#endif + std::smatch m; + + // extract the true namespace name from the function signature + CAPTURE(ns); + CHECK(std::regex_search(ns, m, std::regex("nlohmann(::[a-zA-Z0-9_]+)*::basic_json"))); + + return m.str(); +} diff --git a/tests/abi/config/custom.cpp b/tests/abi/config/custom.cpp new file mode 100644 index 0000000000..a004fcca20 --- /dev/null +++ b/tests/abi/config/custom.cpp @@ -0,0 +1,33 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include "doctest_compatibility.h" + +#include "config.hpp" + +// define custom namespace +#define NLOHMANN_JSON_NAMESPACE nlohmann // this line may be omitted +#define NLOHMANN_JSON_NAMESPACE_BEGIN namespace nlohmann { +#define NLOHMANN_JSON_NAMESPACE_END } +#include + +TEST_CASE("custom namespace") +{ + // GCC 4.8 fails with regex_error +#if !DOCTEST_GCC || DOCTEST_GCC >= DOCTEST_COMPILER(4, 9, 0) + SECTION("namespace matches expectation") + { + std::string expected = "nlohmann::basic_json"; + + // fallback for Clang + std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"}; + + CHECK(namespace_name(ns) == expected); + } +#endif +} diff --git a/tests/abi/config/default.cpp b/tests/abi/config/default.cpp new file mode 100644 index 0000000000..908314acf3 --- /dev/null +++ b/tests/abi/config/default.cpp @@ -0,0 +1,41 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include "doctest_compatibility.h" + +#include "config.hpp" + +#include + +TEST_CASE("default namespace") +{ + // GCC 4.8 fails with regex_error +#if !DOCTEST_GCC || DOCTEST_GCC >= DOCTEST_COMPILER(4, 9, 0) + SECTION("namespace matches expectation") + { + std::string expected = "nlohmann::json_abi"; + +#if JSON_DIAGNOSTICS + expected += "_diag"; +#endif + +#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + expected += "_ldvcmp"; +#endif + + expected += "_v" STRINGIZE(NLOHMANN_JSON_VERSION_MAJOR); + expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_MINOR); + expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_PATCH) "::basic_json"; + + // fallback for Clang + std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"}; + + CHECK(namespace_name(ns) == expected); + } +#endif +} diff --git a/tests/abi/config/noversion.cpp b/tests/abi/config/noversion.cpp new file mode 100644 index 0000000000..d4fcb3f461 --- /dev/null +++ b/tests/abi/config/noversion.cpp @@ -0,0 +1,40 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include "doctest_compatibility.h" + +#include "config.hpp" + +#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 1 +#include + +TEST_CASE("default namespace without version component") +{ + // GCC 4.8 fails with regex_error +#if !DOCTEST_GCC || DOCTEST_GCC >= DOCTEST_COMPILER(4, 9, 0) + SECTION("namespace matches expectation") + { + std::string expected = "nlohmann::json_abi"; + +#if JSON_DIAGNOSTICS + expected += "_diag"; +#endif + +#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + expected += "_ldvcmp"; +#endif + + expected += "::basic_json"; + + // fallback for Clang + std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"}; + + CHECK(namespace_name(ns) == expected); + } +#endif +} diff --git a/tests/abi/diag/diag.cpp b/tests/abi/diag/diag.cpp index df554e72a2..1861f67065 100644 --- a/tests/abi/diag/diag.cpp +++ b/tests/abi/diag/diag.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/abi/diag/diag.hpp b/tests/abi/diag/diag.hpp index 4d1309ac7d..ebca6d06ef 100644 --- a/tests/abi/diag/diag.hpp +++ b/tests/abi/diag/diag.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/abi/diag/diag_off.cpp b/tests/abi/diag/diag_off.cpp index c5d8791b97..3c59db9514 100644 --- a/tests/abi/diag/diag_off.cpp +++ b/tests/abi/diag/diag_off.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/abi/diag/diag_on.cpp b/tests/abi/diag/diag_on.cpp index 005ac8ed93..9026230811 100644 --- a/tests/abi/diag/diag_on.cpp +++ b/tests/abi/diag/diag_on.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/abi/include/nlohmann/json_v3_10_5.hpp b/tests/abi/include/nlohmann/json_v3_10_5.hpp index cb27e05811..87995556e8 100644 --- a/tests/abi/include/nlohmann/json_v3_10_5.hpp +++ b/tests/abi/include/nlohmann/json_v3_10_5.hpp @@ -36,8 +36,8 @@ SOFTWARE. * file doc/README.md. * \****************************************************************************/ -#ifndef INCLUDE_NLOHMANN_JSON_HPP_ -#define INCLUDE_NLOHMANN_JSON_HPP_ +#ifndef INCLUDE_NLOHMANN_JSON_V3_10_5_HPP_ +#define INCLUDE_NLOHMANN_JSON_V3_10_5_HPP_ #define NLOHMANN_JSON_VERSION_MAJOR 3 #define NLOHMANN_JSON_VERSION_MINOR 10 @@ -22088,4 +22088,4 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std -#endif // INCLUDE_NLOHMANN_JSON_HPP_ +#endif // INCLUDE_NLOHMANN_JSON_V3_10_5_HPP_ diff --git a/tests/abi/inline_ns/use_current.cpp b/tests/abi/inline_ns/use_current.cpp index b3916642ba..2ec1ab367d 100644 --- a/tests/abi/inline_ns/use_current.cpp +++ b/tests/abi/inline_ns/use_current.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/abi/inline_ns/use_v3_10_5.cpp b/tests/abi/inline_ns/use_v3_10_5.cpp index 43d4624fce..d1b27ca75a 100644 --- a/tests/abi/inline_ns/use_v3_10_5.cpp +++ b/tests/abi/inline_ns/use_v3_10_5.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/abi/main.cpp b/tests/abi/main.cpp index d1a6fde551..54c4b6ca45 100644 --- a/tests/abi/main.cpp +++ b/tests/abi/main.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // Copyright (c) 2013-2022 Niels Lohmann . diff --git a/tests/benchmarks/src/benchmarks.cpp b/tests/benchmarks/src/benchmarks.cpp index 2f30619ae3..6c3d4d5a79 100644 --- a/tests/benchmarks/src/benchmarks.cpp +++ b/tests/benchmarks/src/benchmarks.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cmake_add_subdirectory/project/main.cpp b/tests/cmake_add_subdirectory/project/main.cpp index 91e83a9e3a..eff2ecfacc 100644 --- a/tests/cmake_add_subdirectory/project/main.cpp +++ b/tests/cmake_add_subdirectory/project/main.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cmake_fetch_content/project/main.cpp b/tests/cmake_fetch_content/project/main.cpp index 91e83a9e3a..eff2ecfacc 100644 --- a/tests/cmake_fetch_content/project/main.cpp +++ b/tests/cmake_fetch_content/project/main.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cmake_fetch_content2/project/main.cpp b/tests/cmake_fetch_content2/project/main.cpp index 91e83a9e3a..eff2ecfacc 100644 --- a/tests/cmake_fetch_content2/project/main.cpp +++ b/tests/cmake_fetch_content2/project/main.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cmake_import/project/main.cpp b/tests/cmake_import/project/main.cpp index 91e83a9e3a..eff2ecfacc 100644 --- a/tests/cmake_import/project/main.cpp +++ b/tests/cmake_import/project/main.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cmake_import_minver/project/main.cpp b/tests/cmake_import_minver/project/main.cpp index 91e83a9e3a..eff2ecfacc 100644 --- a/tests/cmake_import_minver/project/main.cpp +++ b/tests/cmake_import_minver/project/main.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cmake_target_include_directories/project/Bar.cpp b/tests/cmake_target_include_directories/project/Bar.cpp index b46ab75045..49c54d7bd6 100644 --- a/tests/cmake_target_include_directories/project/Bar.cpp +++ b/tests/cmake_target_include_directories/project/Bar.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cmake_target_include_directories/project/Bar.hpp b/tests/cmake_target_include_directories/project/Bar.hpp index 8d4dae89ad..6184c5a2c1 100644 --- a/tests/cmake_target_include_directories/project/Bar.hpp +++ b/tests/cmake_target_include_directories/project/Bar.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cmake_target_include_directories/project/Foo.cpp b/tests/cmake_target_include_directories/project/Foo.cpp index c85b56d776..18807889da 100644 --- a/tests/cmake_target_include_directories/project/Foo.cpp +++ b/tests/cmake_target_include_directories/project/Foo.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cmake_target_include_directories/project/Foo.hpp b/tests/cmake_target_include_directories/project/Foo.hpp index 09ac38db46..9a387dc133 100644 --- a/tests/cmake_target_include_directories/project/Foo.hpp +++ b/tests/cmake_target_include_directories/project/Foo.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cmake_target_include_directories/project/main.cpp b/tests/cmake_target_include_directories/project/main.cpp index 91e83a9e3a..eff2ecfacc 100644 --- a/tests/cmake_target_include_directories/project/main.cpp +++ b/tests/cmake_target_include_directories/project/main.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/cuda_example/json_cuda.cu b/tests/cuda_example/json_cuda.cu index d247634449..7b965098b8 100644 --- a/tests/cuda_example/json_cuda.cu +++ b/tests/cuda_example/json_cuda.cu @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/fuzzer-driver_afl.cpp b/tests/src/fuzzer-driver_afl.cpp index b0878a0f4e..2fe65b919a 100644 --- a/tests/src/fuzzer-driver_afl.cpp +++ b/tests/src/fuzzer-driver_afl.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/fuzzer-parse_bjdata.cpp b/tests/src/fuzzer-parse_bjdata.cpp index c06c8e06d8..abecead44f 100644 --- a/tests/src/fuzzer-parse_bjdata.cpp +++ b/tests/src/fuzzer-parse_bjdata.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/fuzzer-parse_bson.cpp b/tests/src/fuzzer-parse_bson.cpp index e2e47155a9..56e677c3f6 100644 --- a/tests/src/fuzzer-parse_bson.cpp +++ b/tests/src/fuzzer-parse_bson.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/fuzzer-parse_cbor.cpp b/tests/src/fuzzer-parse_cbor.cpp index 2586ec2f25..3e05e0ad0f 100644 --- a/tests/src/fuzzer-parse_cbor.cpp +++ b/tests/src/fuzzer-parse_cbor.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/fuzzer-parse_json.cpp b/tests/src/fuzzer-parse_json.cpp index a88e2b98ea..cdad1462be 100644 --- a/tests/src/fuzzer-parse_json.cpp +++ b/tests/src/fuzzer-parse_json.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/fuzzer-parse_msgpack.cpp b/tests/src/fuzzer-parse_msgpack.cpp index 39db376abe..7855b42a7b 100644 --- a/tests/src/fuzzer-parse_msgpack.cpp +++ b/tests/src/fuzzer-parse_msgpack.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/fuzzer-parse_ubjson.cpp b/tests/src/fuzzer-parse_ubjson.cpp index 2728c51037..a3f1e9f74b 100644 --- a/tests/src/fuzzer-parse_ubjson.cpp +++ b/tests/src/fuzzer-parse_ubjson.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/make_test_data_available.hpp b/tests/src/make_test_data_available.hpp index ef9fc62ca7..83b926621c 100644 --- a/tests/src/make_test_data_available.hpp +++ b/tests/src/make_test_data_available.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/test_utils.hpp b/tests/src/test_utils.hpp index 198222de76..15e87973e9 100644 --- a/tests/src/test_utils.hpp +++ b/tests/src/test_utils.hpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-32bit.cpp b/tests/src/unit-32bit.cpp index 82e6f33b23..3ff6277e84 100644 --- a/tests/src/unit-32bit.cpp +++ b/tests/src/unit-32bit.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index d10c14dcf2..f4b87f8fa3 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-allocator.cpp b/tests/src/unit-allocator.cpp index 9e5edc4f82..c6b77ed669 100644 --- a/tests/src/unit-allocator.cpp +++ b/tests/src/unit-allocator.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-alt-string.cpp b/tests/src/unit-alt-string.cpp index 0c94d0fb94..609b5d159b 100644 --- a/tests/src/unit-alt-string.cpp +++ b/tests/src/unit-alt-string.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-assert_macro.cpp b/tests/src/unit-assert_macro.cpp index e9be6b5e25..7189119c08 100644 --- a/tests/src/unit-assert_macro.cpp +++ b/tests/src/unit-assert_macro.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-binary_formats.cpp b/tests/src/unit-binary_formats.cpp index 896bc1bdb8..463360ad5e 100644 --- a/tests/src/unit-binary_formats.cpp +++ b/tests/src/unit-binary_formats.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 74e331f75c..41b78742bd 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -8,11 +8,13 @@ #include "doctest_compatibility.h" -#include -#include +#define JSON_TESTS_PRIVATE #include using nlohmann::json; +#include +#include +#include #include #include #include @@ -205,6 +207,17 @@ TEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, \ TEST_CASE("BJData") { + SECTION("binary_reader BJData LUT arrays are sorted") + { + std::vector data; + auto ia = nlohmann::detail::input_adapter(data); + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + nlohmann::detail::binary_reader br{std::move(ia), json::input_format_t::bjdata}; + + CHECK(std::is_sorted(br.bjd_optimized_type_markers.begin(), br.bjd_optimized_type_markers.end())); + CHECK(std::is_sorted(br.bjd_types_map.begin(), br.bjd_types_map.end())); + } + SECTION("individual values") { SECTION("discarded") diff --git a/tests/src/unit-bson.cpp b/tests/src/unit-bson.cpp index 05fe8d3e8f..a231c8cca3 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-byte_container_with_subtype.cpp b/tests/src/unit-byte_container_with_subtype.cpp index c651273fe5..ba8eab27fa 100644 --- a/tests/src/unit-byte_container_with_subtype.cpp +++ b/tests/src/unit-byte_container_with_subtype.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // Copyright (c) 2013-2022 Niels Lohmann . diff --git a/tests/src/unit-capacity.cpp b/tests/src/unit-capacity.cpp index 858e111ad4..2f644a1f0e 100644 --- a/tests/src/unit-capacity.cpp +++ b/tests/src/unit-capacity.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // Copyright (c) 2013-2022 Niels Lohmann . diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index 78bdeb2b9f..ffa3e92d89 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-class_const_iterator.cpp b/tests/src/unit-class_const_iterator.cpp index 8e0bc823ea..3c5ba053f7 100644 --- a/tests/src/unit-class_const_iterator.cpp +++ b/tests/src/unit-class_const_iterator.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-class_iterator.cpp b/tests/src/unit-class_iterator.cpp index 7568d927da..8a36c18a74 100644 --- a/tests/src/unit-class_iterator.cpp +++ b/tests/src/unit-class_iterator.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-class_lexer.cpp b/tests/src/unit-class_lexer.cpp index 9991b355eb..30d4e5e1b5 100644 --- a/tests/src/unit-class_lexer.cpp +++ b/tests/src/unit-class_lexer.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-class_parser.cpp b/tests/src/unit-class_parser.cpp index 86dd85a7fe..0193b4b89f 100644 --- a/tests/src/unit-class_parser.cpp +++ b/tests/src/unit-class_parser.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-comparison.cpp b/tests/src/unit-comparison.cpp index f713c980a4..b838c02f21 100644 --- a/tests/src/unit-comparison.cpp +++ b/tests/src/unit-comparison.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-concepts.cpp b/tests/src/unit-concepts.cpp index c179b0c3c3..3a0c81b051 100644 --- a/tests/src/unit-concepts.cpp +++ b/tests/src/unit-concepts.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-constructor1.cpp b/tests/src/unit-constructor1.cpp index f294e5cd64..791fb60b3a 100644 --- a/tests/src/unit-constructor1.cpp +++ b/tests/src/unit-constructor1.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -454,10 +454,19 @@ TEST_CASE("constructors") CHECK(j.type() == json::value_t::boolean); } - SECTION("from std::vector::refrence") + SECTION("from std::vector::reference") { std::vector v{true}; json j(v[0]); + CHECK(std::is_same::reference>::value); + CHECK(j.type() == json::value_t::boolean); + } + + SECTION("from std::vector::const_reference") + { + const std::vector v{true}; + json j(v[0]); + CHECK(std::is_same::const_reference>::value); CHECK(j.type() == json::value_t::boolean); } } diff --git a/tests/src/unit-constructor2.cpp b/tests/src/unit-constructor2.cpp index b1b5a6ed46..7932caeffa 100644 --- a/tests/src/unit-constructor2.cpp +++ b/tests/src/unit-constructor2.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-convenience.cpp b/tests/src/unit-convenience.cpp index fcb7723200..d60d1a00e7 100644 --- a/tests/src/unit-convenience.cpp +++ b/tests/src/unit-convenience.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-conversions.cpp b/tests/src/unit-conversions.cpp index d86b614c45..78ed3bb3eb 100644 --- a/tests/src/unit-conversions.cpp +++ b/tests/src/unit-conversions.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // Copyright (c) 2013-2022 Niels Lohmann . diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp index 3616f35c57..86640fd3f9 100644 --- a/tests/src/unit-deserialization.cpp +++ b/tests/src/unit-deserialization.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // Copyright (c) 2013-2022 Niels Lohmann . diff --git a/tests/src/unit-diagnostics.cpp b/tests/src/unit-diagnostics.cpp index a1aff57afa..0b8e4dbe30 100644 --- a/tests/src/unit-diagnostics.cpp +++ b/tests/src/unit-diagnostics.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // Copyright (c) 2013-2022 Niels Lohmann . diff --git a/tests/src/unit-disabled_exceptions.cpp b/tests/src/unit-disabled_exceptions.cpp index 6a7d5000df..45af2aed75 100644 --- a/tests/src/unit-disabled_exceptions.cpp +++ b/tests/src/unit-disabled_exceptions.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // Copyright (c) 2013-2022 Niels Lohmann . diff --git a/tests/src/unit-element_access1.cpp b/tests/src/unit-element_access1.cpp index f28f2f9f27..af70b94a48 100644 --- a/tests/src/unit-element_access1.cpp +++ b/tests/src/unit-element_access1.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // Copyright (c) 2013-2022 Niels Lohmann . diff --git a/tests/src/unit-element_access2.cpp b/tests/src/unit-element_access2.cpp index 5f28e5a2c3..165b24b464 100644 --- a/tests/src/unit-element_access2.cpp +++ b/tests/src/unit-element_access2.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // Copyright (c) 2013-2022 Niels Lohmann . @@ -14,6 +14,9 @@ using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif +// build test with C++14 +// JSON_HAS_CPP_14 + TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_json) { SECTION("object") @@ -1488,3 +1491,304 @@ TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nl } } #endif + +// TODO(falbrechtskirchinger) merge with the other test case; clean up +TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann::json, nlohmann::ordered_json) +{ + using string_t = typename Json::string_t; + using number_integer_t = typename Json::number_integer_t; + + // test assumes string_t and object_t::key_type are the same + REQUIRE(std::is_same::value); + + Json j + { + {"foo", "bar"}, + {"baz", 42} + }; + + const char* cpstr = "default"; + const char castr[] = "default"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + string_t str = "default"; + + number_integer_t integer = 69; + std::size_t size = 69; + + SECTION("deduced ValueType") + { + SECTION("literal key") + { + CHECK(j.value("foo", "default") == "bar"); + CHECK(j.value("foo", cpstr) == "bar"); + CHECK(j.value("foo", castr) == "bar"); + CHECK(j.value("foo", str) == "bar"); + // this test is in fact different than the one below, + // because of 0 considering const char * overloads + // where as any other number does not + CHECK(j.value("baz", 0) == 42); + CHECK(j.value("baz", 47) == 42); + CHECK(j.value("baz", integer) == 42); + CHECK(j.value("baz", size) == 42); + + CHECK(j.value("bar", "default") == "default"); + CHECK(j.value("bar", 0) == 0); + CHECK(j.value("bar", 47) == 47); + CHECK(j.value("bar", integer) == integer); + CHECK(j.value("bar", size) == size); + + CHECK_THROWS_WITH_AS(Json().value("foo", "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().value("foo", str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } + + SECTION("const char * key") + { + const char* key = "foo"; + const char* key2 = "baz"; + const char* key_notfound = "bar"; + + CHECK(j.value(key, "default") == "bar"); + CHECK(j.value(key, cpstr) == "bar"); + CHECK(j.value(key, castr) == "bar"); + CHECK(j.value(key, str) == "bar"); + CHECK(j.value(key2, 0) == 42); + CHECK(j.value(key2, 47) == 42); + CHECK(j.value(key2, integer) == 42); + CHECK(j.value(key2, size) == 42); + + CHECK(j.value(key_notfound, "default") == "default"); + CHECK(j.value(key_notfound, 0) == 0); + CHECK(j.value(key_notfound, 47) == 47); + CHECK(j.value(key_notfound, integer) == integer); + CHECK(j.value(key_notfound, size) == size); + + CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } + + SECTION("const char(&)[] key") + { + const char key[] = "foo"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + const char key2[] = "baz"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + const char key_notfound[] = "bar"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + + CHECK(j.value(key, "default") == "bar"); + CHECK(j.value(key, cpstr) == "bar"); + CHECK(j.value(key, castr) == "bar"); + CHECK(j.value(key, str) == "bar"); + CHECK(j.value(key2, 0) == 42); + CHECK(j.value(key2, 47) == 42); + CHECK(j.value(key2, integer) == 42); + CHECK(j.value(key2, size) == 42); + + CHECK(j.value(key_notfound, "default") == "default"); + CHECK(j.value(key_notfound, 0) == 0); + CHECK(j.value(key_notfound, 47) == 47); + CHECK(j.value(key_notfound, integer) == integer); + CHECK(j.value(key_notfound, size) == size); + + CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } + + SECTION("string_t/object_t::key_type key") + { + string_t key = "foo"; + string_t key2 = "baz"; + string_t key_notfound = "bar"; + + CHECK(j.value(key, "default") == "bar"); + CHECK(j.value(key, cpstr) == "bar"); + CHECK(j.value(key, castr) == "bar"); + CHECK(j.value(key, str) == "bar"); + CHECK(j.value(key2, 0) == 42); + CHECK(j.value(key2, 47) == 42); + CHECK(j.value(key2, integer) == 42); + CHECK(j.value(key2, size) == 42); + + CHECK(j.value(key_notfound, "default") == "default"); + CHECK(j.value(key_notfound, 0) == 0); + CHECK(j.value(key_notfound, 47) == 47); + CHECK(j.value(key_notfound, integer) == integer); + CHECK(j.value(key_notfound, size) == size); + + CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } + +#ifdef JSON_HAS_CPP_17 + SECTION("std::string_view key") + { + std::string_view key = "foo"; + std::string_view key2 = "baz"; + std::string_view key_notfound = "bar"; + + CHECK(j.value(key, "default") == "bar"); + CHECK(j.value(key, cpstr) == "bar"); + CHECK(j.value(key, castr) == "bar"); + CHECK(j.value(key, str) == "bar"); + CHECK(j.value(key2, 0) == 42); + CHECK(j.value(key2, 47) == 42); + CHECK(j.value(key2, integer) == 42); + CHECK(j.value(key2, size) == 42); + + CHECK(j.value(key_notfound, "default") == "default"); + CHECK(j.value(key_notfound, 0) == 0); + CHECK(j.value(key_notfound, 47) == 47); + CHECK(j.value(key_notfound, integer) == integer); + CHECK(j.value(key_notfound, size) == size); + + CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } +#endif + } + + SECTION("explicit ValueType") + { + SECTION("literal key") + { + CHECK(j.template value("foo", "default") == "bar"); + CHECK(j.template value("foo", cpstr) == "bar"); + CHECK(j.template value("foo", castr) == "bar"); + CHECK(j.template value("foo", str) == "bar"); + CHECK(j.template value("baz", 0) == 42); + CHECK(j.template value("baz", 47) == 42); + CHECK(j.template value("baz", integer) == 42); + CHECK(j.template value("baz", 0) == 42); + CHECK(j.template value("baz", 47) == 42); + CHECK(j.template value("baz", size) == 42); + + CHECK(j.template value("bar", "default") == "default"); + CHECK(j.template value("bar", 0) == 0); + CHECK(j.template value("bar", 47) == 47); + CHECK(j.template value("bar", integer) == integer); + CHECK(j.template value("bar", 0) == 0); + CHECK(j.template value("bar", 47) == 47); + CHECK(j.template value("bar", size) == size); + + CHECK_THROWS_WITH_AS(Json().template value("foo", "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().template value("foo", str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } + + SECTION("const char * key") + { + const char* key = "foo"; + const char* key2 = "baz"; + const char* key_notfound = "bar"; + + CHECK(j.template value(key, "default") == "bar"); + CHECK(j.template value(key, cpstr) == "bar"); + CHECK(j.template value(key, castr) == "bar"); + CHECK(j.template value(key, str) == "bar"); + CHECK(j.template value(key2, 0) == 42); + CHECK(j.template value(key2, 47) == 42); + CHECK(j.template value(key2, integer) == 42); + CHECK(j.template value(key2, 0) == 42); + CHECK(j.template value(key2, 47) == 42); + CHECK(j.template value(key2, size) == 42); + + CHECK(j.template value(key_notfound, "default") == "default"); + CHECK(j.template value(key_notfound, 0) == 0); + CHECK(j.template value(key_notfound, 47) == 47); + CHECK(j.template value(key_notfound, integer) == integer); + CHECK(j.template value(key_notfound, 0) == 0); + CHECK(j.template value(key_notfound, 47) == 47); + CHECK(j.template value(key_notfound, size) == size); + + CHECK_THROWS_WITH_AS(Json().template value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().template value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } + + SECTION("const char(&)[] key") + { + const char key[] = "foo"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + const char key2[] = "baz"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + const char key_notfound[] = "bar"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + + CHECK(j.template value(key, "default") == "bar"); + CHECK(j.template value(key, cpstr) == "bar"); + CHECK(j.template value(key, castr) == "bar"); + CHECK(j.template value(key, str) == "bar"); + CHECK(j.template value(key2, 0) == 42); + CHECK(j.template value(key2, 47) == 42); + CHECK(j.template value(key2, integer) == 42); + CHECK(j.template value(key2, 0) == 42); + CHECK(j.template value(key2, 47) == 42); + CHECK(j.template value(key2, size) == 42); + + CHECK(j.template value(key_notfound, "default") == "default"); + CHECK(j.template value(key_notfound, 0) == 0); + CHECK(j.template value(key_notfound, 47) == 47); + CHECK(j.template value(key_notfound, integer) == integer); + CHECK(j.template value(key_notfound, 0) == 0); + CHECK(j.template value(key_notfound, 47) == 47); + CHECK(j.template value(key_notfound, size) == size); + + CHECK_THROWS_WITH_AS(Json().template value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().template value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } + + SECTION("string_t/object_t::key_type key") + { + string_t key = "foo"; + string_t key2 = "baz"; + string_t key_notfound = "bar"; + + CHECK(j.template value(key, "default") == "bar"); + CHECK(j.template value(key, cpstr) == "bar"); + CHECK(j.template value(key, castr) == "bar"); + CHECK(j.template value(key, str) == "bar"); + CHECK(j.template value(key2, 0) == 42); + CHECK(j.template value(key2, 47) == 42); + CHECK(j.template value(key2, 0) == 42); + CHECK(j.template value(key2, 47) == 42); + + CHECK(j.template value(key_notfound, "default") == "default"); + CHECK(j.template value(key_notfound, 0) == 0); + CHECK(j.template value(key_notfound, 47) == 47); + CHECK(j.template value(key_notfound, 0) == 0); + CHECK(j.template value(key_notfound, 47) == 47); + + CHECK_THROWS_WITH_AS(Json().template value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().template value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } + +#ifdef JSON_HAS_CPP_17 + SECTION("std::string_view key") + { + std::string_view key = "foo"; + std::string_view key2 = "baz"; + std::string_view key_notfound = "bar"; + + CHECK(j.template value(key, "default") == "bar"); + CHECK(j.template value(key, cpstr) == "bar"); + CHECK(j.template value(key, castr) == "bar"); + CHECK(j.template value(key, str) == "bar"); + CHECK(j.template value(key2, 0) == 42); + CHECK(j.template value(key2, 47) == 42); + CHECK(j.template value(key2, integer) == 42); + CHECK(j.template value(key2, 0) == 42); + CHECK(j.template value(key2, 47) == 42); + CHECK(j.template value(key2, size) == 42); + + CHECK(j.template value(key_notfound, "default") == "default"); + CHECK(j.template value(key_notfound, 0) == 0); + CHECK(j.template value(key_notfound, 47) == 47); + CHECK(j.template value(key_notfound, integer) == integer); + CHECK(j.template value(key_notfound, 0) == 0); + CHECK(j.template value(key_notfound, 47) == 47); + CHECK(j.template value(key_notfound, size) == size); + + CHECK(j.template value(key, "default") == "bar"); + CHECK(j.template value(key, cpstr) == "bar"); + CHECK(j.template value(key, castr) == "bar"); + CHECK(j.template value(key, str) == "bar"); + + CHECK(j.template value(key_notfound, "default") == "default"); + + CHECK_THROWS_WITH_AS(Json().template value(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + CHECK_THROWS_WITH_AS(Json().template value(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&); + } +#endif + } +} diff --git a/tests/src/unit-hash.cpp b/tests/src/unit-hash.cpp index 1ed21bd396..9363d62358 100644 --- a/tests/src/unit-hash.cpp +++ b/tests/src/unit-hash.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-inspection.cpp b/tests/src/unit-inspection.cpp index c5ea684d0c..312292585d 100644 --- a/tests/src/unit-inspection.cpp +++ b/tests/src/unit-inspection.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-items.cpp b/tests/src/unit-items.cpp index 55d9edd395..63e6a38a11 100644 --- a/tests/src/unit-items.cpp +++ b/tests/src/unit-items.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-iterators1.cpp b/tests/src/unit-iterators1.cpp index 14bbdf844a..9337c5a212 100644 --- a/tests/src/unit-iterators1.cpp +++ b/tests/src/unit-iterators1.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-iterators2.cpp b/tests/src/unit-iterators2.cpp index 57326a2895..27926084c7 100644 --- a/tests/src/unit-iterators2.cpp +++ b/tests/src/unit-iterators2.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-json_patch.cpp b/tests/src/unit-json_patch.cpp index 3be0f8ecf9..d1a994b93f 100644 --- a/tests/src/unit-json_patch.cpp +++ b/tests/src/unit-json_patch.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-json_pointer.cpp b/tests/src/unit-json_pointer.cpp index 93559eb31e..703289721f 100644 --- a/tests/src/unit-json_pointer.cpp +++ b/tests/src/unit-json_pointer.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -15,6 +15,7 @@ using nlohmann::json; using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif +#include #include TEST_CASE("JSON pointers") @@ -651,11 +652,76 @@ TEST_CASE("JSON pointers") SECTION("equality comparison") { - auto ptr1 = json::json_pointer("/foo/bar"); - auto ptr2 = json::json_pointer("/foo/bar"); + const char* ptr_cpstring = "/foo/bar"; + const char ptr_castring[] = "/foo/bar"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + std::string ptr_string{"/foo/bar"}; + auto ptr1 = json::json_pointer(ptr_string); + auto ptr2 = json::json_pointer(ptr_string); + + // build with C++20 to test rewritten candidates + // JSON_HAS_CPP_20 CHECK(ptr1 == ptr2); + + CHECK(ptr1 == "/foo/bar"); + CHECK(ptr1 == ptr_cpstring); + CHECK(ptr1 == ptr_castring); + CHECK(ptr1 == ptr_string); + + CHECK("/foo/bar" == ptr1); + CHECK(ptr_cpstring == ptr1); + CHECK(ptr_castring == ptr1); + CHECK(ptr_string == ptr1); + CHECK_FALSE(ptr1 != ptr2); + + CHECK_FALSE(ptr1 != "/foo/bar"); + CHECK_FALSE(ptr1 != ptr_cpstring); + CHECK_FALSE(ptr1 != ptr_castring); + CHECK_FALSE(ptr1 != ptr_string); + + CHECK_FALSE("/foo/bar" != ptr1); + CHECK_FALSE(ptr_cpstring != ptr1); + CHECK_FALSE(ptr_castring != ptr1); + CHECK_FALSE(ptr_string != ptr1); + + SECTION("exceptions") + { + CHECK_THROWS_WITH_AS(ptr1 == "foo", + "[json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'", json::parse_error&); + CHECK_THROWS_WITH_AS("foo" == ptr1, + "[json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'", json::parse_error&); + CHECK_THROWS_WITH_AS(ptr1 == "/~~", + "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'", json::parse_error&); + CHECK_THROWS_WITH_AS("/~~" == ptr1, + "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'", json::parse_error&); + } + } + + SECTION("less-than comparison") + { + auto ptr1 = json::json_pointer("/foo/a"); + auto ptr2 = json::json_pointer("/foo/b"); + + CHECK(ptr1 < ptr2); + CHECK_FALSE(ptr2 < ptr1); + + // build with C++20 + // JSON_HAS_CPP_20 +#if JSON_HAS_THREE_WAY_COMPARISON + CHECK((ptr1 <=> ptr2) == std::strong_ordering::less); // *NOPAD* + CHECK(ptr2 > ptr1); +#endif + } + + SECTION("usable as map key") + { + auto ptr = json::json_pointer("/foo"); + std::map m; + + m[ptr] = 42; + + CHECK(m.find(ptr) != m.end()); } SECTION("backwards compatibility and mixing") @@ -676,9 +742,10 @@ TEST_CASE("JSON pointers") CHECK(std::is_same::value); CHECK(std::is_same::value); - json_ptr_str ptr{"/foo/0"}; - json_ptr_j ptr_j{"/foo/0"}; - json_ptr_oj ptr_oj{"/foo/0"}; + std::string ptr_string{"/foo/0"}; + json_ptr_str ptr{ptr_string}; + json_ptr_j ptr_j{ptr_string}; + json_ptr_oj ptr_oj{ptr_string}; CHECK(j.contains(ptr)); CHECK(j.contains(ptr_j)); @@ -697,5 +764,25 @@ TEST_CASE("JSON pointers") CHECK(ptr == ptr_oj); CHECK_FALSE(ptr != ptr_j); CHECK_FALSE(ptr != ptr_oj); + + SECTION("equality comparison") + { + // build with C++20 to test rewritten candidates + // JSON_HAS_CPP_20 + + CHECK(ptr == ptr_j); + CHECK(ptr == ptr_oj); + CHECK(ptr_j == ptr); + CHECK(ptr_j == ptr_oj); + CHECK(ptr_oj == ptr_j); + CHECK(ptr_oj == ptr); + + CHECK_FALSE(ptr != ptr_j); + CHECK_FALSE(ptr != ptr_oj); + CHECK_FALSE(ptr_j != ptr); + CHECK_FALSE(ptr_j != ptr_oj); + CHECK_FALSE(ptr_oj != ptr_j); + CHECK_FALSE(ptr_oj != ptr); + } } } diff --git a/tests/src/unit-large_json.cpp b/tests/src/unit-large_json.cpp index 69f47df64e..5db98116a8 100644 --- a/tests/src/unit-large_json.cpp +++ b/tests/src/unit-large_json.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-merge_patch.cpp b/tests/src/unit-merge_patch.cpp index 5098d12784..cc87bee91e 100644 --- a/tests/src/unit-merge_patch.cpp +++ b/tests/src/unit-merge_patch.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-meta.cpp b/tests/src/unit-meta.cpp index ad3a841c69..7cfc39eeda 100644 --- a/tests/src/unit-meta.cpp +++ b/tests/src/unit-meta.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -22,10 +22,10 @@ TEST_CASE("version information") CHECK(j["url"] == "https://github.com/nlohmann/json"); CHECK(j["version"] == json( { - {"string", "3.11.1"}, + {"string", "3.11.2"}, {"major", 3}, {"minor", 11}, - {"patch", 1} + {"patch", 2} })); CHECK(j.find("platform") != j.end()); diff --git a/tests/src/unit-modifiers.cpp b/tests/src/unit-modifiers.cpp index 8b06f1809e..fa4d17b5be 100644 --- a/tests/src/unit-modifiers.cpp +++ b/tests/src/unit-modifiers.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // Copyright (c) 2013-2022 Niels Lohmann . diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index d0e5ff3d5b..0f7aab8da1 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-noexcept.cpp b/tests/src/unit-noexcept.cpp index 89a7db7b06..2cac058ce9 100644 --- a/tests/src/unit-noexcept.cpp +++ b/tests/src/unit-noexcept.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-ordered_json.cpp b/tests/src/unit-ordered_json.cpp index 3ce0aa1553..c8f425b4ce 100644 --- a/tests/src/unit-ordered_json.cpp +++ b/tests/src/unit-ordered_json.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-ordered_map.cpp b/tests/src/unit-ordered_map.cpp index d907263b48..f9e6302b66 100644 --- a/tests/src/unit-ordered_map.cpp +++ b/tests/src/unit-ordered_map.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-pointer_access.cpp b/tests/src/unit-pointer_access.cpp index b48a4297c6..11cee65a5c 100644 --- a/tests/src/unit-pointer_access.cpp +++ b/tests/src/unit-pointer_access.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-readme.cpp b/tests/src/unit-readme.cpp index 6d296f02f0..1c20614591 100644 --- a/tests/src/unit-readme.cpp +++ b/tests/src/unit-readme.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann @@ -106,12 +106,10 @@ TEST_CASE("README" * doctest::skip()) json j = "{ \"happy\": true, \"pi\": 3.141 }"_json; // NOLINT(modernize-raw-string-literal) // or even nicer with a raw string literal - auto j2 = R"( - { - "happy": true, - "pi": 3.141 - } - )"_json; + auto j2 = R"({ + "happy": true, + "pi": 3.141 + })"_json; // or explicitly auto j3 = json::parse(R"({"happy": true, "pi": 3.141})"); @@ -160,10 +158,10 @@ TEST_CASE("README" * doctest::skip()) CHECK(foo == true); // other stuff - j.size(); // 3 entries - j.empty(); // false - j.type(); // json::value_t::array - j.clear(); // the array is empty again + CHECK(j.size() == 3); // 3 entries + CHECK_FALSE(j.empty()); // false + CHECK(j.type() == json::value_t::array); // json::value_t::array + j.clear(); // the array is empty again // create an object json o; @@ -172,6 +170,7 @@ TEST_CASE("README" * doctest::skip()) o["baz"] = 3.141; // find an entry + CHECK(o.find("foo") != o.end()); if (o.find("foo") != o.end()) { // there is an entry with key "foo" @@ -266,9 +265,9 @@ TEST_CASE("README" * doctest::skip()) { // a JSON value json j_original = R"({ - "baz": ["one", "two", "three"], - "foo": "bar" - })"_json; + "baz": ["one", "two", "three"], + "foo": "bar" + })"_json; // access members with a JSON pointer (RFC 6901) j_original["/baz/1"_json_pointer]; @@ -276,10 +275,10 @@ TEST_CASE("README" * doctest::skip()) // a JSON patch (RFC 6902) json j_patch = R"([ - { "op": "replace", "path": "/baz", "value": "boo" }, - { "op": "add", "path": "/hello", "value": ["world"] }, - { "op": "remove", "path": "/foo"} - ])"_json; + { "op": "replace", "path": "/baz", "value": "boo" }, + { "op": "add", "path": "/hello", "value": ["world"] }, + { "op": "remove", "path": "/foo"} + ])"_json; // apply the patch json j_result = j_original.patch(j_patch); diff --git a/tests/src/unit-reference_access.cpp b/tests/src/unit-reference_access.cpp index abe8bd1f5c..5f450ec2ce 100644 --- a/tests/src/unit-reference_access.cpp +++ b/tests/src/unit-reference_access.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index 45c4bd6209..ee7f8bc12c 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 73c8f3906f..503d2a4f8d 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-serialization.cpp b/tests/src/unit-serialization.cpp index 50dc58b4cc..a023d23d97 100644 --- a/tests/src/unit-serialization.cpp +++ b/tests/src/unit-serialization.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-testsuites.cpp b/tests/src/unit-testsuites.cpp index 268a483276..48cb072553 100644 --- a/tests/src/unit-testsuites.cpp +++ b/tests/src/unit-testsuites.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-to_chars.cpp b/tests/src/unit-to_chars.cpp index 44d4f38018..0d5fcd4226 100644 --- a/tests/src/unit-to_chars.cpp +++ b/tests/src/unit-to_chars.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-type_traits.cpp b/tests/src/unit-type_traits.cpp new file mode 100644 index 0000000000..25ec59668b --- /dev/null +++ b/tests/src/unit-type_traits.cpp @@ -0,0 +1,56 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include "doctest_compatibility.h" + +#if JSON_TEST_USING_MULTIPLE_HEADERS + #include +#else + #include +#endif + +TEST_CASE("type traits") +{ + SECTION("is_c_string") + { + using nlohmann::detail::is_c_string; + using nlohmann::detail::is_c_string_uncvref; + + SECTION("char *") + { + CHECK(is_c_string::value); + CHECK(is_c_string::value); + CHECK(is_c_string::value); + CHECK(is_c_string::value); + + CHECK_FALSE(is_c_string::value); + CHECK_FALSE(is_c_string::value); + CHECK_FALSE(is_c_string::value); + CHECK_FALSE(is_c_string::value); + + CHECK(is_c_string_uncvref::value); + CHECK(is_c_string_uncvref::value); + CHECK(is_c_string_uncvref::value); + CHECK(is_c_string_uncvref::value); + } + + SECTION("char[]") + { + // NOLINTBEGIN(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + CHECK(is_c_string::value); + CHECK(is_c_string::value); + + CHECK_FALSE(is_c_string::value); + CHECK_FALSE(is_c_string::value); + + CHECK(is_c_string_uncvref::value); + CHECK(is_c_string_uncvref::value); + // NOLINTEND(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + } + } +} diff --git a/tests/src/unit-ubjson.cpp b/tests/src/unit-ubjson.cpp index 5086149ce6..8045ba9926 100644 --- a/tests/src/unit-ubjson.cpp +++ b/tests/src/unit-ubjson.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-udl.cpp b/tests/src/unit-udl.cpp index 9347443648..a1cd42dbc2 100644 --- a/tests/src/unit-udl.cpp +++ b/tests/src/unit-udl.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-udt.cpp b/tests/src/unit-udt.cpp index 681536f95a..c95de4199e 100644 --- a/tests/src/unit-udt.cpp +++ b/tests/src/unit-udt.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-udt_macro.cpp b/tests/src/unit-udt_macro.cpp index eed81cdfa8..e52412bf91 100644 --- a/tests/src/unit-udt_macro.cpp +++ b/tests/src/unit-udt_macro.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-unicode1.cpp b/tests/src/unit-unicode1.cpp index 03c5b8006e..0b87cfa9de 100644 --- a/tests/src/unit-unicode1.cpp +++ b/tests/src/unit-unicode1.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-unicode2.cpp b/tests/src/unit-unicode2.cpp index b91d0be866..02eab6f95e 100644 --- a/tests/src/unit-unicode2.cpp +++ b/tests/src/unit-unicode2.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-unicode3.cpp b/tests/src/unit-unicode3.cpp index d5740e3e04..80cff40ad9 100644 --- a/tests/src/unit-unicode3.cpp +++ b/tests/src/unit-unicode3.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-unicode4.cpp b/tests/src/unit-unicode4.cpp index 0a7a58bc32..6992b31235 100644 --- a/tests/src/unit-unicode4.cpp +++ b/tests/src/unit-unicode4.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-unicode5.cpp b/tests/src/unit-unicode5.cpp index 2360dbe368..be12f3ae37 100644 --- a/tests/src/unit-unicode5.cpp +++ b/tests/src/unit-unicode5.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-user_defined_input.cpp b/tests/src/unit-user_defined_input.cpp index a3095a8d92..febc14c7cb 100644 --- a/tests/src/unit-user_defined_input.cpp +++ b/tests/src/unit-user_defined_input.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-windows_h.cpp b/tests/src/unit-windows_h.cpp index 5fa6410916..aa4b414062 100644 --- a/tests/src/unit-windows_h.cpp +++ b/tests/src/unit-windows_h.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit-wstring.cpp b/tests/src/unit-wstring.cpp index b8ed08db82..cadda8b704 100644 --- a/tests/src/unit-wstring.cpp +++ b/tests/src/unit-wstring.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tests/src/unit.cpp b/tests/src/unit.cpp index 8074687a55..a4c3588822 100644 --- a/tests/src/unit.cpp +++ b/tests/src/unit.cpp @@ -1,6 +1,6 @@ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) -// | | |__ | | | | | | version 3.11.1 +// | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann diff --git a/tools/amalgamate/config.json b/tools/amalgamate/config_json.json similarity index 100% rename from tools/amalgamate/config.json rename to tools/amalgamate/config_json.json diff --git a/tools/amalgamate/config_json_fwd.json b/tools/amalgamate/config_json_fwd.json new file mode 100644 index 0000000000..695929c158 --- /dev/null +++ b/tools/amalgamate/config_json_fwd.json @@ -0,0 +1,8 @@ +{ + "project": "JSON for Modern C++", + "target": "single_include/nlohmann/json_fwd.hpp", + "sources": [ + "include/nlohmann/json_fwd.hpp" + ], + "include_paths": ["include"] +} diff --git a/tools/gdb_pretty_printer/nlohmann-json.py b/tools/gdb_pretty_printer/nlohmann-json.py index 774756de79..0099f9c0ae 100644 --- a/tools/gdb_pretty_printer/nlohmann-json.py +++ b/tools/gdb_pretty_printer/nlohmann-json.py @@ -1,7 +1,7 @@ import gdb import re -ns_pattern = re.compile(r'nlohmann::json_v(?P\d+)_(?P\d+)_(?P\d+)(?P\w*)::(?P.+)') +ns_pattern = re.compile(r'nlohmann(::json_abi(?P\w*)(_v(?P\d+)_(?P\d+)_(?P\d+))?)?::(?P.+)') class JsonValuePrinter: "Print a json-value" @@ -26,7 +26,7 @@ def json_lookup_function(val): return gdb.default_visualizer(union_val.dereference()) else: return JsonValuePrinter(union_val) - except: + except Exception: return JsonValuePrinter(val['m_type']) gdb.pretty_printers.append(json_lookup_function) diff --git a/tools/generate_natvis/README.md b/tools/generate_natvis/README.md new file mode 100644 index 0000000000..b4d3a7d7f1 --- /dev/null +++ b/tools/generate_natvis/README.md @@ -0,0 +1,10 @@ +generate_natvis.py +================== + +Generate the Natvis debugger visualization file for all supported namespace combinations. + +## Usage + +``` +./generate_natvis.py --version X.Y.Z output_directory/ +``` diff --git a/tools/generate_natvis/generate_natvis.py b/tools/generate_natvis/generate_natvis.py new file mode 100755 index 0000000000..9266050c5d --- /dev/null +++ b/tools/generate_natvis/generate_natvis.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import argparse +import itertools +import jinja2 +import os +import re +import sys + +def semver(v): + if not re.fullmatch(r'\d+\.\d+\.\d+', v): + raise ValueError + return v + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--version', required=True, type=semver, help='Library version number') + parser.add_argument('output', help='Output directory for nlohmann_json.natvis') + args = parser.parse_args() + + namespaces = ['nlohmann'] + abi_prefix = 'json_abi' + abi_tags = ['_diag', '_ldvcmp'] + version = '_v' + args.version.replace('.', '_') + inline_namespaces = [] + + # generate all combinations of inline namespace names + for n in range(0, len(abi_tags) + 1): + for tags in itertools.combinations(abi_tags, n): + ns = abi_prefix + ''.join(tags) + inline_namespaces += [ns, ns + version] + + namespaces += [f'{namespaces[0]}::{ns}' for ns in inline_namespaces] + + env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=sys.path[0]), autoescape=True, trim_blocks=True, + lstrip_blocks=True, keep_trailing_newline=True) + template = env.get_template('nlohmann_json.natvis.j2') + natvis = template.render(namespaces=namespaces) + + with open(os.path.join(args.output, 'nlohmann_json.natvis'), 'w') as f: + f.write(natvis) diff --git a/tools/generate_natvis/nlohmann_json.natvis.j2 b/tools/generate_natvis/nlohmann_json.natvis.j2 new file mode 100644 index 0000000000..0a9ee2ce24 --- /dev/null +++ b/tools/generate_natvis/nlohmann_json.natvis.j2 @@ -0,0 +1,38 @@ + + + + + +{% for ns in namespaces %} + + + null + {*(m_value.object)} + {*(m_value.array)} + {*(m_value.string)} + {m_value.boolean} + {m_value.number_integer} + {m_value.number_unsigned} + {m_value.number_float} + discarded + + + *(m_value.object),view(simple) + + + *(m_value.array),view(simple) + + + + + + + {second} + + second + + + +{% endfor %} + diff --git a/tools/serve_header/serve_header.py b/tools/serve_header/serve_header.py index 666fa57c3d..9844e68009 100755 --- a/tools/serve_header/serve_header.py +++ b/tools/serve_header/serve_header.py @@ -240,7 +240,7 @@ def stop(self): self.observer.stop() self.observer.join() -class HeaderRequestHandler(SimpleHTTPRequestHandler): +class HeaderRequestHandler(SimpleHTTPRequestHandler): # lgtm[py/missing-call-to-init] def __init__(self, request, client_address, server): """.""" self.worktrees = server.worktrees @@ -388,11 +388,11 @@ def server_bind(self): if https.get('enabled', True): cert_file = https.get('cert_file', 'localhost.pem') key_file = https.get('key_file', 'localhost-key.pem') - ssl.minimum_version = ssl.TLSVersion.TLSv1_3 - ssl.maximum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED - httpd.socket = ssl.wrap_socket(httpd.socket, - certfile=cert_file, keyfile=key_file, - server_side=True, ssl_version=ssl.PROTOCOL_TLS) + ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) + ssl_ctx.minimum_version = ssl.TLSVersion.TLSv1_2 + ssl_ctx.maximum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED + ssl_ctx.load_cert_chain(cert_file, key_file) + httpd.socket = ssl_ctx.wrap_socket(httpd.socket, server_side=True) scheme = 'HTTPS' host, port = httpd.socket.getsockname()[:2] log.info(f'serving {scheme} on {host} port {port}') @@ -402,8 +402,8 @@ def server_bind(self): except KeyboardInterrupt: log.info('exiting') except Exception: - log.exception('an error occurred:') ec = 1 + log.exception('an error occurred:') finally: if worktrees is not None: worktrees.stop() diff --git a/wsjcpp.yml b/wsjcpp.yml index 04648019c8..d40eb011ec 100644 --- a/wsjcpp.yml +++ b/wsjcpp.yml @@ -2,7 +2,7 @@ wsjcpp_version: "v0.1.1" cmake_minimum_required: "3.0" cmake_cxx_standard: "11" name: "nlohmann/json" -version: "v3.11.1" +version: "v3.11.2" description: "JSON for Modern C++" issues: "https://github.com/nlohmann/json/issues" keywords: @@ -21,3 +21,6 @@ distribution: - source-file: "single_include/nlohmann/json.hpp" target-file: "json.hpp" type: "source-code" + - source-file: "single_include/nlohmann/json_fwd.hpp" + target-file: "json_fwd.hpp" + type: "source-code"