mirror of
https://github.com/nlohmann/json.git
synced 2026-10-01 12:10:32 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
289d61ef4f | ||
|
|
a2f45e7fbc | ||
|
|
29a647a08b | ||
|
|
8ee8bff661 | ||
|
|
8ead67cc30 | ||
|
|
aea2132069 | ||
|
|
526b6d3fd6 |
+17
@@ -0,0 +1,17 @@
|
||||
arm_container:
|
||||
image: gcc:latest
|
||||
|
||||
check_task:
|
||||
check_script:
|
||||
# the gcc image ships an outdated CMake, so fetch a recent prebuilt binary
|
||||
# instead of compiling CMake from source
|
||||
- wget -q https://github.com/Kitware/CMake/releases/download/v4.3.4/cmake-4.3.4-linux-aarch64.tar.gz
|
||||
- tar xfz cmake-4.3.4-linux-aarch64.tar.gz
|
||||
- export PATH="$(pwd)/cmake-4.3.4-linux-aarch64/bin:$PATH"
|
||||
- cmake --version
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake .. -DJSON_FastTests=ON
|
||||
- make -j4
|
||||
- cd tests
|
||||
- ctest -j4
|
||||
+5
-10
@@ -1,15 +1,9 @@
|
||||
# bugprone-use-after-move (hicpp-invalid-access-moved is its alias) still flags
|
||||
# the basic_json move constructor, which forwards the whole object to its base
|
||||
# class (#5724), and two forwards in the error-message construction of
|
||||
# at(KeyType&&) (json.hpp, both overloads: find(std::forward<KeyType>(key))
|
||||
# followed by string_t(std::forward<KeyType>(key)) in the throw), which #5689
|
||||
# rewrites. Re-enable both checks once those changes have landed.
|
||||
# portability-avoid-pragma-once: kept disabled on purpose. #pragma once is accepted
|
||||
# by every supported compiler, and tools/amalgamate/amalgamate.py strips it from
|
||||
# single_include, so there is nothing left to fix here.
|
||||
# TODO: The first three checks are only removed to get the CI going. They have to be addressed at some point.
|
||||
# TODO: portability-avoid-pragma-once: should be fixed eventually
|
||||
|
||||
Checks: '*,
|
||||
|
||||
-portability-template-virtual-member-function,
|
||||
-bugprone-use-after-move,
|
||||
-hicpp-invalid-access-moved,
|
||||
|
||||
@@ -43,6 +37,7 @@ Checks: '*,
|
||||
-google-readability-function-size,
|
||||
-google-runtime-float,
|
||||
-google-runtime-int,
|
||||
-google-runtime-references,
|
||||
-hicpp-avoid-goto,
|
||||
-hicpp-explicit-conversions,
|
||||
-hicpp-function-size,
|
||||
@@ -76,7 +71,6 @@ Checks: '*,
|
||||
-readability-magic-numbers,
|
||||
-readability-redundant-access-specifiers,
|
||||
-readability-redundant-parentheses,
|
||||
-readability-redundant-typename,
|
||||
-readability-simplify-boolean-expr,
|
||||
-readability-uppercase-literal-suffix,
|
||||
-readability-use-concise-preprocessor-directives'
|
||||
@@ -87,4 +81,5 @@ CheckOptions:
|
||||
|
||||
WarningsAsErrors: '*'
|
||||
|
||||
#HeaderFilterRegex: '.*nlohmann.*'
|
||||
HeaderFilterRegex: '.*hpp$'
|
||||
|
||||
@@ -142,6 +142,16 @@ The documentation will then be available at <http://127.0.0.1:8000/>. See the do
|
||||
[mkdocs](https://www.mkdocs.org) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) for more
|
||||
information.
|
||||
|
||||
Before opening a pull request, check the documentation like the CI does:
|
||||
|
||||
```shell
|
||||
make build -C docs/mkdocs # strict build: fails on broken links, anchors, and structure problems
|
||||
make check_mermaid -C docs/mkdocs # checks the Mermaid diagrams (requires Node.js)
|
||||
```
|
||||
|
||||
A new API page also needs an entry in [`docs/docset/docSet.sql`](https://github.com/nlohmann/json/blob/develop/docs/docset/docSet.sql),
|
||||
the search index of the docset; `make build` reports missing entries.
|
||||
|
||||
### Amalgamate the source code
|
||||
|
||||
The single-header files
|
||||
|
||||
+11
-4
@@ -18,16 +18,23 @@ updates:
|
||||
cooldown:
|
||||
default-days: 7
|
||||
|
||||
- package-ecosystem: npm
|
||||
directory: /docs/mkdocs/scripts/mermaid
|
||||
schedule:
|
||||
interval: daily
|
||||
cooldown:
|
||||
default-days: 7
|
||||
ignore:
|
||||
# Material for MkDocs loads mermaid@11; keep the checker on the same major version
|
||||
- dependency-name: mermaid
|
||||
update-types: ["version-update:semver-major"]
|
||||
|
||||
- package-ecosystem: pip
|
||||
directory: /tools/astyle
|
||||
schedule:
|
||||
interval: daily
|
||||
cooldown:
|
||||
default-days: 7
|
||||
ignore:
|
||||
# astyle is deliberately pinned (see tools/astyle/requirements.txt): newer versions
|
||||
# reformat the code, and the pinned version defines the formatting CI enforces
|
||||
- dependency-name: astyle
|
||||
|
||||
- package-ecosystem: pip
|
||||
directory: /tools/generate_natvis
|
||||
|
||||
@@ -30,6 +30,14 @@ environment:
|
||||
CMAKE_OPTIONS: ""
|
||||
GENERATOR: Visual Studio 14 2015
|
||||
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
configuration: Release
|
||||
platform: x86
|
||||
name: with_win_header
|
||||
CXX_FLAGS: "/W4 /WX"
|
||||
CMAKE_OPTIONS: ""
|
||||
GENERATOR: Visual Studio 14 2015
|
||||
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
configuration: Release
|
||||
platform: x86
|
||||
@@ -66,6 +74,9 @@ install:
|
||||
- if "%platform%"=="x86" set GENERATOR_PLATFORM=Win32
|
||||
|
||||
before_build:
|
||||
# for with_win_header build, inject the inclusion of Windows.h to the single-header library
|
||||
- ps: if ($env:name -Eq "with_win_header") { $header_path = "single_include\nlohmann\json.hpp" }
|
||||
- ps: if ($env:name -Eq "with_win_header") { "#include <Windows.h>`n" + (Get-Content $header_path | Out-String) | Set-Content $header_path }
|
||||
- cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On "%CMAKE_OPTIONS%"
|
||||
|
||||
build_script:
|
||||
|
||||
@@ -2,23 +2,16 @@ name: "Check amalgamation"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
# also check develop itself: a PR can be merged before its own run of this
|
||||
# workflow completes (e.g. while it is still queued), leaving single_include
|
||||
# stale on develop without any failing check
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
save:
|
||||
if: github.event_name == 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
@@ -42,7 +35,6 @@ jobs:
|
||||
MAIN_DIR: ${{ github.workspace }}/main
|
||||
INCLUDE_DIR: ${{ github.workspace }}/main/single_include/nlohmann
|
||||
TOOL_DIR: ${{ github.workspace }}/tools/tools/amalgamate
|
||||
NATVIS_TOOL_DIR: ${{ github.workspace }}/tools/tools/generate_natvis
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
@@ -50,11 +42,11 @@ jobs:
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: Checkout pull request or pushed commit
|
||||
- name: Checkout pull request
|
||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
path: main
|
||||
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
persist-credentials: false
|
||||
|
||||
- name: Checkout tools
|
||||
@@ -69,48 +61,6 @@ jobs:
|
||||
python3 -mvenv venv
|
||||
venv/bin/pip3 install -r $MAIN_DIR/tools/astyle/requirements.txt
|
||||
|
||||
- name: Install generate_natvis dependencies
|
||||
run: pip3 install -r $NATVIS_TOOL_DIR/requirements.txt
|
||||
|
||||
- name: Regenerate the tools/macro_builder tables in macro_scope.hpp
|
||||
run: |
|
||||
cd $MAIN_DIR
|
||||
|
||||
# Built from this PR's own tools/macro_builder/main.cpp, not a
|
||||
# develop checkout: unlike amalgamate.py and generate_natvis.py,
|
||||
# this tool has no other source of truth to check against (its
|
||||
# own README documents that it must reproduce macro_scope.hpp
|
||||
# byte for byte), so there is nothing to gain from checking out a
|
||||
# separate copy, and doing so would make this step fail on a PR
|
||||
# that adds support for a new dispatch table until that PR itself
|
||||
# merges to develop, the same way generate_natvis.py's --version
|
||||
# requirement briefly did.
|
||||
TMPDIR=$(mktemp -d ./macro_builder_check.XXXXXX)
|
||||
c++ -std=c++11 tools/macro_builder/main.cpp -o "$TMPDIR/macro_builder"
|
||||
"$TMPDIR/macro_builder" > "$TMPDIR/paste.hpp"
|
||||
"$TMPDIR/macro_builder" type_body > "$TMPDIR/type_body.hpp"
|
||||
|
||||
# Splice the (still unindented) generated blocks back into
|
||||
# macro_scope.hpp; the astyle pass below indents their
|
||||
# continuation lines the same way it does for the rest of
|
||||
# include/, so a correctly regenerated file comes out unchanged.
|
||||
awk -v newfile="$TMPDIR/paste.hpp" '
|
||||
BEGIN { while ((getline line < newfile) > 0) { new = new line "\n" } }
|
||||
/^#define NLOHMANN_JSON_EXPAND\( x \) x$/ { printf "%s", new; skip=1 }
|
||||
skip && /^#define NLOHMANN_JSON_DOUBLE_PASTE63\(/ { skip=0; next }
|
||||
skip { next }
|
||||
{ print }
|
||||
' include/nlohmann/detail/macro_scope.hpp > "$TMPDIR/macro_scope_1.hpp"
|
||||
awk -v newfile="$TMPDIR/type_body.hpp" '
|
||||
BEGIN { while ((getline line < newfile) > 0) { new = new line "\n" } }
|
||||
/^#define NLOHMANN_JSON_TYPE_BODY\(Prefix, \.\.\.\)/ { printf "%s", new; skip=1 }
|
||||
skip && /^[[:space:]]*NLOHMANN_JSON_TYPE_BODY_SENTINEL\)\)$/ { skip=0; next }
|
||||
skip { next }
|
||||
{ print }
|
||||
' "$TMPDIR/macro_scope_1.hpp" > "$TMPDIR/macro_scope_2.hpp"
|
||||
mv "$TMPDIR/macro_scope_2.hpp" include/nlohmann/detail/macro_scope.hpp
|
||||
rm -rf "$TMPDIR"
|
||||
|
||||
- name: Regenerate amalgamation, formatting, and BUILD.bazel
|
||||
run: |
|
||||
cd $MAIN_DIR
|
||||
@@ -138,19 +88,6 @@ jobs:
|
||||
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
||||
$(find $SOURCE_DIRS -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
|
||||
|
||||
- name: Regenerate nlohmann_json.natvis
|
||||
run: |
|
||||
cd $MAIN_DIR
|
||||
# Pass --version explicitly so this step also works with the tool
|
||||
# copy from develop before this repository's own generate_natvis.py
|
||||
# learns to derive the version itself: the older script requires
|
||||
# --version, and the newer one accepts it as an explicit override.
|
||||
ABI_MACROS=include/nlohmann/detail/abi_macros.hpp
|
||||
VERSION_MAJOR=$(grep -m1 'define NLOHMANN_JSON_VERSION_MAJOR' $ABI_MACROS | grep -o '[0-9]\+')
|
||||
VERSION_MINOR=$(grep -m1 'define NLOHMANN_JSON_VERSION_MINOR' $ABI_MACROS | grep -o '[0-9]\+')
|
||||
VERSION_PATCH=$(grep -m1 'define NLOHMANN_JSON_VERSION_PATCH' $ABI_MACROS | grep -o '[0-9]\+')
|
||||
python3 $NATVIS_TOOL_DIR/generate_natvis.py --version "$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" $MAIN_DIR
|
||||
|
||||
- name: Build patch and check for differences
|
||||
id: diff
|
||||
run: |
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
name: Check documentation links
|
||||
|
||||
# check the links of the documentation weekly; external links break without any change in this repository
|
||||
on:
|
||||
schedule:
|
||||
- cron: '17 4 * * 1'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
check_docs_links:
|
||||
if: github.repository == 'nlohmann/json'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install virtual environment
|
||||
run: make install_venv -C docs/mkdocs
|
||||
|
||||
- name: Check links
|
||||
shell: bash # adds -o pipefail, so tee does not hide the exit code
|
||||
run: make link_check -C docs/mkdocs 2>&1 | tee link_check.log
|
||||
|
||||
- name: Summarize broken links
|
||||
if: failure()
|
||||
run: |
|
||||
{
|
||||
echo '### Broken documentation links'
|
||||
echo '```'
|
||||
grep 'invalid url' link_check.log || true
|
||||
echo '```'
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
@@ -10,8 +10,7 @@ permissions:
|
||||
|
||||
jobs:
|
||||
comment:
|
||||
# push runs on develop have no PR to comment on (and no "pr" artifact)
|
||||
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }}
|
||||
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
@@ -7,16 +7,6 @@ on:
|
||||
- develop
|
||||
paths:
|
||||
- docs/mkdocs/**
|
||||
# the site also embeds these files via pymdownx.snippets
|
||||
# (mkdocs.yml sets restrict_base_path: false for this)
|
||||
- .clang-tidy
|
||||
- .github/CODE_OF_CONDUCT.md
|
||||
- .github/CONTRIBUTING.md
|
||||
- .github/SECURITY.md
|
||||
- cmake/clang_flags.cmake
|
||||
- cmake/gcc_flags.cmake
|
||||
- tests/fmt_formatter/project/main.cpp
|
||||
- tools/astyle/.astylerc
|
||||
workflow_dispatch:
|
||||
|
||||
# we don't want to have concurrent jobs, and we don't want to cancel running jobs to avoid broken publications
|
||||
@@ -33,7 +23,7 @@ jobs:
|
||||
contents: write
|
||||
|
||||
if: github.repository == 'nlohmann/json'
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||
@@ -42,7 +32,9 @@ jobs:
|
||||
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
# the git-revision-date-localized plugin needs the history for correct "last update" dates and so the
|
||||
# strict build does not fail on a shallow clone
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install virtual environment
|
||||
run: make install_venv -C docs/mkdocs
|
||||
|
||||
@@ -52,13 +52,6 @@ jobs:
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_infer
|
||||
- name: Archive Infer report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: infer-report
|
||||
path: ${{ github.workspace }}/build/build_infer/infer-out/report.txt
|
||||
if-no-files-found: ignore
|
||||
|
||||
ci_static_analysis_ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -85,7 +78,7 @@ jobs:
|
||||
|
||||
ci_static_analysis_clang:
|
||||
runs-on: ubuntu-latest
|
||||
container: silkeh/clang:22
|
||||
container: silkeh/clang:dev
|
||||
strategy:
|
||||
matrix:
|
||||
target: [ci_test_clang, ci_clang_tidy, ci_test_clang_sanitizer, ci_clang_analyze, ci_single_binaries]
|
||||
@@ -104,13 +97,13 @@ jobs:
|
||||
|
||||
ci_cmake_options:
|
||||
runs-on: ubuntu-latest
|
||||
container: ubuntu:24.04
|
||||
container: ubuntu:focal
|
||||
strategy:
|
||||
matrix:
|
||||
target: [ci_cmake_flags, ci_test_diagnostics, ci_test_diagnostic_positions, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls, ci_test_disableenumserialization, ci_test_disabletuplereferenceconversion, ci_test_skiplibraryversioncheck, ci_test_simdutf, ci_test_strict_nul_handling, ci_test_no_thread_local]
|
||||
target: [ci_cmake_flags, ci_test_diagnostics, ci_test_diagnostic_positions, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls, ci_test_disableenumserialization, ci_test_skiplibraryversioncheck, ci_test_simdutf, ci_test_strict_nul_handling, ci_test_no_thread_local]
|
||||
steps:
|
||||
- name: Install build-essential
|
||||
run: apt-get update ; apt-get install -y build-essential unzip wget git
|
||||
run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
@@ -353,8 +346,6 @@ jobs:
|
||||
container: intel/oneapi-hpckit:latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||
- name: Run CMake
|
||||
@@ -367,8 +358,6 @@ jobs:
|
||||
container: nvcr.io/nvidia/nvhpc:25.5-devel-cuda12.9-ubuntu22.04
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||
- name: Run CMake
|
||||
@@ -400,7 +389,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
target: [ci_test_examples, ci_test_build_documentation]
|
||||
target: [ci_test_examples, ci_test_build_documentation, ci_test_documentation_mermaid]
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||
@@ -410,25 +399,13 @@ jobs:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
# the git-revision-date-localized plugin needs the history; a shallow clone makes the strict build fail
|
||||
fetch-depth: ${{ matrix.target == 'ci_test_build_documentation' && '0' || '1' }}
|
||||
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
||||
if: matrix.target == 'ci_test_documentation_mermaid'
|
||||
with:
|
||||
node-version: 24
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
run: cmake --build build --target ${{ matrix.target }}
|
||||
|
||||
# Native Linux ARM64 runner with the latest GCC. The ubuntu-24.04-arm label is
|
||||
# only available for public repositories.
|
||||
ci_test_arm64:
|
||||
runs-on: ubuntu-24.04-arm
|
||||
container: gcc:latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||
- name: Check that the job runs natively on arm64
|
||||
run: uname -m && test "$(uname -m)" = aarch64
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
run: cmake --build build --target ci_test_compiler_default
|
||||
|
||||
@@ -87,8 +87,6 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||
- name: Set extra CXX_FLAGS for latest std_version
|
||||
@@ -125,8 +123,6 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Run CMake (Release)
|
||||
run: cmake -S . -B build -G "Visual Studio 18 2026" -A ARM64 -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||
if: matrix.build_type == 'Release'
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
/docs/docset/docSet.dsidx
|
||||
/docs/mkdocs/.cache/
|
||||
/docs/mkdocs/docs/__pycache__/
|
||||
/docs/mkdocs/hooks/__pycache__/
|
||||
/docs/mkdocs/scripts/mermaid/node_modules/
|
||||
/docs/mkdocs/site/
|
||||
/docs/mkdocs/venv/
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"_comment": "Used by the ci_infer CMake target (#5715 item 4b). fail-on-issue makes CI fail on Infer findings; disable-issue-type is a type-level baseline for the ~174 pre-existing findings (all PULSE_UNNECESSARY_COPY*/PULSE_RESOURCE_LEAK/PULSE_CONST_REFABLE, mostly in test code) triaged in run https://github.com/nlohmann/json/actions/runs/35829411620 on commit 1054b2097, so CI fails only on a NEW issue type. Remove an entry here once its findings have been fixed or explicitly accepted.",
|
||||
"fail-on-issue": true,
|
||||
"disable-issue-type": [
|
||||
"PULSE_UNNECESSARY_COPY_ASSIGNMENT",
|
||||
"PULSE_UNNECESSARY_COPY",
|
||||
"PULSE_UNNECESSARY_COPY_INTERMEDIATE",
|
||||
"PULSE_UNNECESSARY_COPY_OPTIONAL",
|
||||
"PULSE_RESOURCE_LEAK",
|
||||
"PULSE_CONST_REFABLE"
|
||||
]
|
||||
}
|
||||
@@ -23,6 +23,10 @@ Files: tests/thirdparty/fifo_map/*
|
||||
Copyright: 2015-2017 Niels Lohmann
|
||||
License: MIT
|
||||
|
||||
Files: tests/thirdparty/Fuzzer/*
|
||||
Copyright: 2003-2022 LLVM Project.
|
||||
License: Apache-2.0
|
||||
|
||||
Files: tests/thirdparty/imapdl/*
|
||||
Copyright: 2017 Georg Sauthoff <mail@gms.tf>
|
||||
License: GPL-3.0-only
|
||||
|
||||
@@ -20,7 +20,6 @@ cc_library(
|
||||
hdrs = [
|
||||
"include/nlohmann/adl_serializer.hpp",
|
||||
"include/nlohmann/byte_container_with_subtype.hpp",
|
||||
"include/nlohmann/detail/abi_config.hpp",
|
||||
"include/nlohmann/detail/abi_macros.hpp",
|
||||
"include/nlohmann/detail/bit_ops.hpp",
|
||||
"include/nlohmann/detail/conversions/from_json.hpp",
|
||||
@@ -66,13 +65,6 @@ cc_library(
|
||||
"include/nlohmann/detail/string_escape.hpp",
|
||||
"include/nlohmann/detail/string_utils.hpp",
|
||||
"include/nlohmann/detail/value_t.hpp",
|
||||
"include/nlohmann/detail/view/builder.hpp",
|
||||
"include/nlohmann/detail/view/document_data.hpp",
|
||||
"include/nlohmann/detail/view/macro_scope.hpp",
|
||||
"include/nlohmann/detail/view/macro_unscope.hpp",
|
||||
"include/nlohmann/detail/view/node.hpp",
|
||||
"include/nlohmann/detail/view/scan.hpp",
|
||||
"include/nlohmann/detail/view/string_ref.hpp",
|
||||
"include/nlohmann/json.hpp",
|
||||
"include/nlohmann/json_fwd.hpp",
|
||||
"include/nlohmann/json_literals.hpp",
|
||||
|
||||
@@ -55,7 +55,6 @@ option(JSON_Diagnostic_Positions "Enable diagnostic positions." OFF)
|
||||
option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON)
|
||||
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
||||
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
||||
option(JSON_DisableTupleReferenceConversion "Disable conversion from a one-element tuple of a JSON reference." OFF)
|
||||
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
||||
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
|
||||
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
|
||||
@@ -102,10 +101,6 @@ if (JSON_DisableEnumSerialization)
|
||||
message(STATUS "Enum integer serialization is disabled (JSON_DISABLE_ENUM_SERIALIZATION=1)")
|
||||
endif()
|
||||
|
||||
if (JSON_DisableTupleReferenceConversion)
|
||||
message(STATUS "Tuple reference conversion is disabled (JSON_DISABLE_TUPLE_REFERENCE_CONVERSION=1)")
|
||||
endif()
|
||||
|
||||
if (JSON_LegacyDiscardedValueComparison)
|
||||
message(STATUS "Legacy discarded value comparison enabled (JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1)")
|
||||
endif()
|
||||
@@ -148,7 +143,6 @@ target_compile_definitions(
|
||||
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0>
|
||||
$<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0>
|
||||
$<$<BOOL:${JSON_DisableEnumSerialization}>:JSON_DISABLE_ENUM_SERIALIZATION=1>
|
||||
$<$<BOOL:${JSON_DisableTupleReferenceConversion}>:JSON_DISABLE_TUPLE_REFERENCE_CONVERSION=1>
|
||||
$<$<BOOL:${JSON_Diagnostics}>:JSON_DIAGNOSTICS=1>
|
||||
$<$<BOOL:${JSON_Diagnostic_Positions}>:JSON_DIAGNOSTIC_POSITIONS=1>
|
||||
$<$<BOOL:${JSON_LegacyDiscardedValueComparison}>:JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1>
|
||||
|
||||
@@ -33,6 +33,17 @@ Further documentation:
|
||||
> [!IMPORTANT]
|
||||
> The folder `.github/workflows` is predetermined by GitHub.
|
||||
|
||||
### `.cirrus.yml`
|
||||
|
||||
Configuration file for the pipeline at [Cirrus CI](https://cirrus-ci.com/github/nlohmann/json).
|
||||
|
||||
Further documentation:
|
||||
|
||||
- [Writing tasks](https://cirrus-ci.org/guide/writing-tasks/)
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The filename `.cirrus.yml` and position (root of the repository) are predetermined by Cirrus CI.
|
||||
|
||||
### `.github/external_ci/appveyor.yml`
|
||||
|
||||
Configuration for the pipelines at [AppVeyor](https://ci.appveyor.com/project/nlohmann/json).
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.PHONY: pretty clean ChangeLog.md release update_hedley update_hedley_undef BUILD.bazel natvis macro_builder_check
|
||||
.PHONY: pretty clean ChangeLog.md release update_hedley update_hedley_undef BUILD.bazel
|
||||
|
||||
##########################################################################
|
||||
# configuration
|
||||
@@ -24,9 +24,6 @@ AMALGAMATED_FWD_FILE=single_include/nlohmann/json_fwd.hpp
|
||||
# json_literals.hpp only includes <nlohmann/json.hpp>, so it is copied verbatim
|
||||
AMALGAMATED_LITERALS_FILE=single_include/nlohmann/json_literals.hpp
|
||||
|
||||
# the header with the argument-counting macros generated by tools/macro_builder
|
||||
MACRO_SCOPE_HPP=include/nlohmann/detail/macro_scope.hpp
|
||||
|
||||
|
||||
##########################################################################
|
||||
# documentation of the Makefile's targets
|
||||
@@ -39,9 +36,13 @@ all:
|
||||
@echo "ChangeLog.md - generate ChangeLog file"
|
||||
@echo "check-amalgamation - check whether sources have been amalgamated and BUILD.bazel is up to date"
|
||||
@echo "clean - remove built files"
|
||||
@echo "fuzzing - see tests/fuzzing.md for how to build and run the fuzzers"
|
||||
@echo "macro_builder_check - check that macro_scope.hpp matches tools/macro_builder's output"
|
||||
@echo "natvis - regenerate nlohmann_json.natvis from the current ABI tags and version"
|
||||
@echo "doctest - compile example files and check their output"
|
||||
@echo "fuzz_testing - prepare fuzz testing of the JSON parser"
|
||||
@echo "fuzz_testing_bon8 - prepare fuzz testing of the BON8 parser"
|
||||
@echo "fuzz_testing_bson - prepare fuzz testing of the BSON parser"
|
||||
@echo "fuzz_testing_cbor - prepare fuzz testing of the CBOR parser"
|
||||
@echo "fuzz_testing_msgpack - prepare fuzz testing of the MessagePack parser"
|
||||
@echo "fuzz_testing_ubjson - prepare fuzz testing of the UBJSON parser"
|
||||
@echo "pretty - beautify code with Artistic Style"
|
||||
@echo "run_benchmarks - build and run benchmarks"
|
||||
@echo "update_hedley - download Hedley and regenerate hedley.hpp / hedley_undef.hpp"
|
||||
@@ -60,6 +61,74 @@ run_benchmarks:
|
||||
cd cmake-build-benchmarks ; ./json_benchmarks
|
||||
|
||||
|
||||
##########################################################################
|
||||
# fuzzing
|
||||
##########################################################################
|
||||
|
||||
# the overall fuzz testing target
|
||||
fuzz_testing:
|
||||
rm -fr fuzz-testing
|
||||
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||
$(MAKE) parse_afl_fuzzer -C tests CXX=afl-clang++
|
||||
mv tests/parse_afl_fuzzer fuzz-testing/fuzzer
|
||||
find tests/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||
|
||||
fuzz_testing_bon8:
|
||||
rm -fr fuzz-testing
|
||||
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||
$(MAKE) parse_bon8_fuzzer -C tests CXX=afl-clang++
|
||||
mv tests/parse_bon8_fuzzer fuzz-testing/fuzzer
|
||||
find tests/data -size -5k -name *.bon8 | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||
|
||||
fuzz_testing_bson:
|
||||
rm -fr fuzz-testing
|
||||
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||
$(MAKE) parse_bson_fuzzer -C tests CXX=afl-clang++
|
||||
mv tests/parse_bson_fuzzer fuzz-testing/fuzzer
|
||||
find tests/data -size -5k -name *.bson | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||
|
||||
fuzz_testing_cbor:
|
||||
rm -fr fuzz-testing
|
||||
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||
$(MAKE) parse_cbor_fuzzer -C tests CXX=afl-clang++
|
||||
mv tests/parse_cbor_fuzzer fuzz-testing/fuzzer
|
||||
find tests/data -size -5k -name *.cbor | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||
|
||||
fuzz_testing_msgpack:
|
||||
rm -fr fuzz-testing
|
||||
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||
$(MAKE) parse_msgpack_fuzzer -C tests CXX=afl-clang++
|
||||
mv tests/parse_msgpack_fuzzer fuzz-testing/fuzzer
|
||||
find tests/data -size -5k -name *.msgpack | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||
|
||||
fuzz_testing_ubjson:
|
||||
rm -fr fuzz-testing
|
||||
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||
$(MAKE) parse_ubjson_fuzzer -C tests CXX=afl-clang++
|
||||
mv tests/parse_ubjson_fuzzer fuzz-testing/fuzzer
|
||||
find tests/data -size -5k -name *.ubjson | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||
|
||||
fuzzing-start:
|
||||
afl-fuzz -S fuzzer1 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||
afl-fuzz -S fuzzer2 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||
afl-fuzz -S fuzzer3 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||
afl-fuzz -S fuzzer4 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||
afl-fuzz -S fuzzer5 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||
afl-fuzz -S fuzzer6 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||
afl-fuzz -S fuzzer7 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||
afl-fuzz -M fuzzer0 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer
|
||||
|
||||
fuzzing-stop:
|
||||
-killall fuzzer
|
||||
-killall afl-fuzz
|
||||
|
||||
|
||||
##########################################################################
|
||||
# Static analysis
|
||||
##########################################################################
|
||||
@@ -87,7 +156,11 @@ install_astyle:
|
||||
|
||||
# call the Artistic Style pretty printer on all source files
|
||||
pretty: install_astyle
|
||||
$(ASTYLE) --project=tools/astyle/.astylerc $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE) docs/mkdocs/docs/examples/*.cpp docs/mkdocs/docs/examples/*.hpp
|
||||
$(ASTYLE) --project=tools/astyle/.astylerc $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE) docs/mkdocs/docs/examples/*.cpp
|
||||
|
||||
# call the Clang-Format on all source files
|
||||
pretty_format:
|
||||
for FILE in $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/mkdocs/docs/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done
|
||||
|
||||
# create single header files and pretty print
|
||||
amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE)
|
||||
@@ -105,26 +178,8 @@ $(AMALGAMATED_FWD_FILE): $(SRCS)
|
||||
$(AMALGAMATED_LITERALS_FILE): include/nlohmann/json_literals.hpp
|
||||
cp include/nlohmann/json_literals.hpp $(AMALGAMATED_LITERALS_FILE)
|
||||
|
||||
# regenerate nlohmann_json.natvis from the ABI tags and version in include/nlohmann/detail/abi_macros.hpp
|
||||
natvis:
|
||||
python3 tools/generate_natvis/generate_natvis.py .
|
||||
|
||||
# regenerate the two tools/macro_builder blocks of $(MACRO_SCOPE_HPP) (see its README.md) and diff against the
|
||||
# checked-in header; phony, because it never writes $(MACRO_SCOPE_HPP) itself
|
||||
macro_builder_check:
|
||||
@set -e; \
|
||||
TMPDIR=$$(mktemp -d ./macro_builder_check.XXXXXX); \
|
||||
trap 'rm -rf "$$TMPDIR"' EXIT; \
|
||||
$(CXX) -std=c++11 tools/macro_builder/main.cpp -o "$$TMPDIR/macro_builder"; \
|
||||
"$$TMPDIR/macro_builder" > "$$TMPDIR/paste.hpp"; \
|
||||
"$$TMPDIR/macro_builder" type_body > "$$TMPDIR/type_body.hpp"; \
|
||||
$(ASTYLE) --project=tools/astyle/.astylerc --suffix=none --quiet "$$TMPDIR/paste.hpp" "$$TMPDIR/type_body.hpp"; \
|
||||
sed -n '/^#define NLOHMANN_JSON_EXPAND( x ) x$$/,/^#define NLOHMANN_JSON_DOUBLE_PASTE63(/p' $(MACRO_SCOPE_HPP) > "$$TMPDIR/paste_actual.hpp"; \
|
||||
sed -n '/^#define NLOHMANN_JSON_TYPE_BODY(Prefix, \.\.\.)/,/^ NLOHMANN_JSON_TYPE_BODY_SENTINEL))$$/p' $(MACRO_SCOPE_HPP) > "$$TMPDIR/type_body_actual.hpp"; \
|
||||
diff "$$TMPDIR/paste.hpp" "$$TMPDIR/paste_actual.hpp" || (echo "===================================================================\n $(MACRO_SCOPE_HPP) (NLOHMANN_JSON_EXPAND..NLOHMANN_JSON_DOUBLE_PASTE63) is out of date!\n Regenerate it, see tools/macro_builder/README.md.\n===================================================================" ; exit 1); \
|
||||
diff "$$TMPDIR/type_body.hpp" "$$TMPDIR/type_body_actual.hpp" || (echo "===================================================================\n $(MACRO_SCOPE_HPP) (NLOHMANN_JSON_TYPE_BODY) is out of date!\n Regenerate it, see tools/macro_builder/README.md.\n===================================================================" ; exit 1)
|
||||
|
||||
# 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)~
|
||||
@@ -140,11 +195,6 @@ check-amalgamation:
|
||||
@$(MAKE) BUILD.bazel
|
||||
@diff BUILD.bazel BUILD.bazel~ || (echo "===================================================================\n BUILD.bazel is out of date! Please run 'make BUILD.bazel'.\n===================================================================" ; mv BUILD.bazel~ BUILD.bazel ; false)
|
||||
@mv BUILD.bazel~ BUILD.bazel
|
||||
@mv nlohmann_json.natvis nlohmann_json.natvis~
|
||||
@$(MAKE) natvis
|
||||
@diff nlohmann_json.natvis nlohmann_json.natvis~ || (echo "===================================================================\n nlohmann_json.natvis is out of date! Please run 'make natvis'.\n===================================================================" ; mv nlohmann_json.natvis~ nlohmann_json.natvis ; false)
|
||||
@mv nlohmann_json.natvis~ nlohmann_json.natvis
|
||||
@$(MAKE) macro_builder_check
|
||||
|
||||
# generate the Bazel BUILD file; phony, because a removed header would not trigger a rebuild
|
||||
BUILD.bazel:
|
||||
@@ -196,7 +246,7 @@ release: include.zip json.tar.xz
|
||||
cp $(AMALGAMATED_FWD_FILE) release_files
|
||||
cp $(AMALGAMATED_LITERALS_FILE) release_files
|
||||
mv $(AMALGAMATED_FILE).asc $(AMALGAMATED_FWD_FILE).asc $(AMALGAMATED_LITERALS_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files
|
||||
cd release_files ; shasum -a 256 $$(find . -type f -not -name '*.asc' | sed 's|^\./||' | sort) > hashes.txt
|
||||
cd release_files ; shasum -a 256 json.hpp include.zip json.tar.xz > hashes.txt
|
||||
|
||||
|
||||
##########################################################################
|
||||
@@ -206,6 +256,7 @@ release: include.zip json.tar.xz
|
||||
# clean up
|
||||
clean:
|
||||
rm -fr fuzz fuzz-testing *.dSYM tests/*.dSYM
|
||||
rm -fr benchmarks/files/numbers/*.json
|
||||
rm -fr cmake-build-benchmarks fuzz-testing cmake-build-pvs-studio release_files
|
||||
$(MAKE) clean -Cdocs
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
[](https://coveralls.io/github/nlohmann/json?branch=develop)
|
||||
[](https://scan.coverity.com/projects/nlohmann-json)
|
||||
[](https://app.codacy.com/gh/nlohmann/json/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
||||
[](https://cirrus-ci.com/github/nlohmann/json)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:json)
|
||||
[](https://wandbox.org/permlink/1mp10JbaANo6FUc7)
|
||||
[](https://json.nlohmann.me)
|
||||
[](https://raw.githubusercontent.com/nlohmann/json/develop/LICENSE.MIT)
|
||||
[](https://github.com/nlohmann/json/releases)
|
||||
[](https://repology.org/project/nlohmann-json/versions)
|
||||
[](https://github.com/nlohmann/json/releases)
|
||||
[](https://github.com/nlohmann/json/issues)
|
||||
[](https://isitmaintained.com/project/nlohmann/json "Average time to resolve an issue")
|
||||
@@ -1394,7 +1394,7 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
|
||||
- The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the [MIT License](https://opensource.org/licenses/MIT) (see above). Copyright © 2009 [Florian Loitsch](https://florian.loitsch.com/)
|
||||
- The class contains a copy of [Hedley](https://nemequ.github.io/hedley/) from Evan Nemerson which is licensed as [CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/).
|
||||
- The class contains parts of [Google Abseil](https://github.com/abseil/abseil-cpp) which is licensed under the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0).
|
||||
- The class contains an adapted version of the Eisel-Lemire algorithm, its table of powers of five, and its digit comparison for long numbers from [fast_float](https://github.com/fastfloat/fast_float) by Daniel Lemire and contributors, which is available under the [MIT License](https://opensource.org/licenses/MIT) (used here), the Apache 2.0 License, and the Boost Software License. Copyright © 2021 The fast_float authors
|
||||
- The class contains an adapted version of the Eisel-Lemire algorithm and its table of powers of five from [fast_float](https://github.com/fastfloat/fast_float) by Daniel Lemire and contributors, which is available under the [MIT License](https://opensource.org/licenses/MIT) (used here), the Apache 2.0 License, and the Boost Software License. Copyright © 2021 The fast_float authors
|
||||
|
||||
<img align="right" src="https://git.fsfe.org/reuse/reuse-ci/raw/branch/master/reuse-horizontal.png" alt="REUSE Software">
|
||||
|
||||
|
||||
+104
-137
@@ -8,24 +8,24 @@ set(N 10)
|
||||
include(FindPython3)
|
||||
find_package(Python3 COMPONENTS Interpreter)
|
||||
|
||||
find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-22 clang++-21 clang++-20 clang++-19 clang++-18 clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
|
||||
find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-20 clang++-19 clang++-18 clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
|
||||
execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION)
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
|
||||
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
|
||||
|
||||
find_program(CLANG_TIDY_TOOL NAMES clang-tidy-22 clang-tidy-21 clang-tidy-20 clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy)
|
||||
find_program(CLANG_TIDY_TOOL NAMES clang-tidy-20 clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy)
|
||||
execute_process(COMMAND ${CLANG_TIDY_TOOL} --version OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION)
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}")
|
||||
message(STATUS "🔖 Clang-Tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})")
|
||||
|
||||
message(STATUS "🔖 CMake ${CMAKE_VERSION} (${CMAKE_COMMAND})")
|
||||
|
||||
find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++ g++-16 g++-15 g++-14 g++-13 g++-12 g++-11 g++-10)
|
||||
find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++ g++-15 g++-14 g++-13 g++-12 g++-11 g++-10)
|
||||
execute_process(COMMAND ${GCC_TOOL} --version OUTPUT_VARIABLE GCC_TOOL_VERSION ERROR_VARIABLE GCC_TOOL_VERSION)
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
|
||||
message(STATUS "🔖 GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})")
|
||||
|
||||
find_program(GCOV_TOOL NAMES gcov-HEAD gcov gcov-16 gcov-15 gcov-14 gcov-13 gcov-12 gcov-11 gcov-10)
|
||||
find_program(GCOV_TOOL NAMES gcov-HEAD gcov gcov-15 gcov-14 gcov-13 gcov-12 gcov-11 gcov-10)
|
||||
execute_process(COMMAND ${GCOV_TOOL} --version OUTPUT_VARIABLE GCOV_TOOL_VERSION ERROR_VARIABLE GCOV_TOOL_VERSION)
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCOV_TOOL_VERSION "${GCOV_TOOL_VERSION}")
|
||||
message(STATUS "🔖 GCOV ${GCOV_TOOL_VERSION} (${GCOV_TOOL})")
|
||||
@@ -40,14 +40,6 @@ execute_process(COMMAND ${IWYU_TOOL} --version OUTPUT_VARIABLE IWYU_TOOL_VERSION
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" IWYU_TOOL_VERSION "${IWYU_TOOL_VERSION}")
|
||||
message(STATUS "🔖 include-what-you-use ${IWYU_TOOL_VERSION} (${IWYU_TOOL})")
|
||||
|
||||
# CMake's CXX_INCLUDE_WHAT_YOU_USE launcher runs IWYU during the normal compile step (useful to see
|
||||
# diagnostics inline), but CMake's own __run_co_compile wrapper does not propagate the launched
|
||||
# tool's exit code to the build, so IWYU's own "-Xiwyu --error" cannot fail that step (verified: a
|
||||
# deliberately-unused #include in a header still lets `cmake --build` finish with exit code 0).
|
||||
# iwyu_tool.py, which ships with IWYU, reads compile_commands.json and does return a non-zero exit
|
||||
# code for any analyzed file with findings; ci_single_binaries uses it to actually fail on findings.
|
||||
find_program(IWYU_TOOL_PY NAMES iwyu_tool iwyu_tool.py iwyu-tool)
|
||||
|
||||
find_program(INFER_TOOL NAMES infer)
|
||||
execute_process(COMMAND ${INFER_TOOL} --version OUTPUT_VARIABLE INFER_TOOL_VERSION ERROR_VARIABLE INFER_TOOL_VERSION)
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" INFER_TOOL_VERSION "${INFER_TOOL_VERSION}")
|
||||
@@ -63,6 +55,12 @@ execute_process(COMMAND ${NINJA_TOOL} --version OUTPUT_VARIABLE NINJA_TOOL_VERSI
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" NINJA_TOOL_VERSION "${NINJA_TOOL_VERSION}")
|
||||
message(STATUS "🔖 Ninja ${NINJA_TOOL_VERSION} (${NINJA_TOOL})")
|
||||
|
||||
find_program(OCLINT_TOOL NAMES oclint-json-compilation-database)
|
||||
find_program(OCLINT_VERSION_TOOL NAMES oclint)
|
||||
execute_process(COMMAND ${OCLINT_VERSION_TOOL} --version OUTPUT_VARIABLE OCLINT_TOOL_VERSION ERROR_VARIABLE OCLINT_TOOL_VERSION)
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" OCLINT_TOOL_VERSION "${OCLINT_TOOL_VERSION}")
|
||||
message(STATUS "🔖 OCLint ${OCLINT_TOOL_VERSION} (${OCLINT_TOOL})")
|
||||
|
||||
find_program(VALGRIND_TOOL NAMES valgrind)
|
||||
execute_process(COMMAND ${VALGRIND_TOOL} --version OUTPUT_VARIABLE VALGRIND_TOOL_VERSION ERROR_VARIABLE VALGRIND_TOOL_VERSION)
|
||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" VALGRIND_TOOL_VERSION "${VALGRIND_TOOL_VERSION}")
|
||||
@@ -130,16 +128,16 @@ foreach(CXX_STANDARD 11 14 17 20 23 26)
|
||||
COMMENT "Compile and test with Clang for C++${CXX_STANDARD}"
|
||||
)
|
||||
|
||||
# pass -stdlib=libc++ through CXXFLAGS: an explicit -DCMAKE_CXX_FLAGS would make CMake ignore CXXFLAGS
|
||||
add_custom_target(ci_test_clang_libcxx_cxx${CXX_STANDARD}
|
||||
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS};-stdlib=libc++" ${CMAKE_COMMAND}
|
||||
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||
-DJSON_TestStandards=${CXX_STANDARD}
|
||||
-DCMAKE_CXX_FLAGS="-stdlib=libc++"
|
||||
-DCMAKE_EXE_LINKER_FLAGS="-lc++abi"
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD}
|
||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD}
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||
COMMENT "Compile and test with Clang for C++${CXX_STANDARD} (libc++)"
|
||||
)
|
||||
endforeach()
|
||||
@@ -278,20 +276,6 @@ add_custom_target(ci_test_disableenumserialization
|
||||
COMMENT "Compile and test with enum serialization disabled"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Disable conversion from a one-element tuple of a JSON reference.
|
||||
###############################################################################
|
||||
|
||||
add_custom_target(ci_test_disabletuplereferenceconversion
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_DisableTupleReferenceConversion=ON
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_disabletuplereferenceconversion
|
||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_disabletuplereferenceconversion
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_disabletuplereferenceconversion && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||
COMMENT "Compile and test with tuple reference conversion disabled"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Skip the multiple-inclusion library version check.
|
||||
###############################################################################
|
||||
@@ -378,20 +362,13 @@ add_custom_target(ci_test_clang_sanitizer
|
||||
# Check if header is amalgamated and sources are properly indented.
|
||||
###############################################################################
|
||||
|
||||
# Same file set as .github/workflows/check_amalgamation.yml, so a direct push to develop/master/release/*
|
||||
# (which only this CMake target checks, not the pull_request-only workflow) is held to the same standard.
|
||||
file(GLOB_RECURSE INDENT_FILES
|
||||
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp
|
||||
${PROJECT_SOURCE_DIR}/tests/src/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/tests/src/*.hpp
|
||||
${PROJECT_SOURCE_DIR}/tests/benchmarks/src/benchmarks.cpp
|
||||
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cu
|
||||
${PROJECT_SOURCE_DIR}/include/*.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/include/*.cu
|
||||
${PROJECT_SOURCE_DIR}/tests/*.hpp
|
||||
${PROJECT_SOURCE_DIR}/tests/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/tests/*.cu
|
||||
)
|
||||
list(FILTER INDENT_FILES EXCLUDE REGEX "/tests/thirdparty/|/tests/abi/include/nlohmann/")
|
||||
|
||||
set(include_dir ${PROJECT_SOURCE_DIR}/single_include/nlohmann)
|
||||
set(tool_dir ${PROJECT_SOURCE_DIR}/tools/amalgamate)
|
||||
@@ -400,7 +377,6 @@ add_custom_target(ci_test_amalgamation
|
||||
COMMAND cp ${include_dir}/json.hpp ${include_dir}/json.hpp~
|
||||
COMMAND cp ${include_dir}/json_fwd.hpp ${include_dir}/json_fwd.hpp~
|
||||
COMMAND cp ${include_dir}/json_literals.hpp ${include_dir}/json_literals.hpp~
|
||||
COMMAND cp ${PROJECT_SOURCE_DIR}/BUILD.bazel ${PROJECT_SOURCE_DIR}/BUILD.bazel~
|
||||
|
||||
COMMAND ${Python3_EXECUTABLE} -mvenv venv_astyle
|
||||
COMMAND venv_astyle/bin/pip3 --quiet install -r ${CMAKE_SOURCE_DIR}/tools/astyle/requirements.txt
|
||||
@@ -410,18 +386,16 @@ add_custom_target(ci_test_amalgamation
|
||||
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_fwd.json -s .
|
||||
COMMAND cp ${PROJECT_SOURCE_DIR}/include/nlohmann/json_literals.hpp ${include_dir}/json_literals.hpp
|
||||
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=none ${include_dir}/json.hpp ${include_dir}/json_fwd.hpp
|
||||
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/scripts/gen_bazel_build_file.cmake
|
||||
|
||||
COMMAND diff ${include_dir}/json.hpp~ ${include_dir}/json.hpp
|
||||
COMMAND diff ${include_dir}/json_fwd.hpp~ ${include_dir}/json_fwd.hpp
|
||||
COMMAND diff ${include_dir}/json_literals.hpp~ ${include_dir}/json_literals.hpp
|
||||
COMMAND diff ${PROJECT_SOURCE_DIR}/BUILD.bazel~ ${PROJECT_SOURCE_DIR}/BUILD.bazel
|
||||
|
||||
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=orig ${INDENT_FILES}
|
||||
COMMAND for FILE in `find . -name '*.orig'`\; do false \; done
|
||||
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
COMMENT "Check amalgamation, formatting, and BUILD.bazel"
|
||||
COMMENT "Check amalgamation and indentation"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
@@ -456,14 +430,14 @@ add_custom_target(ci_test_valgrind
|
||||
# Check code with Clang Static Analyzer.
|
||||
###############################################################################
|
||||
|
||||
set(CLANG_ANALYZER_CHECKS "nullability.NullableDereferenced,nullability.NullablePassedToNonnull,nullability.NullableReturnedFromNonnull,optin.cplusplus.UninitializedObject,optin.cplusplus.VirtualCall,optin.performance.Padding,optin.portability.UnixAPI,security.FloatLoopCounter,security.insecureAPI.DeprecatedOrUnsafeBufferHandling,security.insecureAPI.bcmp,security.insecureAPI.bcopy,security.insecureAPI.bzero,security.insecureAPI.rand,security.insecureAPI.strcpy,valist.CopyToSelf,valist.Uninitialized,valist.Unterminated,core.CallAndMessage,core.DivideZero,core.NonNullParamChecker,core.NullDereference,core.StackAddressEscape,core.UndefinedBinaryOperatorResult,core.VLASize,core.uninitialized.ArraySubscript,core.uninitialized.Assign,core.uninitialized.Branch,core.uninitialized.CapturedBlockVariable,core.uninitialized.UndefReturn,cplusplus.InnerPointer,cplusplus.Move,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,cplusplus.PlacementNew,cplusplus.PureVirtualCall,deadcode.DeadStores,nullability.NullPassedToNonnull,nullability.NullReturnedFromNonnull,security.insecureAPI.UncheckedReturn,security.insecureAPI.decodeValueOfObjCType,security.insecureAPI.getpw,security.insecureAPI.gets,security.insecureAPI.mkstemp,security.insecureAPI.mktemp,security.insecureAPI.vfork,unix.API,unix.Malloc,unix.MallocSizeof,unix.MismatchedDeallocator,unix.Vfork,unix.cstring.BadSizeArg,unix.cstring.NullArg")
|
||||
set(CLANG_ANALYZER_CHECKS "fuchsia.HandleChecker,nullability.NullableDereferenced,nullability.NullablePassedToNonnull,nullability.NullableReturnedFromNonnull,optin.cplusplus.UninitializedObject,optin.cplusplus.VirtualCall,optin.mpi.MPI-Checker,optin.osx.OSObjectCStyleCast,optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,optin.osx.cocoa.localizability.NonLocalizedStringChecker,optin.performance.GCDAntipattern,optin.performance.Padding,optin.portability.UnixAPI,security.FloatLoopCounter,security.insecureAPI.DeprecatedOrUnsafeBufferHandling,security.insecureAPI.bcmp,security.insecureAPI.bcopy,security.insecureAPI.bzero,security.insecureAPI.rand,security.insecureAPI.strcpy,valist.CopyToSelf,valist.Uninitialized,valist.Unterminated,webkit.NoUncountedMemberChecker,webkit.RefCntblBaseVirtualDtor,core.CallAndMessage,core.DivideZero,core.NonNullParamChecker,core.NullDereference,core.StackAddressEscape,core.UndefinedBinaryOperatorResult,core.VLASize,core.uninitialized.ArraySubscript,core.uninitialized.Assign,core.uninitialized.Branch,core.uninitialized.CapturedBlockVariable,core.uninitialized.UndefReturn,cplusplus.InnerPointer,cplusplus.Move,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,cplusplus.PlacementNew,cplusplus.PureVirtualCall,deadcode.DeadStores,nullability.NullPassedToNonnull,nullability.NullReturnedFromNonnull,osx.API,osx.MIG,osx.NumberObjectConversion,osx.OSObjectRetainCount,osx.ObjCProperty,osx.SecKeychainAPI,osx.cocoa.AtSync,osx.cocoa.AutoreleaseWrite,osx.cocoa.ClassRelease,osx.cocoa.Dealloc,osx.cocoa.IncompatibleMethodTypes,osx.cocoa.Loops,osx.cocoa.MissingSuperCall,osx.cocoa.NSAutoreleasePool,osx.cocoa.NSError,osx.cocoa.NilArg,osx.cocoa.NonNilReturnValue,osx.cocoa.ObjCGenerics,osx.cocoa.RetainCount,osx.cocoa.RunLoopAutoreleaseLeak,osx.cocoa.SelfInit,osx.cocoa.SuperDealloc,osx.cocoa.UnusedIvars,osx.cocoa.VariadicMethodTypes,osx.coreFoundation.CFError,osx.coreFoundation.CFNumber,osx.coreFoundation.CFRetainRelease,osx.coreFoundation.containers.OutOfBounds,osx.coreFoundation.containers.PointerSizedValues,security.insecureAPI.UncheckedReturn,security.insecureAPI.decodeValueOfObjCType,security.insecureAPI.getpw,security.insecureAPI.gets,security.insecureAPI.mkstemp,security.insecureAPI.mktemp,security.insecureAPI.vfork,unix.API,unix.Malloc,unix.MallocSizeof,unix.MismatchedDeallocator,unix.Vfork,unix.cstring.BadSizeArg,unix.cstring.NullArg")
|
||||
|
||||
add_custom_target(ci_clang_analyze
|
||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DJSON_BuildTests=ON
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_analyze
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_analyze && ${SCAN_BUILD_TOOL} -enable-checker ${CLANG_ANALYZER_CHECKS} --use-c++=${CLANG_TOOL} --use-analyzer=${CLANG_TOOL} -analyze-headers --status-bugs -o ${PROJECT_BINARY_DIR}/report ninja
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_analyze && ${SCAN_BUILD_TOOL} -enable-checker ${CLANG_ANALYZER_CHECKS} --use-c++=${CLANG_TOOL} -analyze-headers -o ${PROJECT_BINARY_DIR}/report ninja
|
||||
COMMENT "Check code with Clang Analyzer"
|
||||
)
|
||||
|
||||
@@ -479,7 +453,7 @@ add_custom_target(ci_cppcheck
|
||||
COMMAND venv_cppcheck/bin/cppcheck --enable=warning --check-level=exhaustive --inline-suppr --inconclusive --force
|
||||
--std=c++11 ${PROJECT_SOURCE_DIR}/include/nlohmann/json.hpp -I ${CMAKE_SOURCE_DIR}/include
|
||||
--error-exitcode=1 --relative-paths=${PROJECT_SOURCE_DIR} -j ${N} --include=default_defines.hpp
|
||||
--cppcheck-build-dir=cppcheck
|
||||
--cppcheck-build-dir=cppcheck --check-level=exhaustive
|
||||
-UJSON_CATCH_USER -UJSON_TRY_USER -UJSON_ASSERT -UJSON_INTERNAL_CATCH -UJSON_THROW
|
||||
-DJSON_HAS_CPP_11 -UJSON_HAS_CPP_14 -UJSON_HAS_CPP_17 -UJSON_HAS_CPP_20 -UJSON_HAS_THREE_WAY_COMPARISON
|
||||
COMMENT "Check code with Cppcheck"
|
||||
@@ -497,6 +471,34 @@ add_custom_target(ci_cpplint
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Check code with OCLint.
|
||||
###############################################################################
|
||||
|
||||
file(COPY ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp DESTINATION ${PROJECT_BINARY_DIR}/src_single)
|
||||
file(RENAME ${PROJECT_BINARY_DIR}/src_single/json.hpp ${PROJECT_BINARY_DIR}/src_single/all.cpp)
|
||||
file(APPEND "${PROJECT_BINARY_DIR}/src_single/all.cpp" "\n\nint main()\n{}\n")
|
||||
|
||||
add_executable(single_all ${PROJECT_BINARY_DIR}/src_single/all.cpp)
|
||||
target_compile_features(single_all PRIVATE cxx_std_11)
|
||||
|
||||
add_custom_target(ci_oclint
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
-DJSON_BuildTests=OFF -DJSON_CI=ON
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_oclint
|
||||
COMMAND ${OCLINT_TOOL} -i ${PROJECT_BINARY_DIR}/build_oclint/src_single/all.cpp -p ${PROJECT_BINARY_DIR}/build_oclint --
|
||||
-report-type html -enable-global-analysis --max-priority-1=0 --max-priority-2=1000 --max-priority-3=2000
|
||||
--disable-rule=MultipleUnaryOperator
|
||||
--disable-rule=DoubleNegative
|
||||
--disable-rule=ShortVariableName
|
||||
--disable-rule=GotoStatement
|
||||
--disable-rule=LongLine
|
||||
-o ${PROJECT_BINARY_DIR}/build_oclint/oclint_report.html
|
||||
COMMENT "Check code with OCLint"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Check code with Clang-Tidy.
|
||||
###############################################################################
|
||||
@@ -511,16 +513,29 @@ add_custom_target(ci_clang_tidy
|
||||
COMMENT "Check code with Clang-Tidy"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Check code with PVS-Studio Analyzer <https://www.viva64.com/en/pvs-studio/>.
|
||||
###############################################################################
|
||||
|
||||
add_custom_target(ci_pvs_studio
|
||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
-DJSON_BuildTests=ON
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_pvs_studio
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_pvs_studio && ${PVS_STUDIO_ANALYZER_TOOL} analyze -j 10
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_pvs_studio && ${PLOG_CONVERTER_TOOL} -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs
|
||||
COMMENT "Check code with PVS Studio"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Check code with Infer <https://fbinfer.com> static analyzer.
|
||||
###############################################################################
|
||||
|
||||
# .inferconfig (repository root) pins --fail-on-issue and the currently-triaged issue types that
|
||||
# are disabled until they are addressed separately; see #5715 item 4b.
|
||||
add_custom_target(ci_infer
|
||||
COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_infer
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} compile -- ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_DIR} -DJSON_BuildTests=ON
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} run --project-root ${PROJECT_SOURCE_DIR} -- make
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} run -- make
|
||||
COMMENT "Check code with Infer"
|
||||
)
|
||||
|
||||
@@ -576,13 +591,7 @@ add_custom_target(ci_reproducible_tests
|
||||
# be compiled individually.
|
||||
###############################################################################
|
||||
|
||||
set(iwyu_options -Xiwyu --error -Xiwyu --max_line_length=300)
|
||||
set(iwyu_path_and_options ${IWYU_TOOL} ${iwyu_options})
|
||||
|
||||
# CMake needs to know the exact flags used to compile each src_single/*.cpp below to hand them to
|
||||
# iwyu_tool.py; JSON_CI already implies a from-scratch configure, so enabling this project-wide has
|
||||
# no downside here.
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(iwyu_path_and_options ${IWYU_TOOL} -Xiwyu --max_line_length=300)
|
||||
|
||||
foreach(SRC_FILE ${SRC_FILES})
|
||||
# get relative path of the header file
|
||||
@@ -597,34 +606,14 @@ foreach(SRC_FILE ${SRC_FILES})
|
||||
target_include_directories(single_${RELATIVE_SRC_FILE} PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
target_compile_features(single_${RELATIVE_SRC_FILE} PRIVATE cxx_std_11)
|
||||
set_property(TARGET single_${RELATIVE_SRC_FILE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE "${iwyu_path_and_options}")
|
||||
# remember binary for ci_single_binaries
|
||||
# remember binary for ci_single_binaries target
|
||||
list(APPEND single_binaries single_${RELATIVE_SRC_FILE})
|
||||
# json.hpp pulls together the whole library behind heavily templated, SFINAE-based code, and
|
||||
# IWYU's suggestion for its one truly ambiguous symbol (a container-comparison "swap,
|
||||
# operator!=") is not deterministic between runs (observed <set>, <unordered_map>, and <map>
|
||||
# for the exact same source across otherwise-identical local and containerized builds). Keep
|
||||
# reporting its diagnostics (informational, via CXX_INCLUDE_WHAT_YOU_USE above) but exclude it
|
||||
# from the hard gate below so a fresh IWYU/compiler combination does not fail this target on a
|
||||
# nondeterministic suggestion for a header that already re-exports everything on purpose.
|
||||
if(NOT RELATIVE_SRC_FILE STREQUAL "json")
|
||||
list(APPEND single_binaries_tus src_single/${RELATIVE_SRC_FILE}.cpp)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(IWYU_TOOL_PY)
|
||||
add_custom_target(ci_single_binaries
|
||||
DEPENDS ${single_binaries}
|
||||
COMMAND ${IWYU_TOOL_PY} -p ${PROJECT_BINARY_DIR} ${single_binaries_tus} -- ${iwyu_options}
|
||||
COMMENT "Check if headers are self-contained"
|
||||
)
|
||||
else()
|
||||
# iwyu_tool.py (ships with IWYU, e.g. as /usr/bin/iwyu_tool on Debian/Ubuntu) was not found;
|
||||
# fall back to building the self-containment check without enforcing the IWYU findings.
|
||||
add_custom_target(ci_single_binaries
|
||||
DEPENDS ${single_binaries}
|
||||
COMMENT "Check if headers are self-contained"
|
||||
)
|
||||
endif()
|
||||
add_custom_target(ci_single_binaries
|
||||
DEPENDS ${single_binaries}
|
||||
COMMENT "Check if headers are self-contained"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Benchmarks
|
||||
@@ -646,41 +635,21 @@ add_custom_target(ci_benchmarks
|
||||
# we test the project with different CMake versions:
|
||||
# - CMake 3.5 (the earliest supported)
|
||||
# - CMake 3.31.6 (the latest 3.x release)
|
||||
# - CMake 4.0.0 (the first 4.x release)
|
||||
# - the CMake version running this build (usually the latest release)
|
||||
# - CMake 4.0.0 (the latest release)
|
||||
|
||||
function(ci_get_cmake version var)
|
||||
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}/bin/cmake)
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$")
|
||||
# Kitware publishes a prebuilt Linux x86_64 archive for every release; unpacking it is far
|
||||
# cheaper than compiling all of CMake (including its own test helpers) from source.
|
||||
add_custom_command(
|
||||
OUTPUT ${${var}}
|
||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-linux-x86_64.tar.gz
|
||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-SHA-256.txt
|
||||
# verify the archive against Kitware's published SHA-256 sums before unpacking it
|
||||
COMMAND sh -c "grep ' cmake-${version}-linux-x86_64[.]tar[.]gz$' cmake-${version}-SHA-256.txt | sha256sum -c -"
|
||||
COMMAND tar xfz cmake-${version}-linux-x86_64.tar.gz
|
||||
COMMAND rm cmake-${version}-linux-x86_64.tar.gz cmake-${version}-SHA-256.txt
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -rf cmake-${version}
|
||||
COMMAND ${CMAKE_COMMAND} -E rename cmake-${version}-linux-x86_64 cmake-${version}
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
COMMENT "Download prebuilt CMake ${version}"
|
||||
)
|
||||
else()
|
||||
# no prebuilt archive for this platform (e.g. macOS or Linux aarch64): build from source
|
||||
add_custom_command(
|
||||
OUTPUT ${${var}}
|
||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}.tar.gz
|
||||
COMMAND tar xfz cmake-${version}.tar.gz
|
||||
COMMAND rm cmake-${version}.tar.gz
|
||||
# -DCMAKE_POLICY_VERSION_MINIMUM=3.5 required to compile older CMake versions with CMake 4.0.0
|
||||
COMMAND cmake -S cmake-${version} -B cmake-${version} -DCMAKE_POLICY_VERSION_MINIMUM=3.5
|
||||
COMMAND cmake --build cmake-${version} --parallel 10
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
COMMENT "Download and build CMake ${version} from source"
|
||||
)
|
||||
endif()
|
||||
add_custom_command(
|
||||
OUTPUT ${${var}}
|
||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}.tar.gz
|
||||
COMMAND tar xfz cmake-${version}.tar.gz
|
||||
COMMAND rm cmake-${version}.tar.gz
|
||||
# -DCMAKE_POLICY_VERSION_MINIMUM=3.5 required to compile older CMake versions with CMake 4.0.0
|
||||
COMMAND cmake -S cmake-${version} -B cmake-${version} -DCMAKE_POLICY_VERSION_MINIMUM=3.5
|
||||
COMMAND cmake --build cmake-${version} --parallel 10
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
COMMENT "Download CMake ${version}"
|
||||
)
|
||||
set(${var} ${${var}} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
@@ -690,24 +659,30 @@ ci_get_cmake(4.0.0 CMAKE_4_0_0_BINARY)
|
||||
|
||||
# the tests require CMake 3.13 or later, so they are excluded for CMake 3.5.0
|
||||
set(JSON_CMAKE_FLAGS_3_5_0 JSON_Diagnostics JSON_Diagnostic_Positions JSON_GlobalUDLs JSON_ImplicitConversions JSON_DisableEnumSerialization
|
||||
JSON_LegacyDiscardedValueComparison JSON_Install JSON_MultipleHeaders JSON_SystemInclude JSON_Valgrind
|
||||
JSON_StrictNulHandling)
|
||||
set(JSON_CMAKE_FLAGS_3_31_6 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_5_0})
|
||||
JSON_LegacyDiscardedValueComparison JSON_Install JSON_MultipleHeaders JSON_SystemInclude JSON_Valgrind)
|
||||
set(JSON_CMAKE_FLAGS_3_31_6 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_31_6})
|
||||
set(JSON_CMAKE_FLAGS_4_0_0 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_5_0})
|
||||
|
||||
function(ci_add_cmake_flags_targets flag min_version)
|
||||
string(TOLOWER "ci_cmake_flag_${flag}" flag_target)
|
||||
string(REPLACE . _ min_version_var ${min_version})
|
||||
set(cmake_binary ${CMAKE_${min_version_var}_BINARY})
|
||||
add_custom_target(${flag_target}_${min_version}_2
|
||||
COMMENT "Check CMake flag ${flag} (CMake ${CMAKE_VERSION})"
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-Werror=dev
|
||||
-D${flag}=ON
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_${flag_target}
|
||||
)
|
||||
add_custom_target(${flag_target}_${min_version_var}
|
||||
COMMENT "Check CMake flag ${flag} (CMake ${min_version})"
|
||||
COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake ${min_version})"
|
||||
COMMAND mkdir -pv ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
||||
&& ${cmake_binary} -Werror=dev ${PROJECT_SOURCE_DIR} -D${flag}=ON
|
||||
DEPENDS ${cmake_binary}
|
||||
)
|
||||
list(APPEND JSON_CMAKE_FLAG_TARGETS ${flag_target}_${min_version_var})
|
||||
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var})
|
||||
list(APPEND JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGET} ${flag_target}_${min_version_var})
|
||||
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target} ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var})
|
||||
set(JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGETS} PARENT_SCOPE)
|
||||
set(JSON_CMAKE_FLAG_BUILD_DIRS ${JSON_CMAKE_FLAG_BUILD_DIRS} PARENT_SCOPE)
|
||||
endfunction()
|
||||
@@ -724,20 +699,6 @@ foreach(JSON_CMAKE_FLAG ${JSON_CMAKE_FLAGS_4_0_0})
|
||||
ci_add_cmake_flags_targets(${JSON_CMAKE_FLAG} 4.0.0)
|
||||
endforeach()
|
||||
|
||||
# check the same flags with the CMake version running this build
|
||||
foreach(JSON_CMAKE_FLAG ${JSON_CMAKE_FLAGS_4_0_0})
|
||||
string(TOLOWER "ci_cmake_flag_${JSON_CMAKE_FLAG}" flag_target)
|
||||
add_custom_target(${flag_target}
|
||||
COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake ${CMAKE_VERSION})"
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-Werror=dev
|
||||
-D${JSON_CMAKE_FLAG}=ON
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_${flag_target}
|
||||
)
|
||||
list(APPEND JSON_CMAKE_FLAG_TARGETS ${flag_target})
|
||||
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target})
|
||||
endforeach()
|
||||
|
||||
add_custom_target(ci_cmake_flags
|
||||
DEPENDS ${JSON_CMAKE_FLAG_TARGETS}
|
||||
COMMENT "Check CMake flags"
|
||||
@@ -891,11 +852,17 @@ add_custom_target(ci_test_build_documentation
|
||||
COMMENT "Build the documentation"
|
||||
)
|
||||
|
||||
add_custom_target(ci_test_documentation_mermaid
|
||||
COMMAND make check_mermaid
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs/mkdocs
|
||||
COMMENT "Check the Mermaid diagrams of the documentation"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Clean up all generated files.
|
||||
###############################################################################
|
||||
|
||||
add_custom_target(ci_clean
|
||||
COMMAND rm -fr ${PROJECT_BINARY_DIR}/build_* ${PROJECT_BINARY_DIR}/cmake-3.5.0 ${PROJECT_BINARY_DIR}/cmake-3.31.6 ${PROJECT_BINARY_DIR}/cmake-4.0.0 ${JSON_CMAKE_FLAG_BUILD_DIRS} ${single_binaries}
|
||||
COMMAND rm -fr ${PROJECT_BINARY_DIR}/build_* cmake-3.5.0-Darwin64 ${JSON_CMAKE_FLAG_BUILD_DIRS} ${single_binaries}
|
||||
COMMENT "Clean generated directories"
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# -Wno-c++98-compat The library targets C++11.
|
||||
# -Wno-c++98-compat-pedantic The library targets C++11.
|
||||
# -Wno-deprecated-declarations The library contains annotations for deprecated functions.
|
||||
# -Wno-extra-semi-stmt The library uses assert which triggers this warning.
|
||||
# -Wno-padded We do not care about padding warnings.
|
||||
# -Wno-covered-switch-default All switches list all cases and a default case.
|
||||
# -Wno-c2y-extensions Clang 22.1 diagnoses __COUNTER__ as a C2y extension, also in
|
||||
@@ -19,6 +20,7 @@ set(CLANG_CXXFLAGS
|
||||
-Wno-c++98-compat
|
||||
-Wno-c++98-compat-pedantic
|
||||
-Wno-deprecated-declarations
|
||||
-Wno-extra-semi-stmt
|
||||
-Wno-padded
|
||||
-Wno-covered-switch-default
|
||||
-Wno-c2y-extensions
|
||||
|
||||
+13
-24
@@ -1,4 +1,4 @@
|
||||
# Warning flags determined for GCC 16.2.0 with https://github.com/nlohmann/gcc_flags:
|
||||
# Warning flags determined for GCC 15.1.0 with https://github.com/nlohmann/gcc_flags:
|
||||
# Ignored GCC warnings:
|
||||
# -Wno-abi-tag We do not care about ABI tags.
|
||||
# -Wno-aggregate-return The library uses aggregate returns.
|
||||
@@ -16,8 +16,6 @@ set(GCC_CXXFLAGS
|
||||
--extra-warnings
|
||||
-W
|
||||
-WNSObject-attribute
|
||||
-Wabbreviated-auto-in-template-arg
|
||||
-Wabi
|
||||
-Wno-abi-tag
|
||||
-Waddress
|
||||
-Waddress-of-packed-member
|
||||
@@ -66,7 +64,6 @@ set(GCC_CXXFLAGS
|
||||
-Wanalyzer-tainted-divisor
|
||||
-Wanalyzer-tainted-offset
|
||||
-Wanalyzer-tainted-size
|
||||
-Wanalyzer-throw-of-unexpected-type
|
||||
-Wanalyzer-too-complex
|
||||
-Wanalyzer-undefined-behavior-ptrdiff
|
||||
-Wanalyzer-undefined-behavior-strtok
|
||||
@@ -83,13 +80,10 @@ set(GCC_CXXFLAGS
|
||||
-Warith-conversion
|
||||
-Warray-bounds=2
|
||||
-Warray-compare
|
||||
-Warray-parameter
|
||||
-Warray-parameter=2
|
||||
-Wattribute-alias=2
|
||||
-Wattribute-warning
|
||||
-Wattributes
|
||||
-Wauto-profile
|
||||
-Wbidi-chars=any
|
||||
-Wbool-compare
|
||||
-Wbool-operation
|
||||
-Wbuiltin-declaration-mismatch
|
||||
@@ -105,7 +99,6 @@ set(GCC_CXXFLAGS
|
||||
-Wc++20-compat
|
||||
-Wc++20-extensions
|
||||
-Wc++23-extensions
|
||||
-Wc++26-compat
|
||||
-Wc++26-extensions
|
||||
-Wc++2a-compat
|
||||
-Wcalloc-transposed-args
|
||||
@@ -149,7 +142,6 @@ set(GCC_CXXFLAGS
|
||||
-Wdeprecated-enum-enum-conversion
|
||||
-Wdeprecated-enum-float-conversion
|
||||
-Wdeprecated-literal-operator
|
||||
-Wdeprecated-openmp
|
||||
-Wdeprecated-variadic-comma-omission
|
||||
-Wdisabled-optimization
|
||||
-Wdiv-by-zero
|
||||
@@ -164,18 +156,21 @@ set(GCC_CXXFLAGS
|
||||
-Wenum-conversion
|
||||
-Wexceptions
|
||||
-Wexpansion-to-defined
|
||||
-Wexperimental-fmv-target
|
||||
-Wexpose-global-module-tu-local
|
||||
-Wexternal-tu-local
|
||||
-Wextra
|
||||
-Wextra-semi
|
||||
-Wflex-array-member-not-at-end
|
||||
-Wfloat-conversion
|
||||
-Wfloat-equal
|
||||
-Wformat-diag
|
||||
-Wformat-overflow=2
|
||||
-Wformat-signedness
|
||||
-Wformat-truncation=2
|
||||
-Wformat -Wformat-contains-nul
|
||||
-Wformat -Wformat-diag
|
||||
-Wformat -Wformat-extra-args
|
||||
-Wformat -Wformat-nonliteral
|
||||
-Wformat -Wformat-overflow=2
|
||||
-Wformat -Wformat-security
|
||||
-Wformat -Wformat-signedness
|
||||
-Wformat -Wformat-truncation=2
|
||||
-Wformat -Wformat-y2k
|
||||
-Wformat -Wformat-zero-length
|
||||
-Wformat=2
|
||||
-Wframe-address
|
||||
-Wfree-nonheap-object
|
||||
@@ -202,8 +197,6 @@ set(GCC_CXXFLAGS
|
||||
-Winvalid-offsetof
|
||||
-Winvalid-pch
|
||||
-Winvalid-utf8
|
||||
-Wkeyword-macro
|
||||
-Wleading-whitespace=spaces
|
||||
-Wliteral-suffix
|
||||
-Wlogical-not-parentheses
|
||||
-Wlogical-op
|
||||
@@ -234,7 +227,6 @@ set(GCC_CXXFLAGS
|
||||
-Wnarrowing
|
||||
-Wnoexcept
|
||||
-Wnoexcept-type
|
||||
-Wnon-c-typedef-for-linkage
|
||||
-Wnon-template-friend
|
||||
-Wnon-virtual-dtor
|
||||
-Wnonnull
|
||||
@@ -277,8 +269,6 @@ set(GCC_CXXFLAGS
|
||||
-Wscalar-storage-order
|
||||
-Wself-move
|
||||
-Wsequence-point
|
||||
-Wsfinae-incomplete
|
||||
-Wsfinae-incomplete=2
|
||||
-Wshadow=compatible-local
|
||||
-Wshadow=global
|
||||
-Wshadow=local
|
||||
@@ -299,7 +289,6 @@ set(GCC_CXXFLAGS
|
||||
-Wstrict-aliasing=3
|
||||
-Wstrict-null-sentinel
|
||||
-Wstrict-overflow
|
||||
-Wstrict-overflow=5
|
||||
-Wstring-compare
|
||||
-Wstringop-overflow
|
||||
-Wstringop-overflow=4
|
||||
@@ -344,8 +333,8 @@ set(GCC_CXXFLAGS
|
||||
-Wunreachable-code
|
||||
-Wunsafe-loop-optimizations
|
||||
-Wunused
|
||||
-Wunused-but-set-parameter=3
|
||||
-Wunused-but-set-variable=3
|
||||
-Wunused-but-set-parameter
|
||||
-Wunused-but-set-variable
|
||||
-Wunused-const-variable=2
|
||||
-Wunused-function
|
||||
-Wunused-label
|
||||
|
||||
+8
-18
@@ -11,31 +11,20 @@ EXAMPLES = $(wildcard mkdocs/docs/examples/*.cpp)
|
||||
|
||||
cxx_standard = $(lastword c++11 $(filter c++%, $(subst ., ,$1)))
|
||||
|
||||
# common compile flags for the stand-alone example files
|
||||
EXAMPLE_CPPFLAGS = -I $(SRCDIR) -DJSON_USE_GLOBAL_UDLS=0
|
||||
EXAMPLE_WARNFLAGS = -Werror=deprecated-declarations
|
||||
|
||||
# examples that document deprecated API and are allowed to use it
|
||||
DEPRECATED_EXAMPLES = $(addprefix mkdocs/docs/examples/, \
|
||||
json_pointer__operator__equal_stringtype \
|
||||
json_pointer__operator__notequal_stringtype \
|
||||
json_pointer__operator_string_t)
|
||||
$(DEPRECATED_EXAMPLES:=.output) $(DEPRECATED_EXAMPLES:=.test): EXAMPLE_WARNFLAGS = -Wno-deprecated-declarations
|
||||
|
||||
# create output from a stand-alone example file
|
||||
%.output: %.cpp
|
||||
@echo "standard $(call cxx_standard,$(<:.cpp=))"
|
||||
@echo "standard $(call cxx_standard $(<:.cpp=))"
|
||||
$(MAKE) $(<:.cpp=) \
|
||||
CPPFLAGS="$(EXAMPLE_CPPFLAGS)" \
|
||||
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) $(EXAMPLE_WARNFLAGS)"
|
||||
CPPFLAGS="-I $(SRCDIR) -DJSON_USE_GLOBAL_UDLS=0" \
|
||||
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) -Wno-deprecated-declarations"
|
||||
./$(<:.cpp=) > $@
|
||||
rm $(<:.cpp=)
|
||||
|
||||
# compare created output with current output of the example files
|
||||
%.test: %.cpp
|
||||
$(MAKE) $(<:.cpp=) \
|
||||
CPPFLAGS="$(EXAMPLE_CPPFLAGS)" \
|
||||
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) $(EXAMPLE_WARNFLAGS)"
|
||||
CPPFLAGS="-I $(SRCDIR) -DJSON_USE_GLOBAL_UDLS=0" \
|
||||
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) -Wno-deprecated-declarations"
|
||||
./$(<:.cpp=) > $@
|
||||
diff $@ $(<:.cpp=.output)
|
||||
rm $(<:.cpp=) $@
|
||||
@@ -46,9 +35,10 @@ create_output: $(EXAMPLES:.cpp=.output)
|
||||
# check output of all stand-alone example files
|
||||
check_output: $(EXAMPLES:.cpp=.test)
|
||||
|
||||
# check output of all stand-alone example files (exclude files with platform-dependent output.)
|
||||
# check output of all stand-alone example files (exclude files whose output depends on the platform by nature:
|
||||
# library and compiler information, container size limits, and hash values)
|
||||
# This target is used in the CI (ci_test_documentation).
|
||||
check_output_portable: $(filter-out mkdocs/docs/examples/meta.test mkdocs/docs/examples/max_size.test mkdocs/docs/examples/std_hash.test mkdocs/docs/examples/basic_json__CompatibleType.test,$(EXAMPLES:.cpp=.test))
|
||||
check_output_portable: $(filter-out mkdocs/docs/examples/meta.test mkdocs/docs/examples/max_size.test mkdocs/docs/examples/std_hash.test,$(EXAMPLES:.cpp=.test))
|
||||
|
||||
clean:
|
||||
rm -fr $(EXAMPLES:.cpp=)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<key>dashIndexFilePath</key>
|
||||
<string>index.html</string>
|
||||
<key>DashDocSetFallbackURL</key>
|
||||
<string>https://json.nlohmann.me/</string>
|
||||
<string>https://nlohmann.github.io/json/</string>
|
||||
<key>isJavaScriptEnabled</key>
|
||||
<true/>
|
||||
</dict>
|
||||
|
||||
+22
-12
@@ -52,25 +52,35 @@ install_docset_zeal: JSON_for_Modern_C++.docset
|
||||
mkdir -p $$docset_root; \
|
||||
cp -r JSON_for_Modern_C++.docset $$docset_root/
|
||||
|
||||
# both targets below compare the docset search index with the mkdocs page
|
||||
# set. They share the same normalization (docs/foo/index.md and
|
||||
# docs/foo.md both become foo/index.html, the URL mkdocs itself would
|
||||
# give the page; the top-level index.md is excluded, as it is not part
|
||||
# of the hand-curated docSet.sql) and use comm(1) on two sorted lists
|
||||
# instead of running a sqlite3 query, or an O(n*m) nested shell loop,
|
||||
# once per page.
|
||||
DOCSET_INDEX_PATHS=$(shell sqlite3 docSet.dsidx "SELECT DISTINCT path FROM searchIndex" | sort)
|
||||
DOCSET_PAGE_PATHS=$(shell echo '$(MKDOCS_PAGES)' | tr ' ' '\n' | grep -v '^index\.md$$' | $(SED) -E 's@/index\.md$$@/index.html@; s@\.md$$@/index.html@' | sort)
|
||||
|
||||
# list mkdocs pages missing from the docset index
|
||||
.PHONY: list_missing_pages
|
||||
list_missing_pages: docSet.dsidx
|
||||
@comm -23 <(echo '$(DOCSET_PAGE_PATHS)' | tr ' ' '\n') <(echo '$(DOCSET_INDEX_PATHS)' | tr ' ' '\n')
|
||||
@for page in $(MKDOCS_PAGES); do \
|
||||
case "$$page" in \
|
||||
*/index.md) path=$${page/\/index.md/} ;; \
|
||||
*) path=$${page/.md/} ;; \
|
||||
esac; \
|
||||
if [ "x$$page" != "xindex.md" -a "x$$(sqlite3 docSet.dsidx "SELECT COUNT(*) FROM searchIndex WHERE path='$$path/index.html'")" = "x0" ]; then \
|
||||
echo $$page; \
|
||||
fi \
|
||||
done
|
||||
|
||||
# list paths in the docset index without a corresponding mkdocs page
|
||||
.PHONY: list_removed_paths
|
||||
list_removed_paths: docSet.dsidx
|
||||
@comm -13 <(echo '$(DOCSET_PAGE_PATHS)' | tr ' ' '\n') <(echo '$(DOCSET_INDEX_PATHS)' | tr ' ' '\n')
|
||||
@for path in $$(sqlite3 docSet.dsidx "SELECT path FROM searchIndex"); do \
|
||||
page=$${path/\/index.html/.md}; \
|
||||
page_index=$${path/index.html/index.md}; \
|
||||
page_found=0; \
|
||||
for p in $(MKDOCS_PAGES); do \
|
||||
if [ "x$$p" = "x$$page" -o "x$$p" = "x$$page_index" ]; then \
|
||||
page_found=1; \
|
||||
fi \
|
||||
done; \
|
||||
if [ "x$$page_found" = "x0" ]; then \
|
||||
echo $$path; \
|
||||
fi \
|
||||
done
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
||||
@@ -7,11 +7,10 @@ documentation browsers like [Dash](https://kapeli.com/dash), [Velocity](https://
|
||||
The docset can be created with
|
||||
|
||||
```sh
|
||||
make JSON_for_Modern_C++.docset
|
||||
make nlohmann_json.docset
|
||||
```
|
||||
|
||||
The generated folder `JSON_for_Modern_C++.docset` can then be opened in the documentation browser. `make all` builds a
|
||||
`JSON_for_Modern_C++.tgz` archive instead, and `make install_docset_zeal` installs the docset for Zeal directly.
|
||||
The generated folder `nlohmann_json.docset` can then be opened in the documentation browser.
|
||||
|
||||
A recent version is also part of the [Dash user contributions](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B).
|
||||
|
||||
|
||||
+36
-1
@@ -10,9 +10,12 @@ INSERT INTO searchIndex(name, type, path) VALUES ('byte_container_with_subtype',
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('byte_container_with_subtype::byte_container_with_subtype', 'Constructor', 'api/byte_container_with_subtype/byte_container_with_subtype/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('byte_container_with_subtype::clear_subtype', 'Method', 'api/byte_container_with_subtype/clear_subtype/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('byte_container_with_subtype::has_subtype', 'Method', 'api/byte_container_with_subtype/has_subtype/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('byte_container_with_subtype::operator!=', 'Operator', 'api/byte_container_with_subtype/operator_ne/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('byte_container_with_subtype::operator==', 'Operator', 'api/byte_container_with_subtype/operator_eq/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('byte_container_with_subtype::set_subtype', 'Method', 'api/byte_container_with_subtype/set_subtype/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('byte_container_with_subtype::subtype', 'Method', 'api/byte_container_with_subtype/subtype/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json', 'Class', 'api/basic_json/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('format_as', 'Function', 'api/basic_json/format_as/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json::accept', 'Function', 'api/basic_json/accept/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json::array', 'Function', 'api/basic_json/array/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('basic_json::array_t', 'Type', 'api/basic_json/array_t/index.html');
|
||||
@@ -132,15 +135,19 @@ INSERT INTO searchIndex(name, type, path) VALUES ('json', 'Class', 'api/json/ind
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer', 'Class', 'api/json_pointer/index.html');
|
||||
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::front', 'Method', 'api/json_pointer/front/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');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::operator<=>', 'Operator', 'api/json_pointer/operator_spaceship/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::parent_pointer', 'Method', 'api/json_pointer/parent_pointer/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::pop_back', 'Method', 'api/json_pointer/pop_back/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::pop_front', 'Method', 'api/json_pointer/pop_front/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::push_back', 'Method', 'api/json_pointer/push_back/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::push_front', 'Method', 'api/json_pointer/push_front/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::string_t', 'Type', 'api/json_pointer/string_t/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_pointer::to_string', 'Method', 'api/json_pointer/to_string/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('json_sax', 'Class', 'api/json_sax/index.html');
|
||||
@@ -163,6 +170,7 @@ INSERT INTO searchIndex(name, type, path) VALUES ('operator<<', 'Operator', 'api
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('operator>>', 'Operator', 'api/operator_gtgt/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('ordered_json', 'Class', 'api/ordered_json/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('ordered_map', 'Class', 'api/ordered_map/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('std::formatter<basic_json>', 'Class', 'api/basic_json/std_formatter/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('std::hash<basic_json>', 'Class', 'api/basic_json/std_hash/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('std::swap<basic_json>', 'Function', 'api/basic_json/std_swap/index.html');
|
||||
|
||||
@@ -195,54 +203,81 @@ INSERT INTO searchIndex(name, type, path) VALUES ('nlohmann Namespace', 'Guide',
|
||||
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');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Performance', 'Guide', 'features/performance/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Parsing', 'Guide', 'features/parsing/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Parsing: JSON Lines', 'Guide', 'features/parsing/json_lines/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Parsing: Parser Callbacks', 'Guide', 'features/parsing/parser_callbacks/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Parsing: Parsing and Exceptions', 'Guide', 'features/parsing/parse_exceptions/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Parsing: SAX Interface', 'Guide', 'features/parsing/sax_interface/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Parsing: Untrusted Input', 'Guide', 'features/parsing/untrusted_input/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Runtime Assertions', 'Guide', 'features/assertions/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Specializing enum conversion', 'Guide', 'features/enum_conversion/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Supported Macros', 'Guide', 'features/macros/index.html');
|
||||
|
||||
-- Macros
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_ASSERT', 'Macro', 'api/macros/json_assert/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_BRACE_INIT_COPY_SEMANTICS', 'Macro', 'api/macros/json_brace_init_copy_semantics/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_CATCH_USER', 'Macro', 'api/macros/json_throw_user/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DIAGNOSTICS', 'Macro', 'api/macros/json_diagnostics/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DIAGNOSTIC_POSITIONS', 'Macro', 'api/macros/json_diagnostic_positions/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DISABLE_ENUM_SERIALIZATION', 'Macro', 'api/macros/json_disable_enum_serialization/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DISABLE_TUPLE_REFERENCE_CONVERSION', 'Macro', 'api/macros/json_disable_tuple_reference_conversion/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_11', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_14', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_17', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_20', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_23', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_26', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_EXPERIMENTAL_FILESYSTEM', 'Macro', 'api/macros/json_has_filesystem/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_FILESYSTEM', 'Macro', 'api/macros/json_has_filesystem/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_RANGES', 'Macro', 'api/macros/json_has_ranges/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_STATIC_RTTI', 'Macro', 'api/macros/json_has_static_rtti/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_STD_FORMAT', 'Macro', 'api/macros/json_has_std_format/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_THREE_WAY_COMPARISON', 'Macro', 'api/macros/json_has_three_way_comparison/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_NOEXCEPTION', 'Macro', 'api/macros/json_noexception/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_NO_AUTOMATIC_UDLS', 'Macro', 'api/macros/json_no_automatic_udls/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_NO_IO', 'Macro', 'api/macros/json_no_io/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_NO_THREAD_LOCAL', 'Macro', 'api/macros/json_no_thread_local/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_PRECISE_STREAM_POSITION', 'Macro', 'api/macros/json_precise_stream_position/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_SKIP_LIBRARY_VERSION_CHECK', 'Macro', 'api/macros/json_skip_library_version_check/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_SKIP_UNSUPPORTED_COMPILER_CHECK', 'Macro', 'api/macros/json_skip_unsupported_compiler_check/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_STRICT_NUL_HANDLING', 'Macro', 'api/macros/json_strict_nul_handling/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_THROW_USER', 'Macro', 'api/macros/json_throw_user/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_TRY_USER', 'Macro', 'api/macros/json_throw_user/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_GLOBAL_UDLS', 'Macro', 'api/macros/json_use_global_udls/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_IMPLICIT_CONVERSIONS', 'Macro', 'api/macros/json_use_implicit_conversions/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON', 'Macro', 'api/macros/json_use_legacy_discarded_value_comparison/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_SIMDUTF', 'Macro', 'api/macros/json_use_simdutf/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('Macros', 'Macro', 'api/macros/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE', 'Macro', 'api/macros/nlohmann_define_derived_type/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE', 'Macro', 'api/macros/nlohmann_define_derived_type/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT', 'Macro', 'api/macros/nlohmann_define_derived_type/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE', 'Macro', 'api/macros/nlohmann_define_derived_type/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE', 'Macro', 'api/macros/nlohmann_define_derived_type/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT', 'Macro', 'api/macros/nlohmann_define_derived_type/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_INTRUSIVE', 'Macro', 'api/macros/nlohmann_define_type_intrusive/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE', 'Macro', 'api/macros/nlohmann_define_type_intrusive/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT', 'Macro', 'api/macros/nlohmann_define_type_intrusive/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE', 'Macro', 'api/macros/nlohmann_define_type_non_intrusive/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE', 'Macro', 'api/macros/nlohmann_define_type_non_intrusive/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT', 'Macro', 'api/macros/nlohmann_define_type_non_intrusive/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES', 'Macro', 'api/macros/nlohmann_define_type_with_names/index.html');
|
||||
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_SERIALIZE_ENUM_STRICT', 'Macro', 'api/macros/nlohmann_json_serialize_enum_strict/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');
|
||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_JSON_VERSION_PATCH', 'Macro', 'api/macros/nlohmann_json_version_major/index.html');
|
||||
|
||||
+12
-1
@@ -1,3 +1,8 @@
|
||||
# The MkDocs 2.0 banners of Material for MkDocs and ProperDocs (via mkdocs-redirects) are printed to stderr, not
|
||||
# logged, so they do not affect --strict; silence them anyway.
|
||||
export NO_MKDOCS_2_WARNING := true
|
||||
export DISABLE_MKDOCS_2_WARNING := true
|
||||
|
||||
# serve the site locally
|
||||
serve: style_check
|
||||
venv/bin/mkdocs serve
|
||||
@@ -8,11 +13,17 @@ serve_dirty: style_check
|
||||
# This target is used in the CI (ci_test_build_documentation).
|
||||
# This target is used by the docset Makefile.
|
||||
build: style_check
|
||||
venv/bin/mkdocs build
|
||||
venv/bin/mkdocs build --strict
|
||||
|
||||
style_check:
|
||||
@cd docs ; ../venv/bin/python3 ../scripts/check_structure.py
|
||||
|
||||
# check that all Mermaid diagrams parse (needs Node.js)
|
||||
# This target is used in the CI (ci_test_documentation_mermaid).
|
||||
check_mermaid:
|
||||
npm ci --prefix scripts/mermaid --ignore-scripts --no-audit --no-fund
|
||||
node scripts/mermaid/check_mermaid.mjs docs
|
||||
|
||||
# check the links in the documentation files in docs/mkdocs
|
||||
link_check:
|
||||
ENABLED_HTMLPROOFER=true venv/bin/mkdocs build
|
||||
|
||||
@@ -96,7 +96,7 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: (1) reading from a string"
|
||||
|
||||
The example below demonstrates the `accept()` function reading from a string.
|
||||
|
||||
@@ -110,6 +110,21 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
--8<-- "examples/accept__string.output"
|
||||
```
|
||||
|
||||
??? example "Example: (2) reading from an iterator pair"
|
||||
|
||||
The example below demonstrates the `accept()` function reading from an iterator pair. Only the first call covers
|
||||
exactly the JSON text; the second one also covers the trailing bytes and is therefore rejected.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/accept__iterator_pair.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/accept__iterator_pair.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [parse](parse.md) - deserialize from a compatible input
|
||||
@@ -137,3 +152,5 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
|
||||
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
|
||||
function.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#parsing) for how to update existing code.
|
||||
|
||||
@@ -25,7 +25,7 @@ To store objects in C++, a type is defined by the template parameters explained
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
### Default type
|
||||
|
||||
With the default values for `ArrayType` (`std::vector`) and `AllocatorType` (`std::allocator`), the default value for
|
||||
`array_t` is:
|
||||
@@ -37,7 +37,7 @@ std::vector<
|
||||
>
|
||||
```
|
||||
|
||||
#### Limits
|
||||
### Limits
|
||||
|
||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) specifies:
|
||||
> An implementation may set limits on the maximum depth of nesting.
|
||||
@@ -46,7 +46,7 @@ In this class, the array's limit of nesting is not explicitly constrained. Howev
|
||||
introduced by the compiler or runtime environment. A theoretical limit can be queried by calling the
|
||||
[`max_size`](max_size.md) function of a JSON array.
|
||||
|
||||
#### Storage
|
||||
### Storage
|
||||
|
||||
Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of type
|
||||
`#!cpp array_t*` must be dereferenced.
|
||||
@@ -67,6 +67,13 @@ Arrays are stored as pointers in a `basic_json` type. That is, for any access to
|
||||
--8<-- "examples/array_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [object_t](object_t.md) the type used to store JSON objects
|
||||
- [binary_t](binary_t.md) the type used to store binary values
|
||||
- [is_array](is_array.md) checks whether the JSON value is an array
|
||||
- [max_size](max_size.md) returns the maximum possible number of elements
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -92,6 +92,20 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
||||
3. Logarithmic in the size of the container.
|
||||
4. Logarithmic in the size of the container.
|
||||
|
||||
## Notes
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
Overload (4) also accepts a [`json_pointer`](../json_pointer/index.md) whose template argument is a `basic_json`
|
||||
specialization (e.g., `nlohmann::json_pointer<nlohmann::json>`) instead of a string type. This is deprecated since
|
||||
version 3.11.0 and will be removed in a future major version; use `basic_json::json_pointer` (for `json`,
|
||||
`nlohmann::json_pointer<std::string>`) instead.
|
||||
|
||||
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
|
||||
function.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#json-pointers) for how to update existing code.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example: (1) access specified array element with bounds checking"
|
||||
|
||||
@@ -99,6 +99,25 @@ basic_json(basic_json&& other) noexcept;
|
||||
elements of the pairs are treated as keys and the second elements are as values.
|
||||
3. In all other cases, an array is created.
|
||||
|
||||
The following flowchart also takes into account what happens when `type_deduction` is `#!cpp false`, in which case
|
||||
`manual_type` decides between object and array, and an object can only be forced if `init` actually matches rule 2
|
||||
(or is empty):
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
A(["initializer_list init"]) --> B{"empty, or every element is a 2-element<br/>array whose first element is a string?"}
|
||||
B -->|"yes"| C{"type_deduction"}
|
||||
B -->|"no"| D{"type_deduction"}
|
||||
C -->|"true"| OBJ["create object"]
|
||||
C -->|"false"| E{"manual_type"}
|
||||
E -->|"object"| OBJ
|
||||
E -->|"array"| ARR["create array"]
|
||||
D -->|"true"| ARR
|
||||
D -->|"false"| F{"manual_type"}
|
||||
F -->|"array"| ARR
|
||||
F -->|"object"| ERR["throw type_error.301"]
|
||||
```
|
||||
|
||||
The rules aim to create the best fit between a C++ initializer list and JSON values. The rationale is as follows:
|
||||
|
||||
1. The empty initializer list is written as `#!cpp {}` which is exactly an empty JSON object.
|
||||
@@ -159,8 +178,6 @@ basic_json(basic_json&& other) noexcept;
|
||||
- `CompatibleType` is not `basic_json` (to avoid hijacking copy/move constructors),
|
||||
- `CompatibleType` is not a different `basic_json` type (i.e. with different template arguments)
|
||||
- `CompatibleType` is not a `basic_json` nested type (e.g., `json_pointer`, `iterator`, etc.)
|
||||
- if [`JSON_DISABLE_TUPLE_REFERENCE_CONVERSION`](../macros/json_disable_tuple_reference_conversion.md) is defined
|
||||
to `1`: `CompatibleType` is not a one-element `std::tuple` holding a reference to `basic_json`
|
||||
- `json_serializer<U>` (with `U = uncvref_t<CompatibleType>`) has a `to_json(basic_json_t&, CompatibleType&&)`
|
||||
method
|
||||
|
||||
@@ -171,8 +188,8 @@ basic_json(basic_json&& other) noexcept;
|
||||
- `BasicJsonType` has different template arguments than `basic_json_t`.
|
||||
|
||||
**Note:** For cross-`basic_json` conversions to produce correct results, the target `basic_json`'s
|
||||
`object_t::key_type` and `string_t` must be directly constructible from the source `basic_json`'s
|
||||
corresponding types. See the description of overload (4) above for details on what happens when
|
||||
[`object_t`](object_t.md)`::key_type` and [`string_t`](string_t.md) must be directly constructible from the source
|
||||
`basic_json`'s corresponding types. See the description of overload (4) above for details on what happens when
|
||||
this requirement is not met.
|
||||
|
||||
`U`:
|
||||
@@ -347,6 +364,22 @@ basic_json(basic_json&& other) noexcept;
|
||||
|
||||
Note the output is platform-dependent.
|
||||
|
||||
??? example "Example: (4) create a JSON value from another `basic_json` specialization"
|
||||
|
||||
The example below shows how a `json` value is converted to an `ordered_json` value and back using the converting
|
||||
constructor. Note how the original insertion order of `oj` is not restored, because it was already given up when
|
||||
converting to `json`, whose `object_t` sorts by key.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/basic_json__BasicJsonType.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/basic_json__BasicJsonType.output"
|
||||
```
|
||||
|
||||
??? example "Example: (5) create a container (array or object) from an initializer list"
|
||||
|
||||
The example below shows how JSON values are created from initializer lists.
|
||||
@@ -417,6 +450,15 @@ basic_json(basic_json&& other) noexcept;
|
||||
--8<-- "examples/basic_json__moveconstructor.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [array](array.md) create a JSON array value, forcing array creation from an initializer list even when it looks like
|
||||
an object
|
||||
- [object](object.md) create a JSON object value, forcing object creation from an initializer list
|
||||
- [binary](binary.md) create a JSON binary array value
|
||||
- [operator=](operator=.md) copy assignment operator
|
||||
- [Creating JSON values](../../features/creating_values.md) - the article on creating JSON values
|
||||
|
||||
## Version history
|
||||
|
||||
1. Since version 1.0.0.
|
||||
|
||||
@@ -37,6 +37,14 @@ Constant.
|
||||
--8<-- "examples/begin.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [end](end.md) returns an iterator to one past the last element
|
||||
- [cbegin](cbegin.md) returns a const iterator to the first element
|
||||
- [rbegin](rbegin.md) returns a reverse iterator to the last element
|
||||
- [items](items.md) returns an iteration proxy to access keys and values during range-based for loops
|
||||
- [Iterators](../../features/iterators.md) - the article on iterators
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -7,9 +7,9 @@ static basic_json binary(typename binary_t::container_type&& init);
|
||||
|
||||
// (2)
|
||||
static basic_json binary(const typename binary_t::container_type& init,
|
||||
std::uint8_t subtype);
|
||||
typename binary_t::subtype_type subtype);
|
||||
static basic_json binary(typename binary_t::container_type&& init,
|
||||
std::uint8_t subtype);
|
||||
typename binary_t::subtype_type subtype);
|
||||
```
|
||||
|
||||
1. Creates a JSON binary array value from a given binary container.
|
||||
@@ -61,6 +61,15 @@ initialization of a binary array type, for backwards compatibility and so it doe
|
||||
--8<-- "examples/binary.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [binary_t](binary_t.md) type for binary values
|
||||
- [get_binary](get_binary.md) get a reference to the stored binary value
|
||||
- [is_binary](is_binary.md) return whether the value is binary
|
||||
- [byte_container_with_subtype](../byte_container_with_subtype/index.md) container for binary values with subtype
|
||||
- [Binary Values](../../features/binary_values.md) - the article on binary values
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.8.0.
|
||||
- Changed the type of `subtype` from `std::uint8_t` to `binary_t::subtype_type` (`std::uint64_t`) in version 3.10.0.
|
||||
|
||||
@@ -48,16 +48,16 @@ represent a byte array in modern C++.
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
### Default type
|
||||
|
||||
The default values for `BinaryType` is `#!cpp std::vector<std::uint8_t>`.
|
||||
|
||||
#### Supported byte types
|
||||
### Supported byte types
|
||||
|
||||
`#!cpp std::vector<std::uint8_t>`, `#!cpp std::vector<char>`, and `#!cpp std::vector<std::byte>` are supported.
|
||||
Regardless of which of them is configured, [`dump`](dump.md) writes the bytes as the numbers 0..255.
|
||||
|
||||
#### Custom BinaryType behavior
|
||||
### Custom BinaryType behavior
|
||||
|
||||
When a custom `BinaryType` is configured (other than the default `#!cpp std::vector<std::uint8_t>`), you can assign
|
||||
values of that type directly to a `basic_json` instance, and they will automatically be recognized as binary values
|
||||
@@ -89,12 +89,12 @@ assert(extracted == data);
|
||||
This automatic type detection is a convenience feature that only applies to custom (non-default) `BinaryType` configurations.
|
||||
The default `nlohmann::json` continues to treat `#!cpp std::vector<std::uint8_t>` as arrays for backward compatibility.
|
||||
|
||||
#### Storage
|
||||
### Storage
|
||||
|
||||
Binary Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of the
|
||||
type `#!cpp binary_t*` must be dereferenced.
|
||||
|
||||
#### Notes on subtypes
|
||||
### Notes on subtypes
|
||||
|
||||
- CBOR
|
||||
- Binary values are represented as byte strings. Subtypes are written as tags.
|
||||
|
||||
@@ -21,11 +21,11 @@ To store boolean values in C++, a type is defined by the template parameter `Bo
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
### Default type
|
||||
|
||||
With the default values for `BooleanType` (`#!cpp bool`), the default value for `boolean_t` is `#!cpp bool`.
|
||||
|
||||
#### Storage
|
||||
### Storage
|
||||
|
||||
Boolean values are stored directly inside a `basic_json` type.
|
||||
|
||||
@@ -45,6 +45,10 @@ Boolean values are stored directly inside a `basic_json` type.
|
||||
--8<-- "examples/boolean_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [is_boolean](is_boolean.md) checks whether the JSON value is a boolean
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -36,6 +36,13 @@ Constant.
|
||||
--8<-- "examples/cbegin.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [begin](begin.md) returns an iterator to the first element
|
||||
- [cend](cend.md) returns a const iterator to one past the last element
|
||||
- [crbegin](crbegin.md) returns a const reverse iterator to the last element
|
||||
- [Iterators](../../features/iterators.md) - the article on iterators
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -38,6 +38,12 @@ store
|
||||
--8<-- "examples/cbor_tag_handler_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [from_cbor](from_cbor.md) deserializes a JSON value from CBOR
|
||||
- [input_format_t](input_format_t.md) the enumeration of supported input formats
|
||||
- [CBOR](../../features/binary_formats/cbor.md) - the article on the CBOR format
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.9.0. Added value `store` in 3.10.0.
|
||||
|
||||
@@ -36,6 +36,13 @@ Constant.
|
||||
--8<-- "examples/cend.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [end](end.md) returns an iterator to one past the last element
|
||||
- [cbegin](cbegin.md) returns a const iterator to the first element
|
||||
- [crend](crend.md) returns a const reverse iterator to one before the first element
|
||||
- [Iterators](../../features/iterators.md) - the article on iterators
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -52,6 +52,11 @@ All iterators, pointers, and references related to this container are invalidate
|
||||
--8<-- "examples/clear.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [erase](erase.md) removes elements from a JSON value
|
||||
- [empty](empty.md) checks whether the JSON value has no elements
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -67,6 +67,18 @@ Logarithmic in the size of the JSON object.
|
||||
|
||||
If `#!cpp j.contains(x)` returns `#!c true` for a key or JSON pointer `x`, then it is safe to call `j[x]`.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
Overload (3) also accepts a [`json_pointer`](../json_pointer/index.md) whose template argument is a `basic_json`
|
||||
specialization (e.g., `nlohmann::json_pointer<nlohmann::json>`) instead of a string type. This is deprecated since
|
||||
version 3.11.0 and will be removed in a future major version; use `basic_json::json_pointer` (for `json`,
|
||||
`nlohmann::json_pointer<std::string>`) instead.
|
||||
|
||||
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
|
||||
function.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#json-pointers) for how to update existing code.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example: (1) check with key"
|
||||
|
||||
@@ -36,6 +36,13 @@ Constant.
|
||||
--8<-- "examples/crbegin.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [crend](crend.md) returns a const reverse iterator to one before the first element
|
||||
- [rbegin](rbegin.md) returns a reverse iterator to the last element
|
||||
- [cbegin](cbegin.md) returns a const iterator to the first element
|
||||
- [Iterators](../../features/iterators.md) - the article on iterators
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -37,6 +37,13 @@ Constant.
|
||||
--8<-- "examples/crend.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [crbegin](crbegin.md) returns a const reverse iterator to the last element
|
||||
- [rend](rend.md) returns a reverse iterator to one before the first element
|
||||
- [cend](cend.md) returns a const iterator to one past the last element
|
||||
- [Iterators](../../features/iterators.md) - the article on iterators
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -30,6 +30,11 @@ The actual comparator used depends on [`object_t`](object_t.md) and can be obtai
|
||||
--8<-- "examples/default_object_comparator_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [object_comparator_t](object_comparator_t.md) the comparator actually used by `object_t`
|
||||
- [object_t](object_t.md) the type used to store JSON objects
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.11.0.
|
||||
|
||||
@@ -31,7 +31,8 @@ a `#!cpp bool` denoting whether the insertion took place.
|
||||
|
||||
## Exception safety
|
||||
|
||||
Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||
Strong guarantee: if an exception is thrown, there are no changes to any JSON value. As an exception, a `#!json null`
|
||||
value is converted to an empty object before the element is added and keeps that type if adding the element throws.
|
||||
|
||||
## Exceptions
|
||||
|
||||
|
||||
@@ -28,6 +28,11 @@ iterator is invalidated.
|
||||
|
||||
reference to the inserted element
|
||||
|
||||
## Exception safety
|
||||
|
||||
Strong guarantee: if an exception is thrown, there are no changes to any JSON value. As an exception, a `#!json null`
|
||||
value is converted to an empty array before the element is added and keeps that type if adding the element throws.
|
||||
|
||||
## Exceptions
|
||||
|
||||
Throws [`type_error.311`](../../home/exceptions.md#jsonexceptiontype_error311) when called on a type other than JSON
|
||||
|
||||
@@ -60,6 +60,11 @@ itself is empty which is `#!cpp false` in the case of a string.
|
||||
--8<-- "examples/empty.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [size](size.md) returns the number of elements
|
||||
- [clear](clear.md) clears the content and resets the value to the default value
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -37,6 +37,13 @@ Constant.
|
||||
--8<-- "examples/end.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [begin](begin.md) returns an iterator to the first element
|
||||
- [cend](cend.md) returns a const iterator to one past the last element
|
||||
- [rend](rend.md) returns a reverse iterator to one before the first element
|
||||
- [Iterators](../../features/iterators.md) - the article on iterators
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -37,6 +37,11 @@ ignore
|
||||
--8<-- "examples/error_handler_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [dump](dump.md) serializes a JSON value, with an `error_handler_t` parameter to configure invalid UTF-8 handling
|
||||
- [Handling invalid UTF-8](../../features/serialization.md#handling-invalid-utf-8) - the article on handling invalid UTF-8
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.4.0.
|
||||
|
||||
@@ -27,7 +27,7 @@ Empty objects and arrays are flattened to `#!json null` and will not be reconstr
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: flatten a JSON object"
|
||||
|
||||
The following code shows how a JSON object is flattened to an object whose keys consist of JSON pointers.
|
||||
|
||||
@@ -41,6 +41,21 @@ Empty objects and arrays are flattened to `#!json null` and will not be reconstr
|
||||
--8<-- "examples/flatten.output"
|
||||
```
|
||||
|
||||
??? example "Example: empty objects and arrays are flattened to `#!json null`"
|
||||
|
||||
The following code shows that an empty object and an empty array are both flattened to `#!json null`, and that
|
||||
`unflatten()` restores them as `#!json null` rather than as empty containers.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/flatten__empty.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/flatten__empty.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [unflatten](unflatten.md) the reverse function
|
||||
|
||||
@@ -123,3 +123,5 @@ Linear in the size of the input.
|
||||
|
||||
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
|
||||
function.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#parsing) for how to update existing code.
|
||||
|
||||
@@ -133,3 +133,5 @@ Linear in the size of the input.
|
||||
|
||||
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
|
||||
function.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#parsing) for how to update existing code.
|
||||
|
||||
@@ -125,3 +125,5 @@ Linear in the size of the input.
|
||||
|
||||
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
|
||||
function.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#parsing) for how to update existing code.
|
||||
|
||||
@@ -124,3 +124,5 @@ Linear in the size of the input.
|
||||
|
||||
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
|
||||
function.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#parsing) for how to update existing code.
|
||||
|
||||
@@ -13,16 +13,16 @@ BasicJsonType get() const;
|
||||
|
||||
// (3)
|
||||
template<typename PointerType>
|
||||
PointerType get_ptr();
|
||||
PointerType get() noexcept;
|
||||
|
||||
template<typename PointerType>
|
||||
constexpr const PointerType get_ptr() const noexcept;
|
||||
const PointerType get() const noexcept; // constexpr since C++14
|
||||
```
|
||||
|
||||
1. Explicit type conversion between the JSON value and a compatible value which is
|
||||
[CopyConstructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible) and
|
||||
[DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible). The value is converted by
|
||||
calling the `json_serializer<ValueType>` `from_json()` method.
|
||||
calling the [`json_serializer<ValueType>`](json_serializer.md) `from_json()` method.
|
||||
|
||||
The function is equivalent to executing
|
||||
```cpp
|
||||
@@ -84,6 +84,12 @@ constexpr const PointerType get_ptr() const noexcept;
|
||||
3. pointer to the internally stored JSON value if the requested pointer type fits to the JSON value; `#!cpp nullptr`
|
||||
otherwise
|
||||
|
||||
## Exception safety
|
||||
|
||||
Depends on what `json_serializer<ValueType>` `from_json()` method throws for overloads (1) and (2); the JSON value
|
||||
itself is never modified, since `get()` is a `#!cpp const` member function. No-throw guarantee for overload (3): this
|
||||
function never throws exceptions.
|
||||
|
||||
## Exceptions
|
||||
|
||||
Depends on what `json_serializer<ValueType>` `from_json()` method throws
|
||||
@@ -123,13 +129,13 @@ overload (3).
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: (1) explicit conversion to compatible types"
|
||||
|
||||
The example below shows several conversions from JSON values
|
||||
to other types. There a few things to note: (1) Floating-point numbers can
|
||||
be converted to integers, (2) A JSON array can be converted to a standard
|
||||
`std::vector<short>`, (3) A JSON object can be converted to C++
|
||||
associative containers such as `std::unordered_map<std::string, json>`.
|
||||
associative containers such as `std::map<std::string, json>`.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/get__ValueType_const.cpp"
|
||||
@@ -141,7 +147,21 @@ overload (3).
|
||||
--8<-- "examples/get__ValueType_const.output"
|
||||
```
|
||||
|
||||
??? example
|
||||
??? example "Example: (2) explicit conversion to another `basic_json` specialization"
|
||||
|
||||
The example below shows how a `json` value is converted to an `ordered_json` value using `get<BasicJsonType>()`.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/get__BasicJsonType.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/get__BasicJsonType.output"
|
||||
```
|
||||
|
||||
??? example "Example: (3) explicit pointer access to the stored value"
|
||||
|
||||
The example below shows how pointers to internal values of a JSON value can be requested. Note that no type
|
||||
conversions are made and a `#cpp nullptr` is returned if the value and the requested pointer type does not match.
|
||||
|
||||
@@ -10,6 +10,14 @@ Returns the allocator associated with the container.
|
||||
|
||||
associated allocator
|
||||
|
||||
## Exception safety
|
||||
|
||||
Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||
|
||||
## Complexity
|
||||
|
||||
Constant.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
@@ -26,6 +34,11 @@ associated allocator
|
||||
--8<-- "examples/get_allocator.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [basic_json](index.md#template-parameters) the class template, with `AllocatorType` as one of its template parameters
|
||||
- [Template Parameter Requirements](../../features/types/template_parameters.md#allocatortype) - the requirements for `AllocatorType`
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -8,7 +8,7 @@ ValueType& get_to(ValueType& v) const noexcept(
|
||||
```
|
||||
|
||||
Explicit type conversion between the JSON value and a compatible value. The value is filled into the input parameter by
|
||||
calling the `json_serializer<ValueType>` `from_json()` method.
|
||||
calling the [`json_serializer<ValueType>`](json_serializer.md) `from_json()` method.
|
||||
|
||||
The function is equivalent to executing
|
||||
```cpp
|
||||
@@ -34,6 +34,11 @@ the compiler reports that no matching `get_to` was found.
|
||||
|
||||
the input parameter, allowing chaining calls
|
||||
|
||||
## Exception safety
|
||||
|
||||
Depends on what `json_serializer<ValueType>` `from_json()` method throws; the JSON value itself is never modified,
|
||||
since `get_to()` is a `#!cpp const` member function.
|
||||
|
||||
## Exceptions
|
||||
|
||||
Depends on what `json_serializer<ValueType>` `from_json()` method throws
|
||||
@@ -49,7 +54,7 @@ Depends on the `json_serializer<ValueType>::from_json()` implementation.
|
||||
The example below shows several conversions from JSON values to other types. There a few things to note: (1)
|
||||
Floating-point numbers can be converted to integers, (2) A JSON array can be converted to a standard
|
||||
`#!cpp std::vector<short>`, (3) A JSON object can be converted to C++ associative containers such as
|
||||
`#cpp std::unordered_map<std::string, json>`.
|
||||
`#!cpp std::map<std::string, json>`.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/get_to.cpp"
|
||||
|
||||
@@ -51,6 +51,11 @@ bon8
|
||||
--8<-- "examples/sax_parse__binary.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [sax_parse](sax_parse.md) generic SAX parse interface, taking an `input_format_t` to select the input format
|
||||
- [cbor_tag_handler_t](cbor_tag_handler_t.md) configures how CBOR tags are treated while parsing
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.2.0.
|
||||
|
||||
@@ -109,11 +109,11 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
||||
2. Linear in `cnt` plus linear in the distance between `pos` and end of the container.
|
||||
3. Linear in `#!cpp std::distance(first, last)` plus linear in the distance between `pos` and end of the container.
|
||||
4. Linear in `ilist.size()` plus linear in the distance between `pos` and end of the container.
|
||||
5. Logarithmic: `O(N*log(size() + N))`, where `N` is the number of elements to insert.
|
||||
5. `O(N*log(size() + N))`, where `N` is the number of elements to insert.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example (1): insert element into array"
|
||||
??? example "Example: (1) insert element into array"
|
||||
|
||||
The example shows how `insert()` is used.
|
||||
|
||||
@@ -127,7 +127,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
||||
--8<-- "examples/insert.output"
|
||||
```
|
||||
|
||||
??? example "Example (2): insert copies of element into array"
|
||||
??? example "Example: (2) insert copies of element into array"
|
||||
|
||||
The example shows how `insert()` is used.
|
||||
|
||||
@@ -141,7 +141,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
||||
--8<-- "examples/insert__count.output"
|
||||
```
|
||||
|
||||
??? example "Example (3): insert a range of elements into an array"
|
||||
??? example "Example: (3) insert a range of elements into an array"
|
||||
|
||||
The example shows how `insert()` is used.
|
||||
|
||||
@@ -155,7 +155,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
||||
--8<-- "examples/insert__range.output"
|
||||
```
|
||||
|
||||
??? example "Example (4): insert elements from an initializer list into an array"
|
||||
??? example "Example: (4) insert elements from an initializer list into an array"
|
||||
|
||||
The example shows how `insert()` is used.
|
||||
|
||||
@@ -169,7 +169,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
||||
--8<-- "examples/insert__ilist.output"
|
||||
```
|
||||
|
||||
??? example "Example (5): insert a range of elements into an object"
|
||||
??? example "Example: (5) insert a range of elements into an object"
|
||||
|
||||
The example shows how `insert()` is used.
|
||||
|
||||
|
||||
@@ -34,6 +34,13 @@ Constant.
|
||||
--8<-- "examples/is_array.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [is_object](is_object.md) checks whether the JSON value is an object
|
||||
- [is_structured](is_structured.md) checks whether the JSON value is structured (array or object)
|
||||
- [type](type.md) returns the type of the JSON value
|
||||
- [array_t](array_t.md) the type used to store JSON arrays
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -34,6 +34,12 @@ Constant.
|
||||
--8<-- "examples/is_binary.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [is_primitive](is_primitive.md) checks whether the JSON value is primitive
|
||||
- [binary_t](binary_t.md) the type used to store binary values
|
||||
- [get_binary](get_binary.md) returns a reference to the stored binary value
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.8.0.
|
||||
|
||||
@@ -34,6 +34,11 @@ Constant.
|
||||
--8<-- "examples/is_boolean.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [boolean_t](boolean_t.md) the type used to store JSON booleans
|
||||
- [is_primitive](is_primitive.md) checks whether the JSON value is primitive
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -55,7 +55,7 @@ with `allow_exceptions` set to `#!cpp false`: a parse error then yields a discar
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: `is_discarded()` for ordinary JSON values"
|
||||
|
||||
The following code exemplifies `is_discarded()` for all JSON types.
|
||||
|
||||
@@ -69,6 +69,22 @@ with `allow_exceptions` set to `#!cpp false`: a parse error then yields a discar
|
||||
--8<-- "examples/is_discarded.output"
|
||||
```
|
||||
|
||||
??? example "Example: discarded values from parsing"
|
||||
|
||||
The following code shows the two situations in which a discarded value can be observed: parsing invalid JSON with
|
||||
`allow_exceptions` set to `#!cpp false`, and a parser callback that discards the top-level value (which is replaced
|
||||
by `#!json null` and therefore does *not* remain discarded).
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/is_discarded__parse.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/is_discarded__parse.output"
|
||||
```
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -34,6 +34,13 @@ Constant.
|
||||
--8<-- "examples/is_null.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [is_array](is_array.md) checks whether the JSON value is an array
|
||||
- [is_object](is_object.md) checks whether the JSON value is an object
|
||||
- [type](type.md) returns the type of the JSON value
|
||||
- [value_t](value_t.md) the enumeration of JSON types
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -34,6 +34,13 @@ Constant.
|
||||
--8<-- "examples/is_object.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [is_array](is_array.md) checks whether the JSON value is an array
|
||||
- [is_structured](is_structured.md) checks whether the JSON value is structured (array or object)
|
||||
- [type](type.md) returns the type of the JSON value
|
||||
- [object_t](object_t.md) the type used to store JSON objects
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -34,6 +34,12 @@ Constant.
|
||||
--8<-- "examples/is_string.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [is_primitive](is_primitive.md) checks whether the JSON value is primitive
|
||||
- [type](type.md) returns the type of the JSON value
|
||||
- [string_t](string_t.md) the type used to store JSON strings
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -114,3 +114,5 @@ When iterating over an array, `key()` will return the index of the element as st
|
||||
|
||||
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
|
||||
function.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#miscellaneous-functions) for how to update existing code.
|
||||
|
||||
@@ -14,12 +14,12 @@ Examples of such functionality might be metadata, additional member functions (e
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
### Default type
|
||||
|
||||
The default value for `CustomBaseClass` is `void`. In this case, an
|
||||
[empty base class](https://en.cppreference.com/w/cpp/language/ebo) is used and no additional functionality is injected.
|
||||
|
||||
#### Limitations
|
||||
### Limitations
|
||||
|
||||
The type `CustomBaseClass` has to be a default-constructible, non-`final` class.
|
||||
`basic_json` only supports copy/move construction/assignment if `CustomBaseClass` does so as well.
|
||||
@@ -43,6 +43,10 @@ A `CustomBaseClass` with non-static data members forfeits `basic_json`'s
|
||||
--8<-- "examples/json_base_class_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [Template Parameter Requirements](../../features/types/template_parameters.md#custombaseclass) - the requirements for `CustomBaseClass`
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.12.0.
|
||||
|
||||
@@ -15,11 +15,11 @@ using json_serializer = JSONSerializer<T, SFINAE>;
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
### Default type
|
||||
|
||||
The default values for `json_serializer` is [`adl_serializer`](../adl_serializer/index.md).
|
||||
|
||||
#### Requirements
|
||||
### Requirements
|
||||
|
||||
A custom serializer must provide `#!cpp static void to_json(basic_json&, T)` for every type it serializes, and either
|
||||
`#!cpp static void from_json(const basic_json&, T&)` or `#!cpp static T from_json(const basic_json&)` for every type it
|
||||
@@ -42,6 +42,13 @@ deserializes. See [Template Parameter Requirements](../../features/types/templat
|
||||
--8<-- "examples/from_json__non_default_constructible.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [adl_serializer](../adl_serializer/index.md) the default `json_serializer`
|
||||
- [get](get.md) explicit type conversion using the `json_serializer`'s `from_json()` method
|
||||
- [get_to](get_to.md) explicit type conversion into a variable using the `json_serializer`'s `from_json()` method
|
||||
- [Arbitrary Type Conversions](../../features/arbitrary_types.md) - the article on converting between JSON values and arbitrary types
|
||||
|
||||
## Version history
|
||||
|
||||
- Since version 2.0.0.
|
||||
|
||||
@@ -54,6 +54,12 @@ string elements the JSON value can store which is `1`.
|
||||
|
||||
Note the output is platform-dependent.
|
||||
|
||||
## See also
|
||||
|
||||
- [size](size.md) returns the number of elements
|
||||
- [array_t](array_t.md) the type used to store JSON arrays
|
||||
- [object_t](object_t.md) the type used to store JSON objects
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -33,16 +33,14 @@ Thereby, `Target` is the current object; that is, the patch is applied to the cu
|
||||
`apply_patch` (in)
|
||||
: the patch to apply
|
||||
|
||||
## Exception safety
|
||||
|
||||
Basic guarantee: if an exception is thrown during the operation, the JSON value may be partially modified.
|
||||
|
||||
## Complexity
|
||||
|
||||
Linear in the lengths of `apply_patch`.
|
||||
|
||||
## Notes
|
||||
|
||||
`apply_patch` may be `#!cpp *this` itself or refer to a value contained in `#!cpp *this` (for example, a subobject
|
||||
returned by `#!cpp (*this)[key]`); it is read as it was when `merge_patch()` was called, before any modification of
|
||||
`#!cpp *this`.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
@@ -67,5 +65,3 @@ returned by `#!cpp (*this)[key]`); it is read as it was when `merge_patch()` was
|
||||
## Version history
|
||||
|
||||
- Added in version 3.0.0.
|
||||
- Fixed use of freed or relocated memory when `apply_patch` is `#!cpp *this` or refers to a value contained in
|
||||
`#!cpp *this`, in version 3.13.0.
|
||||
|
||||
@@ -23,28 +23,27 @@ type to use.
|
||||
## Template parameters
|
||||
|
||||
`NumberFloatType`
|
||||
: the type to store floating-point numbers. The parser converts `#!cpp float`, `#!cpp double`, and a
|
||||
`#!cpp long double` that is IEEE 754 binary64 itself and other `#!cpp long double` formats with
|
||||
`#!cpp std::from_chars` or `#!cpp std::strtold`, and serialization falls back to `#!cpp std::snprintf`, so the
|
||||
type must be `#!cpp float`, `#!cpp double`, or `#!cpp long double`. The
|
||||
: the type to store floating-point numbers. Parsing and serialization are implemented in terms of
|
||||
`#!cpp std::strtof`/`#!cpp std::strtod`/`#!cpp std::strtold` and `#!cpp std::snprintf`, so the type must be
|
||||
`#!cpp float`, `#!cpp double`, or `#!cpp long double`. The
|
||||
[binary formats](../../features/binary_formats/index.md) additionally require `#!cpp float` or `#!cpp double`,
|
||||
because they have no encoding for `#!cpp long double`. See
|
||||
[Template Parameter Requirements](../../features/types/template_parameters.md#numberfloattype).
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
### Default type
|
||||
|
||||
With the default values for `NumberFloatType` (`double`), the default value for `number_float_t` is `#!cpp double`.
|
||||
|
||||
#### Default behavior
|
||||
### Default behavior
|
||||
|
||||
- The restrictions about leading zeros are not enforced in C++. Instead, leading zeros in floating-point literals will
|
||||
be ignored. Internally, the value will be stored as a decimal number. For instance, the C++ floating-point literal
|
||||
`01.2` will be serialized to `1.2`. During deserialization, leading zeros yield an error.
|
||||
- Not-a-number (NaN) values will be serialized to `null`.
|
||||
|
||||
#### Limits
|
||||
### Limits
|
||||
|
||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) states:
|
||||
> This specification allows implementations to set limits on the range and precision of numbers accepted. Since software
|
||||
@@ -56,7 +55,7 @@ This implementation does exactly follow this approach, as it uses double precisi
|
||||
smaller than `-1.79769313486232e+308` and values greater than `1.79769313486232e+308` will be stored as NaN internally
|
||||
and be serialized to `null`.
|
||||
|
||||
#### Storage
|
||||
### Storage
|
||||
|
||||
Floating-point number values are stored directly inside a `basic_json` type.
|
||||
|
||||
@@ -76,6 +75,13 @@ Floating-point number values are stored directly inside a `basic_json` type.
|
||||
--8<-- "examples/number_float_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [number_integer_t](number_integer_t.md) the type used to store JSON integer numbers
|
||||
- [number_unsigned_t](number_unsigned_t.md) the type used to store JSON unsigned integer numbers
|
||||
- [is_number_float](is_number_float.md) checks whether the JSON value is a floating-point number
|
||||
- [Number Handling](../../features/types/number_handling.md) - the article on number handling
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -29,18 +29,18 @@ to use.
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
### Default type
|
||||
|
||||
With the default values for `NumberIntegerType` (`std::int64_t`), the default value for `number_integer_t` is
|
||||
`#!cpp std::int64_t`.
|
||||
|
||||
#### Default behavior
|
||||
### Default behavior
|
||||
|
||||
- The restrictions about leading zeros are not enforced in C++. Instead, leading zeros in integer literals lead to an
|
||||
interpretation as an octal number. Internally, the value will be stored as a decimal number. For instance, the C++
|
||||
integer literal `010` will be serialized to `8`. During deserialization, leading zeros yield an error.
|
||||
|
||||
#### Limits
|
||||
### Limits
|
||||
|
||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) specifies:
|
||||
> An implementation may set limits on the range and precision of numbers.
|
||||
@@ -51,13 +51,13 @@ range will yield over/underflow when used in a constructor. During deserializati
|
||||
will automatically be stored as [`number_unsigned_t`](number_unsigned_t.md) or [`number_float_t`](number_float_t.md).
|
||||
|
||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
||||
> Note that when such software is used, numbers that are integers and are in the range [-2<sup>53</sup>+1, 2<sup>53</sup>-1] are
|
||||
> Note that when such software is used, numbers that are integers and are in the range $[-2^{53}+1, 2^{53}-1]$ are
|
||||
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
||||
|
||||
As this range is a subrange of the exactly supported range [INT64_MIN, INT64_MAX], this class's integer type is
|
||||
interoperable.
|
||||
|
||||
#### Storage
|
||||
### Storage
|
||||
|
||||
Integer number values are stored directly inside a `basic_json` type.
|
||||
|
||||
@@ -77,6 +77,13 @@ Integer number values are stored directly inside a `basic_json` type.
|
||||
--8<-- "examples/number_integer_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [number_unsigned_t](number_unsigned_t.md) the type used to store JSON unsigned integer numbers
|
||||
- [number_float_t](number_float_t.md) the type used to store JSON floating-point numbers
|
||||
- [is_number_integer](is_number_integer.md) checks whether the JSON value is a signed integer number
|
||||
- [Number Handling](../../features/types/number_handling.md) - the article on number handling
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -30,18 +30,18 @@ the type to use.
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
### Default type
|
||||
|
||||
With the default values for `NumberUnsignedType` (`std::uint64_t`), the default value for `number_unsigned_t` is
|
||||
`#!cpp std::uint64_t`.
|
||||
|
||||
#### Default behavior
|
||||
### Default behavior
|
||||
|
||||
- The restrictions about leading zeros are not enforced in C++. Instead, leading zeros in integer literals lead to an
|
||||
interpretation as an octal number. Internally, the value will be stored as a decimal number. For instance, the C++
|
||||
integer literal `010` will be serialized to `8`. During deserialization, leading zeros yield an error.
|
||||
|
||||
#### Limits
|
||||
### Limits
|
||||
|
||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) specifies:
|
||||
> An implementation may set limits on the range and precision of numbers.
|
||||
@@ -52,13 +52,13 @@ when used in a constructor. During deserialization, too large or small integer n
|
||||
as [`number_integer_t`](number_integer_t.md) or [`number_float_t`](number_float_t.md).
|
||||
|
||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
||||
> Note that when such software is used, numbers that are integers and are in the range [-2<sup>53</sup>+1, 2<sup>53</sup>-1] are
|
||||
> Note that when such software is used, numbers that are integers and are in the range $[-2^{53}+1, 2^{53}-1]$ are
|
||||
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
||||
|
||||
As this range is a subrange (when considered in conjunction with the `number_integer_t` type) of the exactly supported
|
||||
range [0, UINT64_MAX], this class's integer type is interoperable.
|
||||
|
||||
#### Storage
|
||||
### Storage
|
||||
|
||||
Integer number values are stored directly inside a `basic_json` type.
|
||||
|
||||
@@ -78,6 +78,13 @@ Integer number values are stored directly inside a `basic_json` type.
|
||||
--8<-- "examples/number_unsigned_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [number_integer_t](number_integer_t.md) the type used to store JSON integer numbers
|
||||
- [number_float_t](number_float_t.md) the type used to store JSON floating-point numbers
|
||||
- [is_number_unsigned](is_number_unsigned.md) checks whether the JSON value is an unsigned integer number
|
||||
- [Number Handling](../../features/types/number_handling.md) - the article on number handling
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 2.0.0.
|
||||
|
||||
@@ -25,6 +25,11 @@ and [`default_object_comparator_t`](default_object_comparator_t.md) otherwise.
|
||||
--8<-- "examples/object_comparator_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [object_t](object_t.md) the type used to store JSON objects
|
||||
- [default_object_comparator_t](default_object_comparator_t.md) the fallback comparator used when `object_t` has no `key_compare` member type
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.0.0.
|
||||
|
||||
@@ -33,7 +33,7 @@ To store objects in C++, a type is defined by the template parameters described
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
### Default type
|
||||
|
||||
With the default values for `ObjectType` (`std::map`), `StringType` (`std::string`), and `AllocatorType`
|
||||
(`std::allocator`), the default value for `object_t` is:
|
||||
@@ -58,7 +58,7 @@ std::map<
|
||||
|
||||
See [`default_object_comparator_t`](default_object_comparator_t.md) for more information.
|
||||
|
||||
#### Behavior
|
||||
### Behavior
|
||||
|
||||
The choice of `object_t` influences the behavior of the JSON class. With the default type, objects have the following
|
||||
behavior:
|
||||
@@ -76,7 +76,7 @@ behavior:
|
||||
that they will not be affected by these differences. For instance, `#!json {"b": 1, "a": 2}` and
|
||||
`#!json {"a": 2, "b": 1}` will be treated as equal.
|
||||
|
||||
#### Limits
|
||||
### Limits
|
||||
|
||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) specifies:
|
||||
> An implementation may set limits on the maximum depth of nesting.
|
||||
@@ -85,12 +85,12 @@ In this class, the object's limit of nesting is not explicitly constrained. Howe
|
||||
introduced by the compiler or runtime environment. A theoretical limit can be queried by calling the
|
||||
[`max_size`](max_size.md) function of a JSON object.
|
||||
|
||||
#### Storage
|
||||
### Storage
|
||||
|
||||
Objects are stored as pointers in a `basic_json` type. That is, for any access to object values, a pointer of type
|
||||
`object_t*` must be dereferenced.
|
||||
|
||||
#### Object key order
|
||||
### Object key order
|
||||
|
||||
The order name/value pairs are added to the object are *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
|
||||
@@ -98,10 +98,10 @@ alphabetical order as `std::map` with `std::less` is used by default. Please not
|
||||
[RFC 8259](https://tools.ietf.org/html/rfc8259), because any order implements the specified "unordered" nature of JSON
|
||||
objects.
|
||||
|
||||
#### Cross-`basic_json` conversion requirements
|
||||
### Cross-`basic_json` conversion requirements
|
||||
|
||||
When converting an object from one `basic_json` specialization to another via the
|
||||
[converting constructor](basic_json.md#overload-4), the target `object_t`'s `key_type` must be
|
||||
[converting constructor](basic_json.md) (overload 4), the target `object_t`'s `key_type` must be
|
||||
directly constructible from the source `basic_json`'s `string_t` type (or more generally, from the
|
||||
source object's key type). If this requirement is not met, the conversion does not fail; instead,
|
||||
the object is silently converted as an array of key-value pairs, which is incorrect. See
|
||||
@@ -123,6 +123,13 @@ the object is silently converted as an array of key-value pairs, which is incorr
|
||||
--8<-- "examples/object_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [array_t](array_t.md) the type used to store JSON arrays
|
||||
- [string_t](string_t.md) the type used to store JSON strings
|
||||
- [object_comparator_t](object_comparator_t.md) the comparator used to order object keys
|
||||
- [Object Order](../../features/object_order.md) - the article on object key ordering
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -48,6 +48,12 @@ invalidates all iterators and all references.
|
||||
|
||||
`#!cpp *this`
|
||||
|
||||
## Exception safety
|
||||
|
||||
Strong guarantee: if an exception is thrown, there are no changes to any JSON value. As an exception, a `#!json null`
|
||||
value is converted to an empty array or object before the element is added and keeps that type if adding the element
|
||||
throws.
|
||||
|
||||
## Exceptions
|
||||
|
||||
1. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
|
||||
|
||||
@@ -136,6 +136,18 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
||||
while `/foo/one/one/one` creates nested objects. This is not specified by the JSON Pointer RFC; it is
|
||||
this library's own, intentional disambiguation rule. See also [JSON Pointer](../../features/json_pointer.md).
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
Overload (4) also accepts a [`json_pointer`](../json_pointer/index.md) whose template argument is a `basic_json`
|
||||
specialization (e.g., `nlohmann::json_pointer<nlohmann::json>`) instead of a string type. This is deprecated since
|
||||
version 3.11.0 and will be removed in a future major version; use `basic_json::json_pointer` (for `json`,
|
||||
`nlohmann::json_pointer<std::string>`) instead.
|
||||
|
||||
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
|
||||
function.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#json-pointers) for how to update existing code.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example: (1) access specified array element"
|
||||
|
||||
@@ -17,6 +17,11 @@ Implicit type conversion between the JSON value and a compatible value. The call
|
||||
|
||||
copy of the JSON value, converted to `ValueType`
|
||||
|
||||
## Exception safety
|
||||
|
||||
Depends on what `json_serializer<ValueType>` `from_json()` method throws; the JSON value itself is never modified,
|
||||
since `#!cpp operator ValueType()` is a `#!cpp const` member function that only calls [`get()`](get.md).
|
||||
|
||||
## Exceptions
|
||||
|
||||
Depends on what `json_serializer<ValueType>` `from_json()` method throws
|
||||
@@ -56,6 +61,8 @@ Linear in the size of the JSON value.
|
||||
[`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md) to `0` and replace any implicit
|
||||
conversions with calls to [`get`](../basic_json/get.md).
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#replace-implicit-conversions) for how to update existing code.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
@@ -63,7 +70,7 @@ Linear in the size of the JSON value.
|
||||
The example below shows several conversions from JSON values to other types. There are a few things to note: (1)
|
||||
Floating-point numbers can be converted to integers, (2) A JSON array can be converted to a standard
|
||||
`std::vector<short>`, (3) A JSON object can be converted to C++ associative containers such as
|
||||
`std::unordered_map<std::string, json>`.
|
||||
`std::map<std::string, json>`.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/operator__ValueType.cpp"
|
||||
|
||||
@@ -134,7 +134,7 @@ Linear.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: (1) compare JSON values"
|
||||
|
||||
The example demonstrates comparing several JSON types.
|
||||
|
||||
@@ -148,7 +148,7 @@ Linear.
|
||||
--8<-- "examples/operator__equal.output"
|
||||
```
|
||||
|
||||
??? example
|
||||
??? example "Example: (2) compare JSON values with `#!cpp nullptr`"
|
||||
|
||||
The example demonstrates comparing several JSON types against the null pointer (JSON `#!json null`).
|
||||
|
||||
|
||||
@@ -60,6 +60,16 @@ Linear.
|
||||
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
||||
[`operator<=>`](operator_spaceship.md).
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
If [`JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON`](../macros/json_use_legacy_discarded_value_comparison.md) is
|
||||
defined to `1`, the library declares a member `#!cpp bool operator>=(const_reference rhs) const noexcept` in
|
||||
C++20 mode to emulate the legacy comparison of discarded values. This member is deprecated since version 3.11.0,
|
||||
together with the legacy comparison behavior.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#miscellaneous-functions) for how to update existing
|
||||
code.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
@@ -61,6 +61,16 @@ Linear.
|
||||
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
||||
[`operator<=>`](operator_spaceship.md).
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
If [`JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON`](../macros/json_use_legacy_discarded_value_comparison.md) is
|
||||
defined to `1`, the library declares a member `#!cpp bool operator<=(const_reference rhs) const noexcept` in
|
||||
C++20 mode to emulate the legacy comparison of discarded values. This member is deprecated since version 3.11.0,
|
||||
together with the legacy comparison behavior.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#miscellaneous-functions) for how to update existing
|
||||
code.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
@@ -9,17 +9,9 @@ bool operator!=(const_reference lhs, const ScalarType rhs) noexcept; // (2)
|
||||
|
||||
template<typename ScalarType>
|
||||
bool operator!=(ScalarType lhs, const const_reference rhs) noexcept; // (2)
|
||||
|
||||
// since C++20
|
||||
class basic_json {
|
||||
bool operator!=(const_reference rhs) const noexcept; // (1)
|
||||
|
||||
template<typename ScalarType>
|
||||
bool operator!=(ScalarType rhs) const noexcept; // (2)
|
||||
};
|
||||
```
|
||||
|
||||
1. Compares two JSON values for inequality. Returns `#!cpp !(lhs == rhs)` (until C++20) or `#!cpp !(*this == rhs)` (since C++20).
|
||||
1. Compares two JSON values for inequality. Returns `#!cpp !(lhs == rhs)`.
|
||||
- This means the comparison is simply the logical negation of `operator==`, including for special values like `NaN` and `discarded`.
|
||||
|
||||
2. Compares a JSON value and a scalar or a scalar and a JSON value for inequality by converting the scalar to a JSON
|
||||
@@ -52,6 +44,11 @@ Linear.
|
||||
|
||||
## Notes
|
||||
|
||||
!!! note "C++20"
|
||||
|
||||
Since C++20, `basic_json` declares no `operator!=`. The compiler rewrites `#!cpp a != b` as `#!cpp !(a == b)`
|
||||
using [`operator==`](operator_eq.md), so the result is the same as described above.
|
||||
|
||||
!!! note "Comparing `NaN` and `discarded`"
|
||||
|
||||
Since `operator!=` is defined as `!(a == b)`, the behavior for special values follows that of `operator==`:
|
||||
@@ -61,7 +58,7 @@ Linear.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: (1) compare JSON values"
|
||||
|
||||
The example demonstrates comparing several JSON types.
|
||||
|
||||
@@ -75,7 +72,7 @@ Linear.
|
||||
--8<-- "examples/operator__notequal.output"
|
||||
```
|
||||
|
||||
??? example
|
||||
??? example "Example: (2) compare JSON values with `#!cpp nullptr`"
|
||||
|
||||
The example demonstrates comparing several JSON types against the null pointer (JSON `#!json null`).
|
||||
|
||||
@@ -89,9 +86,15 @@ Linear.
|
||||
--8<-- "examples/operator__notequal__nullptr_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [operator==](operator_eq.md) comparison: equal
|
||||
- [operator<=>](operator_spaceship.md) comparison: 3-way (C++20)
|
||||
|
||||
## Version history
|
||||
|
||||
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. Changed in version 3.13.0 to remove
|
||||
special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`.
|
||||
2. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. Changed in version 3.13.0 to remove
|
||||
special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`.
|
||||
1. Added in version 1.0.0. Added a C++20 member function in version 3.11.0. Changed in version 3.13.0 to remove
|
||||
special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`. Removed the C++20
|
||||
member function in version 3.13.0; since C++20, the compiler rewrites `a != b` using `operator==`.
|
||||
2. Added in version 1.0.0. Changed in version 3.13.0 to remove special-casing for `NaN` and `discarded` values;
|
||||
`operator!=` now consistently means `!(a == b)`. Since C++20, the compiler rewrites `a != b` using `operator==`.
|
||||
|
||||
@@ -47,6 +47,11 @@ Constant.
|
||||
--8<-- "examples/operator__value_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [type](type.md) named member function equivalent to this implicit conversion operator
|
||||
- [value_t](value_t.md) the enumeration of JSON types
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -114,7 +114,7 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Parsing from a character array"
|
||||
??? example "Example: (1) parse from a character array"
|
||||
|
||||
The example below demonstrates the `parse()` function reading from an array.
|
||||
|
||||
@@ -128,7 +128,7 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
--8<-- "examples/parse__array__parser_callback_t.output"
|
||||
```
|
||||
|
||||
??? example "Parsing from a string"
|
||||
??? example "Example: (1) parse from a string"
|
||||
|
||||
The example below demonstrates the `parse()` function with and without callback function.
|
||||
|
||||
@@ -142,7 +142,7 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
--8<-- "examples/parse__string__parser_callback_t.output"
|
||||
```
|
||||
|
||||
??? example "Parsing from an input stream"
|
||||
??? example "Example: (1) parse from an input stream"
|
||||
|
||||
The example below demonstrates the `parse()` function with and without callback function.
|
||||
|
||||
@@ -156,7 +156,7 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
--8<-- "examples/parse__istream__parser_callback_t.output"
|
||||
```
|
||||
|
||||
??? example "Parsing from a contiguous container"
|
||||
??? example "Example: (1) parse from a contiguous container"
|
||||
|
||||
The example below demonstrates the `parse()` function reading from a contiguous container.
|
||||
|
||||
@@ -170,7 +170,7 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
--8<-- "examples/parse__contiguouscontainer__parser_callback_t.output"
|
||||
```
|
||||
|
||||
??? example "Parsing from a non-null-terminated string"
|
||||
??? example "Example: (2) parse from a non-null-terminated string"
|
||||
|
||||
The example below demonstrates the `parse()` function reading from a string that is not null-terminated.
|
||||
|
||||
@@ -184,7 +184,7 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
--8<-- "examples/parse__pointers.output"
|
||||
```
|
||||
|
||||
??? example "Parsing from an iterator pair"
|
||||
??? example "Example: (2) parse from an iterator pair"
|
||||
|
||||
The example below demonstrates the `parse()` function reading from an iterator pair.
|
||||
|
||||
@@ -198,7 +198,7 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
--8<-- "examples/parse__iterator_pair.output"
|
||||
```
|
||||
|
||||
??? example "Effect of `allow_exceptions` parameter"
|
||||
??? example "Example: effect of `allow_exceptions` parameter"
|
||||
|
||||
The example below demonstrates the effect of the `allow_exceptions` parameter in the `parse()` function.
|
||||
|
||||
@@ -212,7 +212,7 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
--8<-- "examples/parse__allow_exceptions.output"
|
||||
```
|
||||
|
||||
??? example "Effect of `ignore_comments` parameter"
|
||||
??? example "Example: effect of `ignore_comments` parameter"
|
||||
|
||||
The example below demonstrates the effect of the `ignore_comments` parameter in the `parse()` function.
|
||||
|
||||
@@ -226,7 +226,7 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
--8<-- "examples/comments.output"
|
||||
```
|
||||
|
||||
??? example "Effect of `ignore_trailing_commas` parameter"
|
||||
??? example "Example: effect of `ignore_trailing_commas` parameter"
|
||||
|
||||
The example below demonstrates the effect of the `ignore_trailing_commas` parameter in the `parse()` function.
|
||||
|
||||
@@ -270,3 +270,5 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
||||
|
||||
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
|
||||
function.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#parsing) for how to update existing code.
|
||||
|
||||
@@ -54,7 +54,7 @@ classDiagram
|
||||
|
||||
## Notes
|
||||
|
||||
For an input with <i>n</i> bytes, 1 is the index of the first character and <i>n</i>+1 is the index of the terminating null byte
|
||||
For an input with $n$ bytes, 1 is the index of the first character and $n+1$ is the index of the terminating null byte
|
||||
or the end of file. This also holds true when reading a byte vector for binary formats.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -24,6 +24,21 @@ The parser callback distinguishes the following events:
|
||||
|
||||

|
||||
|
||||
??? example
|
||||
|
||||
The following code parses a small JSON text with a parser callback that reports every event together with its
|
||||
depth and keeps every value (by always returning `#!cpp true`).
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/parse_event_t.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/parse_event_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [parser_callback_t](parser_callback_t.md) callback function type for the parser
|
||||
|
||||
@@ -60,7 +60,7 @@ the latter case, it is skipped completely, or replaced by `null` if it is the to
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: skip an object key while parsing"
|
||||
|
||||
The example below demonstrates the `parse()` function with
|
||||
and without callback function.
|
||||
@@ -75,7 +75,7 @@ the latter case, it is skipped completely, or replaced by `null` if it is the to
|
||||
--8<-- "examples/parse__string__parser_callback_t.output"
|
||||
```
|
||||
|
||||
??? example
|
||||
??? example "Example: how discarded values are removed"
|
||||
|
||||
The example below shows where discarded values are removed. The array and the number are discarded in different
|
||||
ways, but in each case the parse result contains neither the value nor its key.
|
||||
|
||||
@@ -26,10 +26,24 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
||||
- Throws [`parse_error.104`](../../home/exceptions.md#jsonexceptionparse_error104) if the JSON patch does not consist of
|
||||
an array of objects.
|
||||
- Throws [`parse_error.105`](../../home/exceptions.md#jsonexceptionparse_error105) if the JSON patch is malformed (e.g.,
|
||||
mandatory attributes are missing); example: `"operation add must have member path"`.
|
||||
mandatory attributes are missing); example: `"operation 'add' must have member 'path'"`.
|
||||
- Throws [`out_of_range.401`](../../home/exceptions.md#jsonexceptionout_of_range401) if an array index is out of range.
|
||||
- Throws [`parse_error.106`](../../home/exceptions.md#jsonexceptionparse_error106) if an array index in a "path" or
|
||||
"from" member begins with '0'; example: `"array index '01' must not begin with '0'"`.
|
||||
- Throws [`parse_error.107`](../../home/exceptions.md#jsonexceptionparse_error107) if a "path" or "from" member is not
|
||||
empty and does not begin with a slash (`/`); example: `"JSON pointer must be empty or begin with '/' - was: 'a'"`.
|
||||
- Throws [`parse_error.108`](../../home/exceptions.md#jsonexceptionparse_error108) if a tilde (`~`) in a "path" or
|
||||
"from" member is not followed by `0` or `1`; example: `"escape character '~' must be followed with '0' or '1'"`.
|
||||
- Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) if an array index in a "path" or
|
||||
"from" member is not a number; example: `"array index 'foo' is not a number"`.
|
||||
- Throws [`out_of_range.402`](../../home/exceptions.md#jsonexceptionout_of_range402) if the array index `-` is used
|
||||
where an existing element is required (the "path" of "replace", the "from" of "move" and "copy"); example:
|
||||
`"array index '-' (3) is out of range"`.
|
||||
- Throws [`out_of_range.403`](../../home/exceptions.md#jsonexceptionout_of_range403) if a JSON pointer inside the patch
|
||||
could not be resolved successfully in the current JSON value; example: `"key baz not found"`.
|
||||
- Throws [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) if a reference token of a JSON
|
||||
pointer inside the patch cannot be resolved, e.g., `-` in a "remove" operation or `1a` for an array; example:
|
||||
`"unresolved reference token '-'"`.
|
||||
- Throws [`out_of_range.405`](../../home/exceptions.md#jsonexceptionout_of_range405) if JSON pointer has no parent
|
||||
("add", "remove", "move")
|
||||
- Throws [`out_of_range.411`](../../home/exceptions.md#jsonexceptionout_of_range411) if an "add" operation's target
|
||||
@@ -53,7 +67,7 @@ is thrown. In any case, the original value is not changed: the patch is applied
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: apply a JSON patch"
|
||||
|
||||
The following code shows how a JSON patch is applied to a value.
|
||||
|
||||
@@ -67,6 +81,21 @@ is thrown. In any case, the original value is not changed: the patch is applied
|
||||
--8<-- "examples/patch.output"
|
||||
```
|
||||
|
||||
??? example "Example: out_of_range.414 exception"
|
||||
|
||||
The following code shows how a "move" operation whose "from" location is a proper prefix of its "path" location is
|
||||
rejected, and how the original document is left unchanged because the patch is applied to a copy.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/patch__exception.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/patch__exception.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
|
||||
|
||||
@@ -22,10 +22,24 @@ No guarantees, value may be corrupted by an unsuccessful patch operation.
|
||||
- Throws [`parse_error.104`](../../home/exceptions.md#jsonexceptionparse_error104) if the JSON patch does not consist of
|
||||
an array of objects.
|
||||
- Throws [`parse_error.105`](../../home/exceptions.md#jsonexceptionparse_error105) if the JSON patch is malformed (e.g.,
|
||||
mandatory attributes are missing); example: `"operation add must have member path"`.
|
||||
mandatory attributes are missing); example: `"operation 'add' must have member 'path'"`.
|
||||
- Throws [`out_of_range.401`](../../home/exceptions.md#jsonexceptionout_of_range401) if an array index is out of range.
|
||||
- Throws [`parse_error.106`](../../home/exceptions.md#jsonexceptionparse_error106) if an array index in a "path" or
|
||||
"from" member begins with '0'; example: `"array index '01' must not begin with '0'"`.
|
||||
- Throws [`parse_error.107`](../../home/exceptions.md#jsonexceptionparse_error107) if a "path" or "from" member is not
|
||||
empty and does not begin with a slash (`/`); example: `"JSON pointer must be empty or begin with '/' - was: 'a'"`.
|
||||
- Throws [`parse_error.108`](../../home/exceptions.md#jsonexceptionparse_error108) if a tilde (`~`) in a "path" or
|
||||
"from" member is not followed by `0` or `1`; example: `"escape character '~' must be followed with '0' or '1'"`.
|
||||
- Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) if an array index in a "path" or
|
||||
"from" member is not a number; example: `"array index 'foo' is not a number"`.
|
||||
- Throws [`out_of_range.402`](../../home/exceptions.md#jsonexceptionout_of_range402) if the array index `-` is used
|
||||
where an existing element is required (the "path" of "replace", the "from" of "move" and "copy"); example:
|
||||
`"array index '-' (3) is out of range"`.
|
||||
- Throws [`out_of_range.403`](../../home/exceptions.md#jsonexceptionout_of_range403) if a JSON pointer inside the patch
|
||||
could not be resolved successfully in the current JSON value; example: `"key baz not found"`.
|
||||
- Throws [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) if a reference token of a JSON
|
||||
pointer inside the patch cannot be resolved, e.g., `-` in a "remove" operation or `1a` for an array; example:
|
||||
`"unresolved reference token '-'"`.
|
||||
- Throws [`out_of_range.405`](../../home/exceptions.md#jsonexceptionout_of_range405) if JSON pointer has no parent
|
||||
("add", "remove", "move")
|
||||
- Throws [`out_of_range.411`](../../home/exceptions.md#jsonexceptionout_of_range411) if an "add" operation's target
|
||||
@@ -50,7 +64,7 @@ function throws an exception.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: apply a JSON patch in place"
|
||||
|
||||
The following code shows how a JSON patch is applied to a value.
|
||||
|
||||
@@ -64,6 +78,22 @@ function throws an exception.
|
||||
--8<-- "examples/patch_inplace.output"
|
||||
```
|
||||
|
||||
??? example "Example: out_of_range.403 exception with a partially applied patch"
|
||||
|
||||
The following code shows a patch whose first operation succeeds and whose second operation fails. Because
|
||||
`patch_inplace` applies each operation directly to the value, the first operation's effect is still visible after
|
||||
the exception is caught, unlike [`patch`](patch.md).
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/patch_inplace__exception.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/patch_inplace__exception.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
|
||||
|
||||
@@ -44,6 +44,12 @@ invalidates all iterators and all references.
|
||||
`init` (in)
|
||||
: an initializer list
|
||||
|
||||
## Exception safety
|
||||
|
||||
Strong guarantee: if an exception is thrown, there are no changes to any JSON value. As an exception, a `#!json null`
|
||||
value is converted to an empty array or object before the element is added and keeps that type if adding the element
|
||||
throws.
|
||||
|
||||
## Exceptions
|
||||
|
||||
1. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
|
||||
|
||||
@@ -37,6 +37,13 @@ Constant.
|
||||
--8<-- "examples/rbegin.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [rend](rend.md) returns a reverse iterator to one before the first element
|
||||
- [crbegin](crbegin.md) returns a const reverse iterator to the last element
|
||||
- [begin](begin.md) returns an iterator to the first element
|
||||
- [Iterators](../../features/iterators.md) - the article on iterators
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -38,6 +38,13 @@ Constant.
|
||||
--8<-- "examples/rend.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [rbegin](rbegin.md) returns a reverse iterator to the last element
|
||||
- [crend](crend.md) returns a const reverse iterator to one before the first element
|
||||
- [end](end.md) returns an iterator to one past the last element
|
||||
- [Iterators](../../features/iterators.md) - the article on iterators
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -147,3 +147,5 @@ A UTF-8 byte order mark is silently ignored.
|
||||
Overload (2) replaces calls to `sax_parse` with a pair of iterators as their first parameter which has been
|
||||
deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like
|
||||
`#!cpp sax_parse({ptr, ptr+len});` with `#!cpp sax_parse(ptr, ptr+len);`.
|
||||
|
||||
See the [migration guide](../../integration/migration_guide.md#parsing) for how to update existing code.
|
||||
|
||||
@@ -51,6 +51,11 @@ JSON value which is `1` in the case of a string.
|
||||
--8<-- "examples/size.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [empty](empty.md) checks whether the JSON value has no elements
|
||||
- [max_size](max_size.md) returns the maximum possible number of elements
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -28,6 +28,10 @@ type of the JSON value is taken into account to have different hash values for `
|
||||
|
||||
Note the output is platform-dependent.
|
||||
|
||||
## See also
|
||||
|
||||
- [operator==](operator_eq.md) compares two JSON values for equality, consistent with equal hash values
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -30,16 +30,16 @@ JSON class into byte-sized characters during deserialization.
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
### Default type
|
||||
|
||||
With the default values for `StringType` (`std::string`), the default value for `string_t` is `#!cpp std::string`.
|
||||
|
||||
#### Encoding
|
||||
### Encoding
|
||||
|
||||
Strings are stored in UTF-8 encoding. Therefore, functions like `std::string::size()` or `std::string::length()` return
|
||||
the number of bytes in the string rather than the number of characters or glyphs.
|
||||
|
||||
#### String comparison
|
||||
### String comparison
|
||||
|
||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) states:
|
||||
> Software implementations are typically required to test names of object members for equality. Implementations that
|
||||
@@ -50,15 +50,15 @@ the number of bytes in the string rather than the number of characters or glyphs
|
||||
|
||||
This implementation is interoperable as it does compare strings code unit by code unit.
|
||||
|
||||
#### Storage
|
||||
### Storage
|
||||
|
||||
String values are stored as pointers in a `basic_json` type. That is, for any access to string values, a pointer of type
|
||||
`string_t*` must be dereferenced.
|
||||
|
||||
#### Cross-`basic_json` conversion requirements
|
||||
### Cross-`basic_json` conversion requirements
|
||||
|
||||
When converting a string value from one `basic_json` specialization to another via the
|
||||
[converting constructor](basic_json.md#overload-4), the target `string_t` must be directly
|
||||
[converting constructor](basic_json.md) (overload 4), the target `string_t` must be directly
|
||||
constructible from the source `basic_json`'s `string_t` type. If this requirement is not met, the
|
||||
conversion does not fail; instead, the string is silently converted as an array of character codes,
|
||||
which is incorrect. See [issue #3425](https://github.com/nlohmann/json/issues/3425) for details
|
||||
@@ -80,6 +80,12 @@ and an example.
|
||||
--8<-- "examples/string_t.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [object_t](object_t.md) the type used to store JSON objects (and their keys, which are also `string_t`)
|
||||
- [binary_t](binary_t.md) the type used to store binary values
|
||||
- [get_ptr](get_ptr.md) returns a pointer to the stored string value
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0.
|
||||
|
||||
@@ -73,6 +73,16 @@ void swap(typename binary_t::container_type& other);
|
||||
`right` (in, out)
|
||||
: value to exchange the contents with
|
||||
|
||||
## Exception safety
|
||||
|
||||
1. No-throw guarantee: this function never throws exceptions.
|
||||
2. No-throw guarantee: this function never throws exceptions.
|
||||
3. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||
4. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||
5. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||
6. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||
7. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
|
||||
|
||||
## Exceptions
|
||||
|
||||
1. No-throw guarantee: this function never throws exceptions.
|
||||
@@ -94,7 +104,7 @@ Constant.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example: Swap JSON value (1, 2)"
|
||||
??? example "Example: (1, 2) swap JSON values"
|
||||
|
||||
The example below shows how JSON values can be swapped with `swap()`.
|
||||
|
||||
@@ -108,7 +118,7 @@ Constant.
|
||||
--8<-- "examples/swap__reference.output"
|
||||
```
|
||||
|
||||
??? example "Example: Swap array (3)"
|
||||
??? example "Example: (3) swap array"
|
||||
|
||||
The example below shows how arrays can be swapped with `swap()`.
|
||||
|
||||
@@ -122,7 +132,7 @@ Constant.
|
||||
--8<-- "examples/swap__array_t.output"
|
||||
```
|
||||
|
||||
??? example "Example: Swap object (4)"
|
||||
??? example "Example: (4) swap object"
|
||||
|
||||
The example below shows how objects can be swapped with `swap()`.
|
||||
|
||||
@@ -136,7 +146,7 @@ Constant.
|
||||
--8<-- "examples/swap__object_t.output"
|
||||
```
|
||||
|
||||
??? example "Example: Swap string (5)"
|
||||
??? example "Example: (5) swap string"
|
||||
|
||||
The example below shows how strings can be swapped with `swap()`.
|
||||
|
||||
@@ -150,7 +160,7 @@ Constant.
|
||||
--8<-- "examples/swap__string_t.output"
|
||||
```
|
||||
|
||||
??? example "Example: Swap binary (6)"
|
||||
??? example "Example: (6) swap binary"
|
||||
|
||||
The example below shows how binary values can be swapped with `swap()`.
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
||||
## Exceptions
|
||||
|
||||
- Throws [`other_error.502`](../../home/exceptions.md#jsonexceptionother_error502) if `use_type` is true and `use_size`
|
||||
is false.
|
||||
is false, and `j` contains a non-empty array, object, or binary value.
|
||||
|
||||
## Complexity
|
||||
|
||||
@@ -63,7 +63,7 @@ Linear in the size of the JSON value `j`.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: serialize a JSON value to BJData"
|
||||
|
||||
The example shows the serialization of a JSON value to a byte vector in BJData format.
|
||||
|
||||
@@ -77,6 +77,21 @@ Linear in the size of the JSON value `j`.
|
||||
--8<-- "examples/to_bjdata.output"
|
||||
```
|
||||
|
||||
??? example "Example: other_error.502 exception"
|
||||
|
||||
The example shows how requesting type annotations (`use_type`) without size annotations (`use_size`) throws an
|
||||
exception, because type-optimized containers can only be read back with a preceding size.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/to_bjdata__exception.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/to_bjdata__exception.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format
|
||||
|
||||
@@ -48,7 +48,7 @@ Linear in the size of the JSON value `j`.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
??? example "Example: serialize a JSON value to BON8"
|
||||
|
||||
The example shows the serialization of a JSON value to a byte vector in BON8 format.
|
||||
|
||||
@@ -62,6 +62,21 @@ Linear in the size of the JSON value `j`.
|
||||
--8<-- "examples/to_bon8.output"
|
||||
```
|
||||
|
||||
??? example "Example: type_error.316 exception"
|
||||
|
||||
The example shows how serializing a string that is not valid UTF-8 throws an exception, because BON8 stores strings
|
||||
as UTF-8.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/to_bon8__exception.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/to_bon8__exception.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [from_bon8](from_bon8.md) create a JSON value from an input in BON8 format
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user