mirror of
https://github.com/nlohmann/json.git
synced 2026-08-13 04:33:18 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a27065bd12 | ||
|
|
3940f4b730 | ||
|
|
0663907b68 | ||
|
|
f23b3c63a2 |
@@ -15,14 +15,6 @@ guidance.
|
|||||||
|
|
||||||
For vulnerabilities in third-party dependencies or modules, please report them directly to the respective maintainers.
|
For vulnerabilities in third-party dependencies or modules, please report them directly to the respective maintainers.
|
||||||
|
|
||||||
## Unofficial packages
|
|
||||||
|
|
||||||
This project does not publish an official npm package. The npm package
|
|
||||||
[`nlohmann-json`](https://www.npmjs.com/package/nlohmann-json) (or similarly named packages) is not maintained or
|
|
||||||
endorsed by this project. See the
|
|
||||||
[package managers documentation](https://json.nlohmann.me/integration/package_managers/#npm) for supported
|
|
||||||
integration options.
|
|
||||||
|
|
||||||
## Additional Resources
|
## Additional Resources
|
||||||
|
|
||||||
- Explore security-related topics and contribute to tools and projects through
|
- Explore security-related topics and contribute to tools and projects through
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -34,19 +34,19 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout pull request
|
- name: Checkout pull request
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
path: main
|
path: main
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Checkout tools
|
- name: Checkout tools
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
path: tools
|
path: tools
|
||||||
ref: develop
|
ref: develop
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
name: "Check API documentation"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check_api_docs:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
|
with:
|
||||||
|
egress-policy: audit
|
||||||
|
|
||||||
|
- name: Checkout pull request
|
||||||
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
|
|
||||||
|
- name: Install clang
|
||||||
|
# Used only as a subprocess for `clang++ -E -v` system-include-path discovery in
|
||||||
|
# extract_api.py; it does not need to version-match the pinned libclang pip wheel
|
||||||
|
# below, which does the actual AST parsing. Do not "fix" this to be version-matched.
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y clang
|
||||||
|
|
||||||
|
- name: Install Python dependencies
|
||||||
|
run: pip install -r tools/api_checker/requirements.txt
|
||||||
|
|
||||||
|
- name: Extract API and regenerate the committed surface file
|
||||||
|
run: |
|
||||||
|
python3 tools/api_checker/extract_api.py \
|
||||||
|
--header include/nlohmann/json.hpp \
|
||||||
|
--include include \
|
||||||
|
--output /tmp/api_snapshot.json \
|
||||||
|
--surface-output tools/api_checker/api_surface.json
|
||||||
|
|
||||||
|
- name: "Check API documentation (Phase 1: advisory)"
|
||||||
|
# Surfaces missing/broken @sa links without failing the job while the backlog from the
|
||||||
|
# initial AST-based rollout is burned down. See tools/api_checker/POLICY.md and the PR
|
||||||
|
# that introduced this workflow for the two-phase rollout plan.
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
python3 tools/api_checker/check_docs.py \
|
||||||
|
--snapshot /tmp/api_snapshot.json
|
||||||
|
|
||||||
|
- name: Check macro documentation (advisory only)
|
||||||
|
# Cross-checks docs/mkdocs/docs/api/macros/ pages against #define sites. Only checks the
|
||||||
|
# documented-macro-still-exists direction; never blocks CI. See POLICY.md.
|
||||||
|
run: python3 tools/api_checker/check_macros.py
|
||||||
|
|
||||||
|
- name: Check for uncommitted API surface changes
|
||||||
|
id: diff
|
||||||
|
run: |
|
||||||
|
mkdir -p ${{ github.workspace }}/patch
|
||||||
|
git diff --patch --no-color -- tools/api_checker/api_surface.json > ${{ github.workspace }}/patch/api_surface.patch
|
||||||
|
if [ -s ${{ github.workspace }}/patch/api_surface.patch ]; then
|
||||||
|
echo "tools/api_checker/api_surface.json is out of date. Diff:"
|
||||||
|
cat ${{ github.workspace }}/patch/api_surface.patch
|
||||||
|
echo "has_diff=true" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "has_diff=false" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Uploaded so contributors can fix their PR with `git apply api_surface.patch`
|
||||||
|
# instead of installing libclang locally.
|
||||||
|
- name: Upload patch
|
||||||
|
if: steps.diff.outputs.has_diff == 'true'
|
||||||
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||||
|
with:
|
||||||
|
name: api-surface-patch
|
||||||
|
path: patch/api_surface.patch
|
||||||
|
|
||||||
|
- name: Fail if API surface file is not up to date
|
||||||
|
# Unlike the doc-backlog check above, this is purely mechanical regeneration with no
|
||||||
|
# backlog to phase in -- blocking from the start, matching check_amalgamation.yml's
|
||||||
|
# precedent. Contributors who add/remove/rename public API must regenerate and commit
|
||||||
|
# tools/api_checker/api_surface.json as part of their PR.
|
||||||
|
if: steps.diff.outputs.has_diff == 'true'
|
||||||
|
run: exit 1
|
||||||
@@ -9,7 +9,7 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -27,25 +27,25 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
uses: github/codeql-action/init@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
|
||||||
with:
|
with:
|
||||||
languages: c-cpp
|
languages: c-cpp
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
uses: github/codeql-action/autobuild@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
uses: github/codeql-action/analyze@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: 'Checkout Repository'
|
- name: 'Checkout Repository'
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: 'Dependency Review'
|
- name: 'Dependency Review'
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ jobs:
|
|||||||
security-events: write
|
security-events: write
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -43,6 +43,6 @@ jobs:
|
|||||||
output: 'flawfinder_results.sarif'
|
output: 'flawfinder_results.sarif'
|
||||||
|
|
||||||
- name: Upload analysis results to GitHub Security tab
|
- name: Upload analysis results to GitHub Security tab
|
||||||
uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
uses: github/codeql-action/upload-sarif@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
|
||||||
with:
|
with:
|
||||||
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
|
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
@@ -45,7 +45,7 @@ jobs:
|
|||||||
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
@@ -62,7 +62,7 @@ jobs:
|
|||||||
standard: [11, 14, 17, 20, 23, 26]
|
standard: [11, 14, 17, 20, 23, 26]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
|
|
||||||
- name: Install virtual environment
|
- name: Install virtual environment
|
||||||
run: make install_venv -C docs/mkdocs
|
run: make install_venv -C docs/mkdocs
|
||||||
|
|||||||
@@ -36,17 +36,17 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: "Checkout code"
|
- name: "Checkout code"
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: "Run analysis"
|
- name: "Run analysis"
|
||||||
uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4
|
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
|
||||||
with:
|
with:
|
||||||
results_file: results.sarif
|
results_file: results.sarif
|
||||||
results_format: sarif
|
results_format: sarif
|
||||||
@@ -76,6 +76,6 @@ jobs:
|
|||||||
|
|
||||||
# Upload the results to GitHub's code scanning dashboard.
|
# Upload the results to GitHub's code scanning dashboard.
|
||||||
- name: "Upload to code-scanning"
|
- name: "Upload to code-scanning"
|
||||||
uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
uses: github/codeql-action/upload-sarif@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
|
||||||
with:
|
with:
|
||||||
sarif_file: results.sarif
|
sarif_file: results.sarif
|
||||||
|
|||||||
@@ -32,12 +32,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
# Checkout project source
|
# Checkout project source
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ jobs:
|
|||||||
|
|
||||||
# Upload SARIF file generated in previous step
|
# Upload SARIF file generated in previous step
|
||||||
- name: Upload SARIF file
|
- name: Upload SARIF file
|
||||||
uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
uses: github/codeql-action/upload-sarif@54f647b7e1bb85c95cddabcd46b0c578ec92bc1a # v4.36.3
|
||||||
with:
|
with:
|
||||||
sarif_file: semgrep.sarif
|
sarif_file: semgrep.sarif
|
||||||
if: always()
|
if: always()
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/stale@4391f3da665fdf50b6810c1a66712fb9ba21aa93 # v11.0.0
|
- uses: actions/stale@eb5cf3af3ac0a1aa4c9c45633dd1ae542a27a899 # v10.3.0
|
||||||
with:
|
with:
|
||||||
stale-issue-label: 'state: stale'
|
stale-issue-label: 'state: stale'
|
||||||
stale-pr-label: 'state: stale'
|
stale-pr-label: 'state: stale'
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: gcc:latest
|
container: gcc:latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -35,7 +35,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -43,11 +43,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
wget -q -O - "https://github.com/facebook/infer/releases/download/v1.3.0/infer-linux-x86_64-v1.3.0.tar.xz" | sudo tar -C /opt -xJ
|
wget -q -O - "https://github.com/facebook/infer/releases/download/v1.3.0/infer-linux-x86_64-v1.3.0.tar.xz" | sudo tar -C /opt -xJ
|
||||||
sudo ln -s /opt/infer-linux-x86_64-v1.3.0/bin/infer /usr/local/bin/infer
|
sudo ln -s /opt/infer-linux-x86_64-v1.3.0/bin/infer /usr/local/bin/infer
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -60,17 +60,17 @@ jobs:
|
|||||||
target: [ci_test_amalgamation, ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind]
|
target: [ci_test_amalgamation, ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind]
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Install Valgrind
|
- name: Install Valgrind
|
||||||
run: sudo apt-get update ; sudo apt-get install -y valgrind
|
run: sudo apt-get update ; sudo apt-get install -y valgrind
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -85,11 +85,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install git, clang-tools, iwyu (ci_single_binaries), and unzip
|
- name: Install git, clang-tools, iwyu (ci_single_binaries), and unzip
|
||||||
run: apt-get update ; apt-get install -y git clang-tools iwyu unzip
|
run: apt-get update ; apt-get install -y git clang-tools iwyu unzip
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -104,11 +104,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install build-essential
|
- name: Install build-essential
|
||||||
run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev
|
run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -118,11 +118,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Install dependencies and de_DE locale
|
- name: Install dependencies and de_DE locale
|
||||||
@@ -142,7 +142,7 @@ jobs:
|
|||||||
name: code-coverage-report
|
name: code-coverage-report
|
||||||
path: ${{ github.workspace }}/build/html
|
path: ${{ github.workspace }}/build/html
|
||||||
- name: Publish report to Coveralls
|
- name: Publish report to Coveralls
|
||||||
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
|
uses: coverallsapp/github-action@5cbfd81b66ca5d10c19b062c04de0199c215fb6e # v2.3.7
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
path-to-lcov: ${{ github.workspace }}/build/json.info.filtered.noexcept
|
path-to-lcov: ${{ github.workspace }}/build/json.info.filtered.noexcept
|
||||||
@@ -163,15 +163,7 @@ jobs:
|
|||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y --no-install-recommends software-properties-common ca-certificates gnupg make git
|
apt-get install -y --no-install-recommends software-properties-common ca-certificates gnupg make git
|
||||||
# add-apt-repository resolves the PPA through the Launchpad API,
|
add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
||||||
# which intermittently times out or fails the team lookup (the plain
|
|
||||||
# "deb ..." sources below never hit Launchpad and never flake).
|
|
||||||
# Retry with backoff so a transient Launchpad blip does not fail CI.
|
|
||||||
for attempt in 1 2 3 4 5; do
|
|
||||||
add-apt-repository -y ppa:ubuntu-toolchain-r/test && break
|
|
||||||
echo "::warning::add-apt-repository ppa:ubuntu-toolchain-r/test failed (attempt ${attempt}/5); retrying"
|
|
||||||
sleep $((attempt * 10))
|
|
||||||
done
|
|
||||||
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ bionic main"
|
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ bionic main"
|
||||||
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ bionic universe"
|
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ bionic universe"
|
||||||
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial main"
|
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial main"
|
||||||
@@ -180,11 +172,11 @@ jobs:
|
|||||||
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial-updates universe"
|
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial-updates universe"
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y --no-install-recommends g++-${{ matrix.compiler }}
|
apt-get install -y --no-install-recommends g++-${{ matrix.compiler }}
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: CXX=g++-${{ matrix.compiler }} cmake -S . -B build -DJSON_CI=On
|
run: CXX=g++-${{ matrix.compiler }} cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -198,11 +190,11 @@ jobs:
|
|||||||
compiler: ['7', '8', '9', '10', '11', '12', '13', '14', '15', 'latest']
|
compiler: ['7', '8', '9', '10', '11', '12', '13', '14', '15', 'latest']
|
||||||
container: gcc:${{ matrix.compiler }}
|
container: gcc:${{ matrix.compiler }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -212,14 +204,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
compiler: ['3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15-bullseye', '16', '17', '18', '19', '20', '21', '22', 'latest']
|
compiler: ['3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15-bullseye', '16', '17', '18', '19', '20', 'latest']
|
||||||
container: silkeh/clang:${{ matrix.compiler }}
|
container: silkeh/clang:${{ matrix.compiler }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10
|
- name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10
|
||||||
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
|
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
|
||||||
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
|
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
|
||||||
@@ -235,11 +227,11 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
standard: [11, 14, 17, 20, 23, 26]
|
standard: [11, 14, 17, 20, 23, 26]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -255,11 +247,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install git and unzip
|
- name: Install git and unzip
|
||||||
run: apt-get update ; apt-get install -y git unzip
|
run: apt-get update ; apt-get install -y git unzip
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build with libc++
|
- name: Build with libc++
|
||||||
@@ -282,11 +274,11 @@ jobs:
|
|||||||
cuda: ['11.8.0', '12.1.1', '12.6.3']
|
cuda: ['11.8.0', '12.1.1', '12.6.3']
|
||||||
container: nvidia/cuda:${{ matrix.cuda }}-devel-ubuntu22.04
|
container: nvidia/cuda:${{ matrix.cuda }}-devel-ubuntu22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -299,14 +291,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ${{ matrix.container }}
|
container: ${{ matrix.container }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
# The module test uses `import std;`, which needs CMake's experimental
|
# The module test uses `import std;`, which needs CMake's experimental
|
||||||
# import-std support. Its opt-in token is CMake-version-specific, so pin
|
# import-std support. Its opt-in token is CMake-version-specific, so pin
|
||||||
# CMake to the version whose token is set in tests/module_cpp20/CMakeLists.txt.
|
# CMake to the version whose token is set in tests/module_cpp20/CMakeLists.txt.
|
||||||
- name: Get pinned CMake and ninja
|
- name: Get pinned CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
with:
|
with:
|
||||||
cmakeVersion: 4.3.4
|
cmakeVersion: 4.3.4
|
||||||
# Clang: the std library module is provided by libc++ (the image's libstdc++
|
# Clang: the std library module is provided by libc++ (the image's libstdc++
|
||||||
@@ -328,11 +320,11 @@ jobs:
|
|||||||
# Intel's own last officially published image that still includes it.
|
# Intel's own last officially published image that still includes it.
|
||||||
container: intel/oneapi-hpckit:2023.2.1-devel-ubuntu22.04
|
container: intel/oneapi-hpckit:2023.2.1-devel-ubuntu22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -345,9 +337,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: intel/oneapi-hpckit:latest
|
container: intel/oneapi-hpckit:latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -357,9 +349,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: nvcr.io/nvidia/nvhpc:25.5-devel-cuda12.9-ubuntu22.04
|
container: nvcr.io/nvidia/nvhpc:25.5-devel-cuda12.9-ubuntu22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -369,17 +361,17 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Install emscripten
|
- name: Install emscripten
|
||||||
uses: mymindstorm/setup-emsdk@4528d102f7230f0e7b276855c01ea1159be0e984 # v16
|
uses: mymindstorm/setup-emsdk@4528d102f7230f0e7b276855c01ea1159be0e984 # v16
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -GNinja
|
run: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -GNinja
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -392,11 +384,11 @@ jobs:
|
|||||||
target: [ci_test_examples, ci_test_build_documentation]
|
target: [ci_test_examples, ci_test_build_documentation]
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
|
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ jobs:
|
|||||||
architecture: [x64, x86]
|
architecture: [x64, x86]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Set up MinGW
|
- name: Set up MinGW
|
||||||
@@ -49,7 +49,7 @@ jobs:
|
|||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Set extra CXX_FLAGS for latest std_version
|
- name: Set extra CXX_FLAGS for latest std_version
|
||||||
@@ -86,9 +86,9 @@ jobs:
|
|||||||
runs-on: windows-2025
|
runs-on: windows-2025
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
- name: Set extra CXX_FLAGS for latest std_version
|
- name: Set extra CXX_FLAGS for latest std_version
|
||||||
# /wd5285 silences C5285 emitted by the bundled third-party doctest.h, which
|
# /wd5285 silences C5285 emitted by the bundled third-party doctest.h, which
|
||||||
# specializes std::tuple (newly diagnosed by the VS2026 v145 toolset)
|
# specializes std::tuple (newly diagnosed by the VS2026 v145 toolset)
|
||||||
@@ -122,7 +122,7 @@ jobs:
|
|||||||
runs-on: windows-11-arm
|
runs-on: windows-11-arm
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
- name: Run CMake (Release)
|
- name: Run CMake (Release)
|
||||||
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ARM64 -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ARM64 -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||||
if: matrix.build_type == 'Release'
|
if: matrix.build_type == 'Release'
|
||||||
@@ -143,7 +143,7 @@ jobs:
|
|||||||
version: [11.0.1, 12.0.1, 13.0.1, 14.0.6, 15.0.7, 16.0.6, 18.1.8, 19.1.7, 20.1.8]
|
version: [11.0.1, 12.0.1, 13.0.1, 14.0.6, 15.0.7, 16.0.6, 18.1.8, 19.1.7, 20.1.8]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Install Clang
|
- name: Install Clang
|
||||||
@@ -153,16 +153,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
platform: x64
|
platform: x64
|
||||||
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
|
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
|
||||||
# CMAKE_CXX_FLAGS_DEBUG is overridden to drop the default -g: linking
|
|
||||||
# test-regression2_cpp20 intermittently fails with "relocation truncated
|
|
||||||
# to fit: IMAGE_REL_AMD64_SECREL against `.debug_line'" because the
|
|
||||||
# MinGW linker cannot relocate the debug sections this test produces.
|
|
||||||
# The tests are only built and run here, so the debug info is not used.
|
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build ^
|
run: cmake -S . -B build ^
|
||||||
-DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" ^
|
-DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" ^
|
||||||
-DCMAKE_CXX_FLAGS="--target=x86_64-w64-mingw32 -stdlib=libstdc++ -pthread" ^
|
-DCMAKE_CXX_FLAGS="--target=x86_64-w64-mingw32 -stdlib=libstdc++ -pthread" ^
|
||||||
-DCMAKE_CXX_FLAGS_DEBUG="-g0" ^
|
|
||||||
-DCMAKE_EXE_LINKER_FLAGS="-lwinpthread" ^
|
-DCMAKE_EXE_LINKER_FLAGS="-lwinpthread" ^
|
||||||
-G"MinGW Makefiles" ^
|
-G"MinGW Makefiles" ^
|
||||||
-DCMAKE_BUILD_TYPE=Debug ^
|
-DCMAKE_BUILD_TYPE=Debug ^
|
||||||
@@ -179,7 +173,7 @@ jobs:
|
|||||||
architecture: [Win32, x64]
|
architecture: [Win32, x64]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
@@ -192,14 +186,14 @@ jobs:
|
|||||||
ci_module_cpp20:
|
ci_module_cpp20:
|
||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
# The module test uses `import std;`, which needs CMake's experimental
|
# The module test uses `import std;`, which needs CMake's experimental
|
||||||
# import-std support. Its opt-in token is CMake-version-specific, so pin
|
# import-std support. Its opt-in token is CMake-version-specific, so pin
|
||||||
# CMake to the version whose token is set in tests/module_cpp20/CMakeLists.txt.
|
# CMake to the version whose token is set in tests/module_cpp20/CMakeLists.txt.
|
||||||
- name: Get pinned CMake and ninja
|
- name: Get pinned CMake and ninja
|
||||||
uses: lukka/get-cmake@4a7d025fc60f00db0c7b44ebf783d19b52444830 # v4.4.1
|
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||||
with:
|
with:
|
||||||
cmakeVersion: 4.3.4
|
cmakeVersion: 4.3.4
|
||||||
- name: Run CMake (Debug)
|
- name: Run CMake (Debug)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
*.gcno
|
*.gcno
|
||||||
*.gcda
|
*.gcda
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
__pycache__/
|
||||||
|
|
||||||
/.idea
|
/.idea
|
||||||
/cmake-build-*
|
/cmake-build-*
|
||||||
@@ -43,5 +44,9 @@ venv
|
|||||||
|
|
||||||
nlohmann_json.spdx
|
nlohmann_json.spdx
|
||||||
|
|
||||||
|
# api_checker: ephemeral, location/doc-status-sensitive working file (not the committed
|
||||||
|
# release-tracking artifact -- see tools/api_checker/api_surface.json for that)
|
||||||
|
/tools/api_checker/api_snapshot.json
|
||||||
|
|
||||||
# Bazel-related
|
# Bazel-related
|
||||||
MODULE.bazel.lock
|
MODULE.bazel.lock
|
||||||
|
|||||||
@@ -42,7 +42,6 @@
|
|||||||
- [Specializing enum conversion](#specializing-enum-conversion)
|
- [Specializing enum conversion](#specializing-enum-conversion)
|
||||||
- [Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)](#binary-formats-bson-cbor-messagepack-ubjson-and-bjdata)
|
- [Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)](#binary-formats-bson-cbor-messagepack-ubjson-and-bjdata)
|
||||||
- [Customers](#customers)
|
- [Customers](#customers)
|
||||||
- [Ecosystem](#ecosystem)
|
|
||||||
- [Supported compilers](#supported-compilers)
|
- [Supported compilers](#supported-compilers)
|
||||||
- [Integration](#integration)
|
- [Integration](#integration)
|
||||||
- [CMake](#cmake)
|
- [CMake](#cmake)
|
||||||
@@ -91,6 +90,7 @@ You can sponsor this library at [GitHub Sponsors](https://github.com/sponsors/nl
|
|||||||
- [Steve Sperandeo](https://github.com/homer6)
|
- [Steve Sperandeo](https://github.com/homer6)
|
||||||
- [Robert Jefe Lindstädt](https://github.com/eljefedelrodeodeljefe)
|
- [Robert Jefe Lindstädt](https://github.com/eljefedelrodeodeljefe)
|
||||||
- [Steve Wagner](https://github.com/ciroque)
|
- [Steve Wagner](https://github.com/ciroque)
|
||||||
|
- [Lion Yang](https://github.com/LionNatsu)
|
||||||
|
|
||||||
### Further support
|
### Further support
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ Thanks everyone!
|
|||||||
|
|
||||||
:books: If you want to **learn more** about how to use the library, check out the rest of the [**README**](#examples), have a look at [**code examples**](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/examples), or browse through the [**help pages**](https://json.nlohmann.me).
|
:books: If you want to **learn more** about how to use the library, check out the rest of the [**README**](#examples), have a look at [**code examples**](https://github.com/nlohmann/json/tree/develop/docs/mkdocs/docs/examples), or browse through the [**help pages**](https://json.nlohmann.me).
|
||||||
|
|
||||||
:construction: If you want to understand the **API** better, check out the [**API Reference**](https://json.nlohmann.me/api/basic_json/) or have a look at the [quick reference](#quick-reference) below.
|
:construction: If you want to understand the **API** better, check out the [**API Reference**](https://json.nlohmann.me/api/basic_json/) or have a look at the [quick reference](#quick-reference) below. The public API surface is derived mechanically and checked for documentation coverage by the tooling in [`tools/api_checker/`](tools/api_checker/), whose [POLICY.md](tools/api_checker/POLICY.md) defines what counts as public API and what stability is guaranteed.
|
||||||
|
|
||||||
:bug: If you found a **bug**, please check the [**FAQ**](https://json.nlohmann.me/home/faq/) if it is a known issue or the result of a design decision. Please also have a look at the [**issue list**](https://github.com/nlohmann/json/issues) before you [**create a new issue**](https://github.com/nlohmann/json/issues/new/choose). Please provide as much information as possible to help us understand and reproduce your issue.
|
:bug: If you found a **bug**, please check the [**FAQ**](https://json.nlohmann.me/home/faq/) if it is a known issue or the result of a design decision. Please also have a look at the [**issue list**](https://github.com/nlohmann/json/issues) before you [**create a new issue**](https://github.com/nlohmann/json/issues/new/choose). Please provide as much information as possible to help us understand and reproduce your issue.
|
||||||
|
|
||||||
@@ -1187,11 +1187,6 @@ The library is used in multiple projects, applications, operating systems, etc.
|
|||||||
|
|
||||||
[](https://json.nlohmann.me/home/customers/)
|
[](https://json.nlohmann.me/home/customers/)
|
||||||
|
|
||||||
## Ecosystem
|
|
||||||
|
|
||||||
Beyond projects that use the library, there are third-party projects that build on top of it - schema validators,
|
|
||||||
language bindings, format converters, and the like. See the curated [Ecosystem](https://json.nlohmann.me/community/ecosystem/) page.
|
|
||||||
|
|
||||||
## Supported compilers
|
## Supported compilers
|
||||||
|
|
||||||
Though it's 2026 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
Though it's 2026 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
||||||
@@ -1807,13 +1802,13 @@ The library itself consists of a single header file licensed under the MIT licen
|
|||||||
- [**amalgamate.py - Amalgamate C source and header files**](https://github.com/edlund/amalgamate) to create a single header file
|
- [**amalgamate.py - Amalgamate C source and header files**](https://github.com/edlund/amalgamate) to create a single header file
|
||||||
- [**American fuzzy lop**](https://lcamtuf.coredump.cx/afl/) for fuzz testing
|
- [**American fuzzy lop**](https://lcamtuf.coredump.cx/afl/) for fuzz testing
|
||||||
- [**AppVeyor**](https://www.appveyor.com) for [continuous integration](https://ci.appveyor.com/project/nlohmann/json) on Windows
|
- [**AppVeyor**](https://www.appveyor.com) for [continuous integration](https://ci.appveyor.com/project/nlohmann/json) on Windows
|
||||||
- [**Artistic Style**](https://astyle.sourceforge.net) for automatic source code indentation
|
- [**Artistic Style**](http://astyle.sourceforge.net) for automatic source code indentation
|
||||||
- [**Clang**](https://clang.llvm.org) for compilation with code sanitizers
|
- [**Clang**](https://clang.llvm.org) for compilation with code sanitizers
|
||||||
- [**CMake**](https://cmake.org) for build automation
|
- [**CMake**](https://cmake.org) for build automation
|
||||||
- [**Codacy**](https://www.codacy.com) for further [code analysis](https://app.codacy.com/gh/nlohmann/json/dashboard)
|
- [**Codacy**](https://www.codacy.com) for further [code analysis](https://app.codacy.com/gh/nlohmann/json/dashboard)
|
||||||
- [**Coveralls**](https://coveralls.io) to measure [code coverage](https://coveralls.io/github/nlohmann/json)
|
- [**Coveralls**](https://coveralls.io) to measure [code coverage](https://coveralls.io/github/nlohmann/json)
|
||||||
- [**Coverity Scan**](https://scan.coverity.com) for [static analysis](https://scan.coverity.com/projects/nlohmann-json)
|
- [**Coverity Scan**](https://scan.coverity.com) for [static analysis](https://scan.coverity.com/projects/nlohmann-json)
|
||||||
- [**cppcheck**](https://cppcheck.sourceforge.io) for static analysis
|
- [**cppcheck**](http://cppcheck.sourceforge.net) for static analysis
|
||||||
- [**doctest**](https://github.com/onqtam/doctest) for the unit tests
|
- [**doctest**](https://github.com/onqtam/doctest) for the unit tests
|
||||||
- [**GitHub Changelog Generator**](https://github.com/skywinder/github-changelog-generator) to generate the [ChangeLog](https://github.com/nlohmann/json/blob/develop/ChangeLog.md)
|
- [**GitHub Changelog Generator**](https://github.com/skywinder/github-changelog-generator) to generate the [ChangeLog](https://github.com/nlohmann/json/blob/develop/ChangeLog.md)
|
||||||
- [**Google Benchmark**](https://github.com/google/benchmark) to implement the benchmarks
|
- [**Google Benchmark**](https://github.com/google/benchmark) to implement the benchmarks
|
||||||
@@ -1828,15 +1823,6 @@ The library itself consists of a single header file licensed under the MIT licen
|
|||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
### Standards compliance
|
|
||||||
|
|
||||||
The library targets strict conformance with [RFC 8259](https://tools.ietf.org/html/rfc8259.html). Both the original [JSONTestSuite](https://github.com/nst/JSONTestSuite) and its updated revision are exercised in CI; their test data is downloaded from [`nlohmann/json_test_data`](https://github.com/nlohmann/json_test_data) at configure time rather than committed to this repository (see [`tests/src/unit-testsuites.cpp`](https://github.com/nlohmann/json/blob/develop/tests/src/unit-testsuites.cpp)):
|
|
||||||
|
|
||||||
- The updated revision runs all mandatory `y_` (must-accept) and `n_` (must-reject) cases through the strict [`parse()`](https://json.nlohmann.me/api/basic_json/parse/) entry point; the original suite runs its `n_` cases through `parse()` and its `y_` cases through [`operator>>`](https://json.nlohmann.me/api/operator_gtgt/).
|
|
||||||
- The `i_` (implementation-defined) cases are, by RFC 8259, free to be accepted *or* rejected, so "passing all `i_` cases" is not a meaningful conformance metric. The library makes deliberate, documented choices there: nesting depth is not artificially limited, a leading UTF-8 byte order mark is silently ignored, [Unicode noncharacters](https://www.unicode.org/faq/private_use.html#nonchar1) are forwarded unchanged, invalid UTF-8 and lone/unpaired UTF-16 surrogates are rejected (stricter than required), and a number that cannot be stored without becoming `NaN`/`INF` raises [`out_of_range.406`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range406).
|
|
||||||
|
|
||||||
One behavioral nuance is worth calling out, because a superficial test often misreads it as non-compliance: [`parse()`](https://json.nlohmann.me/api/basic_json/parse/) is strict and rejects trailing data after a value, whereas [`operator>>`](https://json.nlohmann.me/api/operator_gtgt/) follows relaxed iostream semantics — it parses a single value and leaves the stream positioned right after it. Feeding "a valid document followed by trailing bytes" through `operator>>` reports success; the same input through `parse()` is rejected. This is a documented two-API design, not a conformance gap. See [**parsing**](https://json.nlohmann.me/features/parsing/) for details.
|
|
||||||
|
|
||||||
### Character encoding
|
### Character encoding
|
||||||
|
|
||||||
The library supports **Unicode input** as follows:
|
The library supports **Unicode input** as follows:
|
||||||
|
|||||||
@@ -5,9 +5,6 @@
|
|||||||
# -Wno-extra-semi-stmt The library uses assert which triggers this warning.
|
# -Wno-extra-semi-stmt The library uses assert which triggers this warning.
|
||||||
# -Wno-padded We do not care about padding warnings.
|
# -Wno-padded We do not care about padding warnings.
|
||||||
# -Wno-covered-switch-default All switches list all cases and a default case.
|
# -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
|
|
||||||
# C++ mode. The library does not use __COUNTER__; the warnings
|
|
||||||
# all come from vendored Doctest (SECTION/TEST_CASE macros).
|
|
||||||
# -Wno-unsafe-buffer-usage Pervasive: the library's own low-level numeric/buffer code
|
# -Wno-unsafe-buffer-usage Pervasive: the library's own low-level numeric/buffer code
|
||||||
# (to_chars, serializer, lexer, binary reader/writer, input
|
# (to_chars, serializer, lexer, binary reader/writer, input
|
||||||
# adapters, json_pointer) plus vendored Doctest itself (~208
|
# adapters, json_pointer) plus vendored Doctest itself (~208
|
||||||
@@ -23,6 +20,5 @@ set(CLANG_CXXFLAGS
|
|||||||
-Wno-extra-semi-stmt
|
-Wno-extra-semi-stmt
|
||||||
-Wno-padded
|
-Wno-padded
|
||||||
-Wno-covered-switch-default
|
-Wno-covered-switch-default
|
||||||
-Wno-c2y-extensions
|
|
||||||
-Wno-unsafe-buffer-usage
|
-Wno-unsafe-buffer-usage
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ Unlike the [`parse()`](parse.md) function, this function neither throws an excep
|
|||||||
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
||||||
|
|
||||||
- a custom sentinel type for C++20 ranges
|
- a custom sentinel type for C++20 ranges
|
||||||
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
- `std::counted_iterator` with a different sentinel type
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -420,7 +420,9 @@ basic_json(basic_json&& other) noexcept;
|
|||||||
1. Since version 1.0.0.
|
1. Since version 1.0.0.
|
||||||
2. Since version 1.0.0.
|
2. Since version 1.0.0.
|
||||||
3. Since version 2.1.0.
|
3. Since version 2.1.0.
|
||||||
4. Since version 3.2.0.
|
4. Since version 3.2.0. Also initializes the position reported by
|
||||||
|
[`start_pos()`](start_pos.md)/[`end_pos()`](end_pos.md) from `val` when
|
||||||
|
[`JSON_DIAGNOSTIC_POSITIONS`](../macros/json_diagnostic_positions.md) is enabled, since version 3.12.0.
|
||||||
5. Since version 1.0.0.
|
5. Since version 1.0.0.
|
||||||
6. Since version 1.0.0.
|
6. Since version 1.0.0.
|
||||||
7. Since version 1.0.0.
|
7. Since version 1.0.0.
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ is compatible with both of the binary data formats that use binary subtyping, (t
|
|||||||
incompatible with each other, and it is up to the user to translate between them). The subtype is added to `BinaryType`
|
incompatible with each other, and it is up to the user to translate between them). The subtype is added to `BinaryType`
|
||||||
via the helper type [byte_container_with_subtype](../byte_container_with_subtype/index.md).
|
via the helper type [byte_container_with_subtype](../byte_container_with_subtype/index.md).
|
||||||
|
|
||||||
[CBOR's RFC 8949](https://www.rfc-editor.org/rfc/rfc8949.html#section-3.1) describes this type as:
|
[CBOR's RFC 7049](https://tools.ietf.org/html/rfc7049) describes this type as:
|
||||||
> Major type 2: A byte string. The number of bytes in the string is equal to the argument.
|
> Major type 2: a byte string. The string's length in bytes is represented following the rules for positive integers
|
||||||
|
> (major type 0).
|
||||||
|
|
||||||
[MessagePack's documentation on the bin type
|
[MessagePack's documentation on the bin type
|
||||||
family](https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family) describes this type as:
|
family](https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family) describes this type as:
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# <small>nlohmann::basic_json::</small>bjdata_version_t
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
enum class bjdata_version_t
|
||||||
|
{
|
||||||
|
draft2,
|
||||||
|
draft3,
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
This enumeration is used in the [`to_bjdata`](to_bjdata.md) function to choose which draft version of
|
||||||
|
the BJData specification to encode ND-array extensions for:
|
||||||
|
|
||||||
|
draft2
|
||||||
|
: encode using the BJData Draft 2 ND-array format
|
||||||
|
|
||||||
|
draft3
|
||||||
|
: encode using the BJData Draft 3 ND-array format
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how `bjdata_version_t` selects the BJData draft used by `to_bjdata`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/bjdata_version_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/bjdata_version_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.12.0.
|
||||||
@@ -43,17 +43,6 @@ Strong guarantee: if an exception is thrown, there are no changes to any JSON va
|
|||||||
Throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) if a string stored inside the JSON value
|
Throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) if a string stored inside the JSON value
|
||||||
is not UTF-8 encoded and `error_handler` is set to `strict`
|
is not UTF-8 encoded and `error_handler` is set to `strict`
|
||||||
|
|
||||||
!!! warning "Serializing untrusted input"
|
|
||||||
|
|
||||||
When serializing values that may contain invalid or untrusted UTF-8 (e.g., bytes taken directly from network
|
|
||||||
input), `dump()` throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) in the default
|
|
||||||
`strict` mode. To serialize such data without throwing, pass
|
|
||||||
[`error_handler_t::replace`](error_handler_t.md) (substitutes U+FFFD) or
|
|
||||||
[`error_handler_t::ignore`](error_handler_t.md). Callers that serialize untrusted input on a crash-sensitive path
|
|
||||||
should either choose a non-strict error handler or wrap `dump()` in a `#!cpp try`/`#!cpp catch`.
|
|
||||||
|
|
||||||
See the [FAQ](../../home/faq.md#serializing-untrusted-or-invalid-utf-8) for details.
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
Linear.
|
Linear.
|
||||||
|
|||||||
@@ -36,10 +36,8 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: a compatible iterator type
|
: a compatible iterator type
|
||||||
|
|
||||||
`SentinelType`
|
`SentinelType`
|
||||||
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance a
|
||||||
|
custom sentinel type for C++20 ranges
|
||||||
- a custom sentinel type for C++20 ranges
|
|
||||||
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,8 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: a compatible iterator type
|
: a compatible iterator type
|
||||||
|
|
||||||
`SentinelType`
|
`SentinelType`
|
||||||
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance a
|
||||||
|
custom sentinel type for C++20 ranges
|
||||||
- a custom sentinel type for C++20 ranges
|
|
||||||
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -39,10 +39,8 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: a compatible iterator type
|
: a compatible iterator type
|
||||||
|
|
||||||
`SentinelType`
|
`SentinelType`
|
||||||
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance a
|
||||||
|
custom sentinel type for C++20 ranges
|
||||||
- a custom sentinel type for C++20 ranges
|
|
||||||
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,8 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: a compatible iterator type
|
: a compatible iterator type
|
||||||
|
|
||||||
`SentinelType`
|
`SentinelType`
|
||||||
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance a
|
||||||
|
custom sentinel type for C++20 ranges
|
||||||
- a custom sentinel type for C++20 ranges
|
|
||||||
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,8 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: a compatible iterator type
|
: a compatible iterator type
|
||||||
|
|
||||||
`SentinelType`
|
`SentinelType`
|
||||||
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance a
|
||||||
|
custom sentinel type for C++20 ranges
|
||||||
- a custom sentinel type for C++20 ranges
|
|
||||||
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# <small>nlohmann::basic_json::</small>initializer_list_t
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using initializer_list_t = std::initializer_list<detail::json_ref<basic_json>>;
|
||||||
|
```
|
||||||
|
|
||||||
|
The type used for the initializer-list [constructor](basic_json.md) (overload 5) and for functions
|
||||||
|
such as [`operator=`](operator=.md) that accept a braced-init-list of JSON values. Each element wraps a
|
||||||
|
`basic_json` value or something convertible to one, deferring the decision of whether the list should be
|
||||||
|
parsed as a JSON array or a JSON object to the constructor itself.
|
||||||
|
|
||||||
|
See the [constructor](basic_json.md) documentation for how `initializer_list_t` values are interpreted.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how an `initializer_list_t` is used to construct a JSON value.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/initializer_list_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/initializer_list_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Since version 1.0.0.
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# <small>nlohmann::basic_json::</small>json_sax_t
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using json_sax_t = json_sax<basic_json>;
|
||||||
|
```
|
||||||
|
|
||||||
|
The [`json_sax`](../json_sax/index.md) interface bound to this `basic_json` specialization, i.e. with
|
||||||
|
`BasicJsonType` fixed to `basic_json`. Used as the SAX interface type by [`sax_parse`](sax_parse.md) and
|
||||||
|
other SAX-based parsing functions.
|
||||||
|
|
||||||
|
See [`nlohmann::json_sax`](../json_sax/index.md) for more information.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the type `json_sax_t`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/json_sax_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/json_sax_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.2.0.
|
||||||
@@ -51,3 +51,5 @@ Linear.
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
- The `noexcept` specification was extended to also depend on
|
||||||
|
[`json_base_class_t`](json_base_class_t.md)'s move-assignment in version 3.11.3.
|
||||||
|
|||||||
@@ -85,3 +85,8 @@ Linear in the size of the JSON value.
|
|||||||
- Since version 1.0.0.
|
- Since version 1.0.0.
|
||||||
- Macros `JSON_EXPLICIT`/[`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md) added
|
- Macros `JSON_EXPLICIT`/[`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md) added
|
||||||
in version 3.9.0.
|
in version 3.9.0.
|
||||||
|
- The exclusion of `std::any` from this conversion became conditional on
|
||||||
|
[`JSON_HAS_STATIC_RTTI`](../macros/json_has_static_rtti.md) in version 3.11.3.
|
||||||
|
- `std::optional<T>` excluded from this conversion in version 3.13.0; use
|
||||||
|
[`get<std::optional<T>>()`](get.md)/[`get_to()`](get_to.md) instead (see
|
||||||
|
[Converting values](../../features/conversions.md)).
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ static basic_json parse(IteratorType first, SentinelType last,
|
|||||||
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
|
||||||
|
|
||||||
- a custom sentinel type for C++20 ranges
|
- a custom sentinel type for C++20 ranges
|
||||||
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
- `std::counted_iterator` with a different sentinel type
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -29,14 +29,7 @@ Discarding a value (i.e., returning `#!cpp false`) has different effects dependi
|
|||||||
called:
|
called:
|
||||||
|
|
||||||
- Discarded values in structured types are skipped. That is, the parser will behave as if the discarded value was never
|
- Discarded values in structured types are skipped. That is, the parser will behave as if the discarded value was never
|
||||||
read. This holds for every value type and for both kinds of parent: a discarded element is removed from the
|
read.
|
||||||
surrounding array, and a discarded member is removed from the surrounding object together with its key.
|
|
||||||
- Arrays and objects can be discarded either at their `parse_event_t::array_start`/`parse_event_t::object_start` event
|
|
||||||
or at their `parse_event_t::array_end`/`parse_event_t::object_end` event, and both remove the whole value. Discarding
|
|
||||||
it at the start event also means the callback is called neither for the content of the value nor for its matching end
|
|
||||||
event.
|
|
||||||
- Discarding a `parse_event_t::key` event discards the whole object member. The callback is still called for the
|
|
||||||
associated value, but its return value has no further effect.
|
|
||||||
- In case a value outside a structured type is skipped, it is replaced with `null`. This case happens if the top-level
|
- In case a value outside a structured type is skipped, it is replaced with `null`. This case happens if the top-level
|
||||||
element is skipped.
|
element is skipped.
|
||||||
|
|
||||||
@@ -56,7 +49,7 @@ called:
|
|||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
Whether the JSON value which called the function during parsing should be kept (`#!cpp true`) or not (`#!cpp false`). In
|
Whether the JSON value which called the function during parsing should be kept (`#!cpp true`) or not (`#!cpp false`). In
|
||||||
the latter case, it is skipped completely, or replaced by `null` if it is the top-level value.
|
the latter case, it is either skipped completely or replaced by an empty discarded object.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@@ -75,21 +68,6 @@ the latter case, it is skipped completely, or replaced by `null` if it is the to
|
|||||||
--8<-- "examples/parse__string__parser_callback_t.output"
|
--8<-- "examples/parse__string__parser_callback_t.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/parser_callback_t.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/parser_callback_t.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [parse](parse.md) deserialize from a compatible input
|
- [parse](parse.md) deserialize from a compatible input
|
||||||
@@ -98,5 +76,3 @@ the latter case, it is skipped completely, or replaced by `null` if it is the to
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
- Fixed in version 3.13.0 to also remove discarded values from a parent object; before, discarding an array or a value
|
|
||||||
stored under an object key left a discarded member behind, which made the parse result serialize to invalid JSON.
|
|
||||||
|
|||||||
@@ -48,10 +48,7 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index
|
|||||||
with a size of 1, 2, or 4 bytes (interpreted respectively as UTF-8, UTF-16, and UTF-32)
|
with a size of 1, 2, or 4 bytes (interpreted respectively as UTF-8, UTF-16, and UTF-32)
|
||||||
|
|
||||||
`SentinelType`
|
`SentinelType`
|
||||||
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for overload (2), for instance.
|
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for overload (2)
|
||||||
|
|
||||||
- a custom sentinel type for C++20 ranges
|
|
||||||
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
|
|
||||||
|
|
||||||
`SAX`
|
`SAX`
|
||||||
: a class fulfilling the SAX event listener interface; see [`json_sax`](../json_sax/index.md)
|
: a class fulfilling the SAX event listener interface; see [`json_sax`](../json_sax/index.md)
|
||||||
|
|||||||
@@ -40,9 +40,6 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
is not an object; example: `"to serialize to BSON, top-level type must be object, but is string"`
|
is not an object; example: `"to serialize to BSON, top-level type must be object, but is string"`
|
||||||
- Throws [`out_of_range.409`](../../home/exceptions.md#jsonexceptionout_of_range409) if a key in the JSON object contains
|
- Throws [`out_of_range.409`](../../home/exceptions.md#jsonexceptionout_of_range409) if a key in the JSON object contains
|
||||||
a null byte (code point U+0000); example: `"BSON key cannot contain code point U+0000 (at byte 2)"`
|
a null byte (code point U+0000); example: `"BSON key cannot contain code point U+0000 (at byte 2)"`
|
||||||
- Throws [`out_of_range.412`](../../home/exceptions.md#jsonexceptionout_of_range412) if the length of a document, array,
|
|
||||||
string, or binary value exceeds the range of the 32-bit BSON length field; example:
|
|
||||||
`"BSON length 2147483661 exceeds maximum of 2147483647"`
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# <small>nlohmann::byte_container_with_subtype::</small>container_type
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using container_type = BinaryType;
|
||||||
|
```
|
||||||
|
|
||||||
|
The type of the underlying binary container, forwarded from the `BinaryType` template parameter that
|
||||||
|
`byte_container_with_subtype` is instantiated with. `byte_container_with_subtype` publicly inherits from
|
||||||
|
`container_type`.
|
||||||
|
|
||||||
|
See [`basic_json::binary_t`](../basic_json/binary_t.md) for the type typically used to instantiate
|
||||||
|
`BinaryType`.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the type `container_type`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/byte_container_with_subtype__container_type.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/byte_container_with_subtype__container_type.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Since version 3.8.0.
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# <small>nlohmann::byte_container_with_subtype::</small>operator==
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
bool operator==(const byte_container_with_subtype& rhs) const;
|
||||||
|
```
|
||||||
|
|
||||||
|
Compares two `byte_container_with_subtype` values for equality by comparing the underlying binary
|
||||||
|
container, the subtype, and whether a subtype is set.
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`rhs` (in)
|
||||||
|
: value to compare `*this` against
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
whether `*this` and `rhs` are equal
|
||||||
|
|
||||||
|
## Exception safety
|
||||||
|
|
||||||
|
No-throw guarantee: this function never throws exceptions.
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the size of the underlying binary container.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example demonstrates comparing `byte_container_with_subtype` values.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/byte_container_with_subtype__operator_eq.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/byte_container_with_subtype__operator_eq.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Since version 3.8.0.
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# <small>nlohmann::byte_container_with_subtype::</small>operator!=
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
bool operator!=(const byte_container_with_subtype& rhs) const;
|
||||||
|
```
|
||||||
|
|
||||||
|
Compares two `byte_container_with_subtype` values for inequality. Implemented as the negation of
|
||||||
|
[`operator==`](operator_eq.md).
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`rhs` (in)
|
||||||
|
: value to compare `*this` against
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
whether `*this` and `rhs` are not equal
|
||||||
|
|
||||||
|
## Exception safety
|
||||||
|
|
||||||
|
No-throw guarantee: this function never throws exceptions.
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the size of the underlying binary container.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example demonstrates comparing `byte_container_with_subtype` values.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/byte_container_with_subtype__operator_ne.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/byte_container_with_subtype__operator_ne.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Since version 3.8.0.
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# <small>nlohmann::byte_container_with_subtype::</small>subtype_type
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using subtype_type = std::uint64_t;
|
||||||
|
```
|
||||||
|
|
||||||
|
The type used to store the optional binary subtype tag. See [`subtype`](subtype.md) and
|
||||||
|
[`set_subtype`](set_subtype.md).
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the type `subtype_type`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/byte_container_with_subtype__subtype_type.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/byte_container_with_subtype__subtype_type.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Since version 3.8.0.
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# <small>nlohmann::json_sax::</small>binary_t
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using binary_t = typename BasicJsonType::binary_t;
|
||||||
|
```
|
||||||
|
|
||||||
|
The type used by the [`binary`](binary.md) callback for JSON binary values, forwarded from the
|
||||||
|
`BasicJsonType` template parameter.
|
||||||
|
|
||||||
|
See [`basic_json::binary_t`](../basic_json/binary_t.md) for more information.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the type `binary_t` and its relation to `basic_json::binary_t`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/json_sax__binary_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/json_sax__binary_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.8.0.
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# <small>nlohmann::json_sax::</small>json_sax
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
json_sax() = default;
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
json_sax(const json_sax&) = default;
|
||||||
|
|
||||||
|
// (3)
|
||||||
|
json_sax(json_sax&&) noexcept = default;
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Default constructor.
|
||||||
|
2. Copy constructor.
|
||||||
|
3. Move constructor.
|
||||||
|
|
||||||
|
`json_sax` is a pure abstract base class with no data members of its own, so all three constructors are
|
||||||
|
defaulted and only exist to make derived SAX consumers explicitly copyable/movable.
|
||||||
|
|
||||||
|
## Exception safety
|
||||||
|
|
||||||
|
No-throw guarantee: none of these constructors throw exceptions.
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Constant.
|
||||||
|
|
||||||
|
<!-- NOLINT Examples -->
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.2.0.
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# <small>nlohmann::json_sax::</small>number_float_t
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using number_float_t = typename BasicJsonType::number_float_t;
|
||||||
|
```
|
||||||
|
|
||||||
|
The type used by the [`number_float`](number_float.md) callback for JSON floating-point numbers,
|
||||||
|
forwarded from the `BasicJsonType` template parameter.
|
||||||
|
|
||||||
|
See [`basic_json::number_float_t`](../basic_json/number_float_t.md) for more information.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the type `number_float_t` and its relation to `basic_json::number_float_t`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/json_sax__number_float_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/json_sax__number_float_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.2.0.
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# <small>nlohmann::json_sax::</small>number_integer_t
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using number_integer_t = typename BasicJsonType::number_integer_t;
|
||||||
|
```
|
||||||
|
|
||||||
|
The type used by the [`number_integer`](number_integer.md) callback for JSON integer numbers, forwarded
|
||||||
|
from the `BasicJsonType` template parameter.
|
||||||
|
|
||||||
|
See [`basic_json::number_integer_t`](../basic_json/number_integer_t.md) for more information.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the type `number_integer_t` and its relation to `basic_json::number_integer_t`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/json_sax__number_integer_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/json_sax__number_integer_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.2.0.
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# <small>nlohmann::json_sax::</small>number_unsigned_t
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
|
||||||
|
```
|
||||||
|
|
||||||
|
The type used by the [`number_unsigned`](number_unsigned.md) callback for JSON unsigned integer numbers,
|
||||||
|
forwarded from the `BasicJsonType` template parameter.
|
||||||
|
|
||||||
|
See [`basic_json::number_unsigned_t`](../basic_json/number_unsigned_t.md) for more information.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the type `number_unsigned_t` and its relation to `basic_json::number_unsigned_t`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/json_sax__number_unsigned_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/json_sax__number_unsigned_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.2.0.
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# <small>nlohmann::json_sax::</small>operator=
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
json_sax& operator=(const json_sax&) = default;
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
json_sax& operator=(json_sax&&) noexcept = default;
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Copy assignment operator.
|
||||||
|
2. Move assignment operator.
|
||||||
|
|
||||||
|
`json_sax` is a pure abstract base class with no data members of its own, so both assignment operators
|
||||||
|
are defaulted and only exist to make derived SAX consumers explicitly copy-/move-assignable.
|
||||||
|
|
||||||
|
## Exception safety
|
||||||
|
|
||||||
|
No-throw guarantee: neither operator throws exceptions.
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Constant.
|
||||||
|
|
||||||
|
<!-- NOLINT Examples -->
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.2.0.
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# <small>nlohmann::json_sax::</small>string_t
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using string_t = typename BasicJsonType::string_t;
|
||||||
|
```
|
||||||
|
|
||||||
|
The type used by the [`string`](string.md) and [`key`](key.md) callbacks for JSON strings and object
|
||||||
|
keys, forwarded from the `BasicJsonType` template parameter.
|
||||||
|
|
||||||
|
See [`basic_json::string_t`](../basic_json/string_t.md) for more information.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the type `string_t` and its relation to `basic_json::string_t`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/json_sax__string_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/json_sax__string_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.2.0.
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# <small>nlohmann::json_sax::</small>~json_sax
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
virtual ~json_sax() = default;
|
||||||
|
```
|
||||||
|
|
||||||
|
Destructor. Virtual to allow proper destruction of derived SAX consumer classes through a
|
||||||
|
pointer/reference to `json_sax`.
|
||||||
|
|
||||||
|
## Exception safety
|
||||||
|
|
||||||
|
No-throw guarantee: this destructor never throws exceptions.
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Constant.
|
||||||
|
|
||||||
|
<!-- NOLINT Examples -->
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.2.0.
|
||||||
@@ -38,8 +38,7 @@ When the macro is not defined, the library will define it to its default value.
|
|||||||
|
|
||||||
Diagnostic messages can also be controlled with the CMake option
|
Diagnostic messages can also be controlled with the CMake option
|
||||||
[`JSON_Diagnostics`](../../integration/cmake.md#json_diagnostics) (`OFF` by default)
|
[`JSON_Diagnostics`](../../integration/cmake.md#json_diagnostics) (`OFF` by default)
|
||||||
which defines `JSON_DIAGNOSTICS` accordingly. Note this only applies when building the
|
which defines `JSON_DIAGNOSTICS` accordingly.
|
||||||
library from source — see the pre-installed-package caveat on that page.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -33,44 +33,17 @@ A UTF-8 byte order mark is silently ignored.
|
|||||||
Invalid Unicode escapes and unpaired surrogates in the input are reported as
|
Invalid Unicode escapes and unpaired surrogates in the input are reported as
|
||||||
[`parse_error.101`](../home/exceptions.md#jsonexceptionparse_error101) with a detailed message.
|
[`parse_error.101`](../home/exceptions.md#jsonexceptionparse_error101) with a detailed message.
|
||||||
|
|
||||||
`operator>>` parses exactly one JSON value, so it can be called repeatedly to read a sequence of concatenated JSON
|
`operator>>` parses exactly one JSON value and leaves the stream positioned right after it, so it can be called
|
||||||
values from the same stream:
|
repeatedly to read a sequence of concatenated JSON values from the same stream:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
json j1, j2;
|
json j1, j2;
|
||||||
input >> j1; // parses the first value
|
input >> j1; // parses the first value, stream now positioned right after it
|
||||||
input >> j2; // parses the next value
|
input >> j2; // parses the next value
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! warning "A number must be followed by whitespace"
|
Note this does **not** work for [JSON Lines](../features/parsing/json_lines.md) (newline-delimited JSON) input --
|
||||||
|
see that page for why and for the recommended alternative.
|
||||||
A number is only terminated by the character that follows it. That character is read from the stream to detect the
|
|
||||||
end of the number, and it is **not** put back. When a value that is a number is immediately followed by the next
|
|
||||||
value, the first character of that next value is lost:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
std::istringstream input("1true");
|
|
||||||
json j1, j2;
|
|
||||||
input >> j1; // j1 == 1
|
|
||||||
input >> j2; // throws parse_error.101: the stream now starts at "rue"
|
|
||||||
```
|
|
||||||
|
|
||||||
Separating the values with whitespace avoids this, because the character that is eaten is then the separator:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
std::istringstream input("1 true");
|
|
||||||
json j1, j2;
|
|
||||||
input >> j1; // j1 == 1
|
|
||||||
input >> j2; // j2 == true
|
|
||||||
```
|
|
||||||
|
|
||||||
Only numbers are affected. Values ending in a self-delimiting character do not read past themselves, so
|
|
||||||
`truefalse`, `[1][2]`, `{"a":1}{"b":2}`, and `"a""b"` can be read back to back without a separator.
|
|
||||||
|
|
||||||
This is tracked in [#5340](https://github.com/nlohmann/json/issues/5340).
|
|
||||||
|
|
||||||
Note that reading concatenated values does **not** work for [JSON Lines](../features/parsing/json_lines.md)
|
|
||||||
(newline-delimited JSON) input -- see that page for why and for the recommended alternative.
|
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -8,17 +8,11 @@ This type preserves the insertion order of object keys.
|
|||||||
|
|
||||||
## Iterator invalidation
|
## Iterator invalidation
|
||||||
|
|
||||||
The type is based on [`ordered_map`](ordered_map.md) which in turn uses a `std::vector` to store object elements.
|
The type is based on [`ordered_map`](ordered_map/index.md) which in turn uses a `std::vector` to store object elements.
|
||||||
Therefore, adding object elements can yield a reallocation in which case all iterators (including the
|
Therefore, adding object elements can yield a reallocation in which case all iterators (including the
|
||||||
[`end()`](basic_json/end.md) iterator) and all references to the elements are invalidated. Also, any iterator or
|
[`end()`](basic_json/end.md) iterator) and all references to the elements are invalidated. Also, any iterator or
|
||||||
reference after the insertion point will point to the same index, which is now a different value.
|
reference after the insertion point will point to the same index, which is now a different value.
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
[`ordered_map`](ordered_map.md) has no lookup index: every key-based object operation is a linear scan, so building or
|
|
||||||
parsing an object of `n` keys costs O(n²) rather than O(n log n). See
|
|
||||||
[`ordered_map` complexity](ordered_map.md#complexity) for the per-operation table and for measured numbers.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
@@ -37,7 +31,7 @@ parsing an object of `n` keys costs O(n²) rather than O(n log n). See
|
|||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
- [ordered_map](ordered_map.md)
|
- [ordered_map](ordered_map/index.md)
|
||||||
- [Object Order](../features/object_order.md)
|
- [Object Order](../features/object_order.md)
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|||||||
@@ -1,124 +0,0 @@
|
|||||||
# <small>nlohmann::</small>ordered_map
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
template<class Key, class T, class IgnoredLess = std::less<Key>,
|
|
||||||
class Allocator = std::allocator<std::pair<const Key, T>>>
|
|
||||||
struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>;
|
|
||||||
```
|
|
||||||
|
|
||||||
A minimal map-like container that preserves insertion order for use within [`nlohmann::ordered_json`](ordered_json.md)
|
|
||||||
(`nlohmann::basic_json<ordered_map>`).
|
|
||||||
|
|
||||||
## Template parameters
|
|
||||||
|
|
||||||
`Key`
|
|
||||||
: key type
|
|
||||||
|
|
||||||
`T`
|
|
||||||
: mapped type
|
|
||||||
|
|
||||||
`IgnoredLess`
|
|
||||||
: comparison function (ignored and only added to ensure compatibility with `#!cpp std::map`)
|
|
||||||
|
|
||||||
`Allocator`
|
|
||||||
: allocator type
|
|
||||||
|
|
||||||
## Iterator invalidation
|
|
||||||
|
|
||||||
The type uses a `std::vector` to store object elements. Therefore, adding elements can yield a reallocation in which
|
|
||||||
case all iterators (including the `end()` iterator) and all references to the elements are invalidated.
|
|
||||||
|
|
||||||
## Member types
|
|
||||||
|
|
||||||
- **key_type** - key type (`Key`)
|
|
||||||
- **mapped_type** - mapped type (`T`)
|
|
||||||
- **Container** - base container type (`#!cpp std::vector<std::pair<const Key, T>, Allocator>`)
|
|
||||||
- **iterator**
|
|
||||||
- **const_iterator**
|
|
||||||
- **size_type**
|
|
||||||
- **value_type**
|
|
||||||
- **key_compare** - key comparison function
|
|
||||||
```cpp
|
|
||||||
std::equal_to<Key> // until C++14
|
|
||||||
|
|
||||||
std::equal_to<> // since C++14
|
|
||||||
```
|
|
||||||
|
|
||||||
## Member functions
|
|
||||||
|
|
||||||
- (constructor)
|
|
||||||
- (destructor)
|
|
||||||
- **emplace**
|
|
||||||
- **operator\[\]**
|
|
||||||
- **at**
|
|
||||||
- **erase**
|
|
||||||
- **count**
|
|
||||||
- **find**
|
|
||||||
- **insert**
|
|
||||||
|
|
||||||
## Complexity
|
|
||||||
|
|
||||||
Because the elements are stored in a `std::vector` in insertion order, there is no index to look a key up by. Every
|
|
||||||
key-based operation performs a **linear scan** over the stored elements. With `n` denoting the number of elements in the
|
|
||||||
container:
|
|
||||||
|
|
||||||
| Operation | Complexity | Note |
|
|
||||||
|----------------------------------------|----------------|----------------------------------------------------------|
|
|
||||||
| **emplace** | O(n) | scans for an existing key, then appends (amortized O(1)) |
|
|
||||||
| **operator\[\]** | O(n) | delegates to **emplace** (non-const) or **at** (const) |
|
|
||||||
| **at** | O(n) | throws `#!cpp std::out_of_range` if the key is not found |
|
|
||||||
| **find** | O(n) | |
|
|
||||||
| **count** | O(n) | the result is always 0 or 1 |
|
|
||||||
| **erase(key)** | O(n) | scan, then move the remaining elements one position down |
|
|
||||||
| **erase(pos)**, **erase(first, last)** | O(n) | moves all elements after the erased range |
|
|
||||||
| **insert(value)** | O(n) | equivalent to **emplace** |
|
|
||||||
| **insert(first, last)** | O((n + m) * m) | for `m` inserted elements |
|
|
||||||
|
|
||||||
This differs from `#!cpp std::map`, where the same operations are O(log n).
|
|
||||||
|
|
||||||
!!! warning "Quadratic cost of building large objects"
|
|
||||||
|
|
||||||
Because every insertion scans all elements inserted so far, building an object of `n` distinct keys costs
|
|
||||||
**O(n²)** in total. This applies to filling an [`ordered_json`](ordered_json.md) object key by key as well as to
|
|
||||||
parsing one, since the parser inserts each key as it is read.
|
|
||||||
|
|
||||||
The cost is negligible for the object sizes typically found in configuration files or API payloads, but it grows
|
|
||||||
steeply for machine-generated objects with many thousands of keys. Measured with `-O2 -DNDEBUG` for parsing a flat
|
|
||||||
object of `n` keys, relative to `#!cpp nlohmann::json` (which uses `#!cpp std::map`):
|
|
||||||
|
|
||||||
| `n` | `json` | `ordered_json` | factor |
|
|
||||||
|--------|--------|----------------|--------|
|
|
||||||
| 2000 | 0.7 ms | 3.6 ms | 5× |
|
|
||||||
| 4000 | 0.8 ms | 14.0 ms | 19× |
|
|
||||||
| 8000 | 1.6 ms | 67.8 ms | 43× |
|
|
||||||
| 16 000 | 3.3 ms | 181.6 ms | 54× |
|
|
||||||
|
|
||||||
If key order matters for objects of that size, consider a container with a lookup index, such as
|
|
||||||
[`tsl::ordered_map`](https://github.com/Tessil/ordered-map)
|
|
||||||
([integration](https://github.com/nlohmann/json/issues/546#issuecomment-304447518)), as the object type -- see
|
|
||||||
[object order](../features/object_order.md).
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
The example shows the different behavior of `std::map` and `nlohmann::ordered_map`.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "examples/ordered_map.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Output:
|
|
||||||
|
|
||||||
```json
|
|
||||||
--8<-- "examples/ordered_map.output"
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [ordered_json](ordered_json.md)
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](ordered_json.md).
|
|
||||||
- Added **key_compare** member in version 3.11.0.
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>Container
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using Container = std::vector<std::pair<const Key, T>, Allocator>;
|
||||||
|
```
|
||||||
|
|
||||||
|
The base container type that `ordered_map` publicly inherits from. Elements are stored in insertion
|
||||||
|
order as `#!cpp std::pair<const Key, T>` entries in a `std::vector`.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the type `Container`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/ordered_map__Container.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/ordered_map__Container.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>at
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
T& at(const key_type& key);
|
||||||
|
const T& at(const key_type& key) const;
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
template<class KeyType>
|
||||||
|
T& at(KeyType&& key);
|
||||||
|
template<class KeyType>
|
||||||
|
const T& at(KeyType&& key) const;
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Returns a reference to the value mapped to `key`.
|
||||||
|
2. Same as (1), but for any `KeyType` comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
(heterogeneous lookup, e.g. looking up by a `#!cpp const char*` without constructing a temporary
|
||||||
|
`key_type`). Only participates in overload resolution if `KeyType` is usable as a key type.
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`KeyType`
|
||||||
|
: a type comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`key` (in)
|
||||||
|
: key of the element to find
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
reference to the mapped value of the element with key equal to `key`
|
||||||
|
|
||||||
|
## Exceptions
|
||||||
|
|
||||||
|
Throws `std::out_of_range` if no element with key `key` exists.
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the number of elements.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how `at` is used.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/ordered_map__at.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/ordered_map__at.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.1 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
|
- Overload (2) added in version 3.11.0.
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>count
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
size_type count(const key_type& key) const;
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
template<class KeyType>
|
||||||
|
size_type count(KeyType&& key) const;
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Returns the number of elements with key equal to `key` (0 or 1, since keys are unique).
|
||||||
|
2. Same as (1), but for any `KeyType` comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
(heterogeneous lookup). Only participates in overload resolution if `KeyType` is usable as a key type.
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`KeyType`
|
||||||
|
: a type comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`key` (in)
|
||||||
|
: key of the elements to count
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
number of elements with key equal to `key` (0 or 1)
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the number of elements.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how `count` is used.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/ordered_map__count.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/ordered_map__count.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.1 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
|
- Overload (2) added in version 3.11.0.
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>emplace
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
std::pair<iterator, bool> emplace(const key_type& key, T&& t);
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
template<class KeyType>
|
||||||
|
std::pair<iterator, bool> emplace(KeyType&& key, T&& t);
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Inserts `#!cpp {key, t}` if no element with an equal key already exists (per [`key_compare`](key_compare.md)),
|
||||||
|
appending it at the end to preserve insertion order. If an equal key already exists, does nothing.
|
||||||
|
2. Same as (1), but for any `KeyType` comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
(heterogeneous lookup). Only participates in overload resolution if `KeyType` is usable as a key type.
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`KeyType`
|
||||||
|
: a type comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`key` (in)
|
||||||
|
: key of the element to insert
|
||||||
|
|
||||||
|
`t` (in)
|
||||||
|
: value of the element to insert
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
pair of an iterator to the (possibly newly inserted) element, and a `bool` that is `true` if insertion
|
||||||
|
took place and `false` if an element with an equal key already existed
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the number of elements.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how `emplace` is used.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/ordered_map__emplace.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/ordered_map__emplace.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
|
- Overload (2) added in version 3.11.0.
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>erase
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
size_type erase(const key_type& key);
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
template<class KeyType>
|
||||||
|
size_type erase(KeyType&& key);
|
||||||
|
|
||||||
|
// (3)
|
||||||
|
iterator erase(iterator pos);
|
||||||
|
|
||||||
|
// (4)
|
||||||
|
iterator erase(iterator first, iterator last);
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Removes the element with key equal to `key`, if any, preserving the relative order of the remaining
|
||||||
|
elements.
|
||||||
|
2. Same as (1), but for any `KeyType` comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
(heterogeneous lookup). Only participates in overload resolution if `KeyType` is usable as a key type.
|
||||||
|
3. Removes the element at `pos`.
|
||||||
|
4. Removes the elements in range `[first, last)`.
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`KeyType`
|
||||||
|
: a type comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`key` (in)
|
||||||
|
: key of the element to remove
|
||||||
|
|
||||||
|
`pos` (in)
|
||||||
|
: iterator to the element to remove
|
||||||
|
|
||||||
|
`first` (in)
|
||||||
|
: iterator to the first element to remove
|
||||||
|
|
||||||
|
`last` (in)
|
||||||
|
: iterator one past the last element to remove
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
1. number of elements removed (0 or 1)
|
||||||
|
2. number of elements removed (0 or 1)
|
||||||
|
3. iterator following the removed element
|
||||||
|
4. iterator following the last removed element
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the number of elements (elements after the removed one(s) are shifted to keep storage
|
||||||
|
contiguous).
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how `erase` is used.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/ordered_map__erase.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/ordered_map__erase.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
|
- Overload (2) added in version 3.11.0.
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>find
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
iterator find(const key_type& key);
|
||||||
|
const_iterator find(const key_type& key) const;
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
template<class KeyType>
|
||||||
|
iterator find(KeyType&& key);
|
||||||
|
template<class KeyType>
|
||||||
|
const_iterator find(KeyType&& key) const;
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Returns an iterator to the element with key equal to `key`, or `end()` if no such element exists.
|
||||||
|
2. Same as (1), but for any `KeyType` comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
(heterogeneous lookup). Only participates in overload resolution if `KeyType` is usable as a key type.
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`KeyType`
|
||||||
|
: a type comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`key` (in)
|
||||||
|
: key of the element to find
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
iterator to the element with key equal to `key`, or `end()` if not found
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the number of elements.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how `find` is used.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/ordered_map__find.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/ordered_map__find.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.1 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
|
- Overload (2) added in version 3.11.0.
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
# <small>nlohmann::</small>ordered_map
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
template<class Key, class T, class IgnoredLess = std::less<Key>,
|
||||||
|
class Allocator = std::allocator<std::pair<const Key, T>>>
|
||||||
|
struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>;
|
||||||
|
```
|
||||||
|
|
||||||
|
A minimal map-like container that preserves insertion order for use within [`nlohmann::ordered_json`](../ordered_json.md)
|
||||||
|
(`nlohmann::basic_json<ordered_map>`).
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`Key`
|
||||||
|
: key type
|
||||||
|
|
||||||
|
`T`
|
||||||
|
: mapped type
|
||||||
|
|
||||||
|
`IgnoredLess`
|
||||||
|
: comparison function (ignored and only added to ensure compatibility with `#!cpp std::map`)
|
||||||
|
|
||||||
|
`Allocator`
|
||||||
|
: allocator type
|
||||||
|
|
||||||
|
## Iterator invalidation
|
||||||
|
|
||||||
|
The type uses a `std::vector` to store object elements. Therefore, adding elements can yield a reallocation in which
|
||||||
|
case all iterators (including the `end()` iterator) and all references to the elements are invalidated.
|
||||||
|
|
||||||
|
## Member types
|
||||||
|
|
||||||
|
- **key_type** - key type (`Key`)
|
||||||
|
- **mapped_type** - mapped type (`T`)
|
||||||
|
- [**Container**](Container.md) - base container type (`#!cpp std::vector<std::pair<const Key, T>, Allocator>`)
|
||||||
|
- **iterator**
|
||||||
|
- **const_iterator**
|
||||||
|
- **size_type**
|
||||||
|
- **value_type**
|
||||||
|
- [**key_compare**](key_compare.md) - key comparison function
|
||||||
|
```cpp
|
||||||
|
std::equal_to<Key> // until C++14
|
||||||
|
|
||||||
|
std::equal_to<> // since C++14
|
||||||
|
```
|
||||||
|
|
||||||
|
## Member functions
|
||||||
|
|
||||||
|
- [(constructor)](ordered_map.md)
|
||||||
|
- [(destructor)](~ordered_map.md)
|
||||||
|
- [**operator=**](operator=.md)
|
||||||
|
- [**emplace**](emplace.md)
|
||||||
|
- [**operator\[\]**](operator[].md)
|
||||||
|
- [**at**](at.md)
|
||||||
|
- [**erase**](erase.md)
|
||||||
|
- [**count**](count.md)
|
||||||
|
- [**find**](find.md)
|
||||||
|
- [**insert**](insert.md)
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows the different behavior of `std::map` and `nlohmann::ordered_map`.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/ordered_map.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/ordered_map.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [ordered_json](../ordered_json.md)
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
|
- Added **key_compare** member in version 3.11.0.
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>insert
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
std::pair<iterator, bool> insert(value_type&& value);
|
||||||
|
std::pair<iterator, bool> insert(const value_type& value);
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
template<typename InputIt>
|
||||||
|
void insert(InputIt first, InputIt last);
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Inserts `value` if no element with an equal key already exists (per [`key_compare`](key_compare.md)),
|
||||||
|
appending it at the end to preserve insertion order. If an equal key already exists, does nothing.
|
||||||
|
2. Inserts the elements from range `[first, last)`, in iteration order, applying the same equal-key rule
|
||||||
|
as (1) to each element.
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`InputIt`
|
||||||
|
: an input iterator type
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`value` (in)
|
||||||
|
: value to insert
|
||||||
|
|
||||||
|
`first` (in)
|
||||||
|
: iterator to the first element to insert
|
||||||
|
|
||||||
|
`last` (in)
|
||||||
|
: iterator one past the last element to insert
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
1. pair of an iterator to the (possibly newly inserted) element, and a `bool` that is `true` if insertion
|
||||||
|
took place and `false` if an element with an equal key already existed
|
||||||
|
2. (none)
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
1. Linear in the number of elements.
|
||||||
|
2. Linear in the distance between `first` and `last`, times linear in the number of elements.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how `insert` is used.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/ordered_map__insert.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/ordered_map__insert.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.1 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>key_compare
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
using key_compare = std::equal_to<Key>; // until C++14
|
||||||
|
|
||||||
|
using key_compare = std::equal_to<>; // since C++14
|
||||||
|
```
|
||||||
|
|
||||||
|
The comparator used to determine key equality when looking up elements. Unlike `std::map`, `ordered_map`
|
||||||
|
uses linear search with `key_compare` rather than an ordering relation, since element order reflects
|
||||||
|
insertion order rather than key order.
|
||||||
|
|
||||||
|
Since C++14, the transparent `#!cpp std::equal_to<>` is used, which enables heterogeneous lookup (e.g.
|
||||||
|
looking up by a `#!cpp const char*` key without constructing a temporary `Key`).
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how `key_compare` is used.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/ordered_map__key_compare.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/ordered_map__key_compare.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.11.0.
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>operator=
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
ordered_map& operator=(const ordered_map& other);
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
ordered_map& operator=(ordered_map&& other) noexcept(std::is_nothrow_move_assignable<Container>::value);
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Copy assignment operator.
|
||||||
|
2. Move assignment operator.
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`other` (in)
|
||||||
|
: value to assign from
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
`*this`
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
1. Linear in the size of `other`.
|
||||||
|
2. Constant.
|
||||||
|
|
||||||
|
<!-- NOLINT Examples -->
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>operator[]
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
T& operator[](const key_type& key);
|
||||||
|
const T& operator[](const key_type& key) const;
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
template<class KeyType>
|
||||||
|
T& operator[](KeyType&& key);
|
||||||
|
template<class KeyType>
|
||||||
|
const T& operator[](KeyType&& key) const;
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Returns a reference to the value mapped to `key`, inserting a default-constructed `T` (non-`const`
|
||||||
|
overload only) if no such element exists yet.
|
||||||
|
2. Same as (1), but for any `KeyType` comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
(heterogeneous lookup). Only participates in overload resolution if `KeyType` is usable as a key type.
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`KeyType`
|
||||||
|
: a type comparable to `key_type` via [`key_compare`](key_compare.md)
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`key` (in)
|
||||||
|
: key of the element to find or insert
|
||||||
|
|
||||||
|
## Return value
|
||||||
|
|
||||||
|
reference to the mapped value of the element with key equal to `key`
|
||||||
|
|
||||||
|
## Exceptions
|
||||||
|
|
||||||
|
The `const` overloads throw `std::out_of_range` if no element with key `key` exists (they delegate to
|
||||||
|
[`at`](at.md)).
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the number of elements.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example shows how `operator[]` is used.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/ordered_map__operator_idx.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```
|
||||||
|
--8<-- "examples/ordered_map__operator_idx.output"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
|
- Overload (2) added in version 3.11.0.
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>ordered_map
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// (1)
|
||||||
|
ordered_map() noexcept(noexcept(Container()));
|
||||||
|
|
||||||
|
// (2)
|
||||||
|
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc)));
|
||||||
|
|
||||||
|
// (3)
|
||||||
|
template <class It>
|
||||||
|
ordered_map(It first, It last, const Allocator& alloc = Allocator());
|
||||||
|
|
||||||
|
// (4)
|
||||||
|
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator());
|
||||||
|
|
||||||
|
// (5)
|
||||||
|
ordered_map(const ordered_map&) = default;
|
||||||
|
|
||||||
|
// (6)
|
||||||
|
ordered_map(ordered_map&&) noexcept(std::is_nothrow_move_constructible<Container>::value) = default;
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Default constructor. Creates an empty `ordered_map`.
|
||||||
|
2. Creates an empty `ordered_map` using the given allocator.
|
||||||
|
3. Creates an `ordered_map` from the elements in range `[first, last)`, inserted in iteration order.
|
||||||
|
4. Creates an `ordered_map` from an initializer list of key/value pairs, inserted in list order.
|
||||||
|
5. Copy constructor.
|
||||||
|
6. Move constructor.
|
||||||
|
|
||||||
|
These constructors are declared explicitly (rather than inherited via `#!cpp using Container::Container`)
|
||||||
|
because older compilers (GCC <= 5.5, Xcode <= 9.4) do not handle the inherited constructors correctly.
|
||||||
|
|
||||||
|
## Template parameters
|
||||||
|
|
||||||
|
`It`
|
||||||
|
: an input iterator type
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`alloc` (in)
|
||||||
|
: allocator to use for the underlying container
|
||||||
|
|
||||||
|
`first` (in)
|
||||||
|
: iterator to the first element to insert
|
||||||
|
|
||||||
|
`last` (in)
|
||||||
|
: iterator one past the last element to insert
|
||||||
|
|
||||||
|
`init` (in)
|
||||||
|
: initializer list of key/value pairs to insert
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
1. Constant.
|
||||||
|
2. Constant.
|
||||||
|
3. Linear in the distance between `first` and `last`.
|
||||||
|
4. Linear in the size of `init`.
|
||||||
|
5. Linear in the size of `other`.
|
||||||
|
6. Constant.
|
||||||
|
|
||||||
|
<!-- NOLINT Examples -->
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# <small>nlohmann::ordered_map::</small>~ordered_map
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
~ordered_map() = default;
|
||||||
|
```
|
||||||
|
|
||||||
|
Destroys the `ordered_map` and frees all allocated memory.
|
||||||
|
|
||||||
|
## Complexity
|
||||||
|
|
||||||
|
Linear in the number of elements.
|
||||||
|
|
||||||
|
<!-- NOLINT Examples -->
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
# Ecosystem
|
|
||||||
|
|
||||||
The projects below build on top of `nlohmann::json` rather than merely using it - schema validators, language
|
|
||||||
bindings, format converters, and similar building blocks. The list is not exhaustive, and is curated rather than
|
|
||||||
automatically generated. If you maintain or know of a project that belongs here,
|
|
||||||
[please let me know](mailto:mail@nlohmann.me).
|
|
||||||
|
|
||||||
For products, applications, and organizations that use the library, see [Customers](../home/customers.md) instead.
|
|
||||||
|
|
||||||
## Schema validation
|
|
||||||
|
|
||||||
- [**json-schema-validator**](https://github.com/pboettch/json-schema-validator), a JSON Schema (draft 7) validator
|
|
||||||
with human-readable error messages
|
|
||||||
|
|
||||||
## Serialization and reflection
|
|
||||||
|
|
||||||
- [**nlohmann_json_reflect**](https://github.com/1261385937/nlohmann_json_reflect), a reflection extension for
|
|
||||||
(de)serializing nested containers-in-structs-in-containers
|
|
||||||
|
|
||||||
## Encodings
|
|
||||||
|
|
||||||
- [**base-encode-decode**](https://github.com/saxonnicholls/base-encode-decode), a header-only Base64/32/16/8/4/2
|
|
||||||
(and DNA/RNA) encoding library, with an adapter that serializes binary data through `nlohmann::json`
|
|
||||||
|
|
||||||
## Language bindings and interop
|
|
||||||
|
|
||||||
- [**pybind11_json**](https://github.com/pybind/pybind11_json), a bidirectional type caster between
|
|
||||||
`nlohmann::json` and Python objects for [pybind11](https://github.com/pybind/pybind11) bindings
|
|
||||||
- [**nanobind_json**](https://github.com/ianhbell/nanobind_json), the same idea for
|
|
||||||
[nanobind](https://github.com/wjakob/nanobind) bindings
|
|
||||||
- [**nlohmann_json_qt**](https://github.com/dpurgin/nlohmann_json_qt), deserialization helpers for Qt types
|
|
||||||
(`QString`, `QUrl`, `QDateTime`, `QVector`, ...) from `nlohmann::json`
|
|
||||||
- [**vulkan2json**](https://github.com/Fadis/vulkan2json), serialization and deserialization of Vulkan API structs
|
|
||||||
|
|
||||||
## Format converters
|
|
||||||
|
|
||||||
- [**tojson**](https://github.com/mircodz/tojson), a header-only converter between YAML/XML documents and
|
|
||||||
`nlohmann::json`
|
|
||||||
- [**json2xml**](https://github.com/testillano/json2xml), a header-only converter from `nlohmann::json` to XML for
|
|
||||||
simple configuration documents
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
# Community
|
# Community
|
||||||
|
|
||||||
- [Ecosystem](ecosystem.md) - third-party projects built on top of this library
|
|
||||||
- [Code of Conduct](code_of_conduct.md) - the rules and norms of this project
|
- [Code of Conduct](code_of_conduct.md) - the rules and norms of this project
|
||||||
- [Contribution Guidelines](contribution_guidelines.md) - guidelines how to contribute to this project
|
- [Contribution Guidelines](contribution_guidelines.md) - guidelines how to contribute to this project
|
||||||
- [Governance](governance.md) - the governance model of this project
|
- [Governance](governance.md) - the governance model of this project
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ Note: Some modern features (like C++20 ranges or filesystem support) may be disa
|
|||||||
| Clang 20.1.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 20.1.1 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 20.1.8 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
| Clang 20.1.8 with GNU-like command-line | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
|
||||||
| Clang 21.1.8 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| Clang 21.1.8 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| Clang 22.1.8 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
|
||||||
| CUDA 11.8.0 (nvcc) | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
| CUDA 11.8.0 (nvcc) | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
||||||
| CUDA 12.1.1 (nvcc) | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
| CUDA 12.1.1 (nvcc) | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
||||||
| CUDA 12.6.3 (nvcc) | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
| CUDA 12.6.3 (nvcc) | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// an empty binary value is encoded differently by the two drafts:
|
||||||
|
// draft2 omits the optimized type marker for an empty byte array,
|
||||||
|
// while draft3 always writes it
|
||||||
|
json j = json::binary({});
|
||||||
|
|
||||||
|
// encode using BJData draft2 (the default)
|
||||||
|
auto v_draft2 = json::to_bjdata(j, true, true, json::bjdata_version_t::draft2);
|
||||||
|
|
||||||
|
// encode using BJData draft3
|
||||||
|
auto v_draft3 = json::to_bjdata(j, true, true, json::bjdata_version_t::draft3);
|
||||||
|
|
||||||
|
std::cout << "draft2 size: " << v_draft2.size() << '\n'
|
||||||
|
<< "draft3 size: " << v_draft3.size() << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
draft2 size: 4
|
||||||
|
draft3 size: 6
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using byte_container_with_subtype = nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>>;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< std::is_same<byte_container_with_subtype::container_type, std::vector<std::uint8_t>>::value
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
true
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using byte_container_with_subtype = nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>>;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
byte_container_with_subtype c1({0xca, 0xfe});
|
||||||
|
byte_container_with_subtype c2({0xca, 0xfe});
|
||||||
|
byte_container_with_subtype c3({0xca, 0xfe}, 42);
|
||||||
|
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< "c1 == c2: " << (c1 == c2) << '\n'
|
||||||
|
<< "c1 == c3: " << (c1 == c3) << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
c1 == c2: true
|
||||||
|
c1 == c3: false
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using byte_container_with_subtype = nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>>;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
byte_container_with_subtype c1({0xca, 0xfe});
|
||||||
|
byte_container_with_subtype c2({0xca, 0xfe});
|
||||||
|
byte_container_with_subtype c3({0xca, 0xfe}, 42);
|
||||||
|
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< "c1 != c2: " << (c1 != c2) << '\n'
|
||||||
|
<< "c1 != c3: " << (c1 != c3) << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
c1 != c2: false
|
||||||
|
c1 != c3: true
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using byte_container_with_subtype = nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>>;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< std::is_same<byte_container_with_subtype::subtype_type, std::uint64_t>::value << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
true
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// an initializer_list_t is what a braced-init-list of JSON values is deduced as
|
||||||
|
json::initializer_list_t init = {"a", 1, 2.0, false};
|
||||||
|
|
||||||
|
json j(init);
|
||||||
|
std::cout << j.dump() << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
["a",1,2.0,false]
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< std::is_same<json::json_sax_t::binary_t, json::binary_t>::value << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
true
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< std::is_same<json::json_sax_t::number_float_t, json::number_float_t>::value << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
true
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< std::is_same<json::json_sax_t::number_integer_t, json::number_integer_t>::value << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
true
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< std::is_same<json::json_sax_t::number_unsigned_t, json::number_unsigned_t>::value << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
true
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< std::is_same<json::json_sax_t::string_t, json::string_t>::value << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
true
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< std::is_same<json::json_sax_t, nlohmann::json_sax<json>>::value << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
true
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using Map = nlohmann::ordered_map<std::string, int>;
|
||||||
|
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< "Container is std::vector<std::pair<const Key, T>>: "
|
||||||
|
<< std::is_same<Map::Container, std::vector<std::pair<const std::string, int>>>::value
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Container is std::vector<std::pair<const Key, T>>: true
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
nlohmann::ordered_map<std::string, int> m;
|
||||||
|
m["one"] = 1;
|
||||||
|
m["two"] = 2;
|
||||||
|
|
||||||
|
// access an existing element
|
||||||
|
std::cout << "m.at(\"one\") = " << m.at("one") << std::endl;
|
||||||
|
|
||||||
|
// modify through the reference returned by at()
|
||||||
|
m.at("two") = 22;
|
||||||
|
std::cout << "m.at(\"two\") = " << m.at("two") << std::endl;
|
||||||
|
|
||||||
|
// accessing a missing key throws
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m.at("three");
|
||||||
|
}
|
||||||
|
catch (const std::out_of_range& e)
|
||||||
|
{
|
||||||
|
std::cout << "exception: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
m.at("one") = 1
|
||||||
|
m.at("two") = 22
|
||||||
|
exception: key not found
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
nlohmann::ordered_map<std::string, int> m;
|
||||||
|
m["one"] = 1;
|
||||||
|
|
||||||
|
std::cout << std::boolalpha
|
||||||
|
<< "m.count(\"one\") = " << m.count("one") << '\n'
|
||||||
|
<< "m.count(\"two\") = " << m.count("two") << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
m.count("one") = 1
|
||||||
|
m.count("two") = 0
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
nlohmann::ordered_map<std::string, std::string> m;
|
||||||
|
|
||||||
|
// emplace a new element
|
||||||
|
auto res1 = m.emplace("one", "eins");
|
||||||
|
std::cout << std::boolalpha << "inserted: " << res1.second << ", value: " << res1.first->second << std::endl;
|
||||||
|
|
||||||
|
// emplace with an already-existing key: no-op, returns the existing element
|
||||||
|
auto res2 = m.emplace("one", "uno");
|
||||||
|
std::cout << std::boolalpha << "inserted: " << res2.second << ", value: " << res2.first->second << std::endl;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user