mirror of
https://github.com/nlohmann/json.git
synced 2026-07-11 21:15:10 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 10d18792bd | |||
| 8557b661ab | |||
| 48face7a20 | |||
| 68c87ad9de |
@@ -1,81 +0,0 @@
|
||||
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
|
||||
@@ -33,21 +33,11 @@ jobs:
|
||||
|
||||
ci_infer:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: Install Infer
|
||||
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
|
||||
sudo ln -s /opt/infer-linux-x86_64-v1.3.0/bin/infer /usr/local/bin/infer
|
||||
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
@@ -153,30 +143,11 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
compiler: ['4.8', '4.9', '5', '6']
|
||||
# official gcc:4.8/4.9/5/6 images fail to check out code (too old for
|
||||
# actions/checkout); install the old compilers on top of official ubuntu:20.04
|
||||
# instead, mirroring what the (now retired) custom json-ci image did.
|
||||
container: ubuntu:20.04
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
steps:
|
||||
- name: Install g++-${{ matrix.compiler }}
|
||||
run: |
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends software-properties-common ca-certificates gnupg make git
|
||||
add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
||||
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/ xenial main"
|
||||
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial universe"
|
||||
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial-updates main"
|
||||
apt-add-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial-updates universe"
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends g++-${{ matrix.compiler }}
|
||||
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||
- name: Run CMake
|
||||
run: CXX=g++-${{ matrix.compiler }} cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
@@ -263,22 +234,11 @@ jobs:
|
||||
|
||||
ci_cuda_example:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# 11.8.0: newest pre-C++20 CUDA release, exercises the C++17 fallback
|
||||
# path (tests/cuda_example/CMakeLists.txt picks the standard per nvcc
|
||||
# version); 12.1.1: permanent regression guard for #3907 (nvcc 12.0/12.1
|
||||
# choke on enable_borrowed_range at C++20, fixed in 12.2); 12.6.3: recent
|
||||
# CUDA/C++20 coverage.
|
||||
cuda: ['11.8.0', '12.1.1', '12.6.3']
|
||||
container: nvidia/cuda:${{ matrix.cuda }}-devel-ubuntu22.04
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
steps:
|
||||
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
@@ -316,22 +276,17 @@ jobs:
|
||||
|
||||
ci_icpc:
|
||||
runs-on: ubuntu-latest
|
||||
# Intel discontinued the classic icc/icpc compiler in oneAPI 2024.0; this is
|
||||
# Intel's own last officially published image that still includes it.
|
||||
container: intel/oneapi-hpckit:2023.2.1-devel-ubuntu22.04
|
||||
container: ghcr.io/nlohmann/json-ci:v2.2.0
|
||||
steps:
|
||||
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Get latest CMake and ninja
|
||||
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
# No need to source setvars.sh here: unlike the old custom image, this
|
||||
# official image already has the oneAPI environment (icc/icpc on PATH)
|
||||
# baked in, and re-sourcing it fails with "already been run" (exit 3).
|
||||
run: cmake --build build --target ci_icpc
|
||||
run: |
|
||||
. /opt/intel/oneapi/setvars.sh
|
||||
cmake --build build --target ci_icpc
|
||||
|
||||
ci_icpx:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*.gcno
|
||||
*.gcda
|
||||
.DS_Store
|
||||
__pycache__/
|
||||
|
||||
/.idea
|
||||
/cmake-build-*
|
||||
@@ -44,9 +43,5 @@ venv
|
||||
|
||||
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
|
||||
MODULE.bazel.lock
|
||||
|
||||
@@ -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).
|
||||
|
||||
: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.
|
||||
: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.
|
||||
|
||||
: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.
|
||||
|
||||
|
||||
+2
-6
@@ -669,6 +669,7 @@ add_custom_target(ci_test_compiler_default
|
||||
add_custom_target(ci_cuda_example
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DCMAKE_CUDA_HOST_COMPILER=g++-8
|
||||
-S${PROJECT_SOURCE_DIR}/tests/cuda_example -B${PROJECT_BINARY_DIR}/build_cuda_example
|
||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_cuda_example
|
||||
)
|
||||
@@ -719,11 +720,6 @@ add_custom_target(ci_icpx
|
||||
# to zero and does not honor NaN ordering; -Kieee restores strict IEEE 754 behavior
|
||||
# (needed for the dtoa/grisu and NaN-comparison code paths).
|
||||
#
|
||||
# -tp=px pins the target processor to the generic x86-64 baseline (SSE2-only) to avoid
|
||||
# a nvc++ 25.5 / LLVM issue: when nvc++ auto-detects -tp from the runner's CPU (e.g. -tp znver4),
|
||||
# certain attribute combinations trigger an llc instruction-selection crash on std::ldexp<unsigned>.
|
||||
# Pinning to px removes this variability and is robust to future llc/nvc++ updates.
|
||||
#
|
||||
# The following tests are excluded as they trigger known nvc++ 25.5 defects (not
|
||||
# library bugs); see https://github.com/nlohmann/json for tracking. Only the
|
||||
# affected language-standard variants are excluded so coverage is otherwise kept:
|
||||
@@ -737,7 +733,7 @@ add_custom_target(ci_nvhpc
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||
-DCMAKE_C_COMPILER=nvc -DCMAKE_CXX_COMPILER=nvc++
|
||||
-DCMAKE_CXX_FLAGS="-Kieee;-tp=px"
|
||||
-DCMAKE_CXX_FLAGS=-Kieee
|
||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_nvhpc
|
||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_nvhpc
|
||||
|
||||
@@ -5,11 +5,8 @@
|
||||
# -Wno-extra-semi-stmt The library uses assert which triggers this warning.
|
||||
# -Wno-padded We do not care about padding warnings.
|
||||
# -Wno-covered-switch-default All switches list all cases and a default case.
|
||||
# -Wno-unsafe-buffer-usage Pervasive: the library's own low-level numeric/buffer code
|
||||
# (to_chars, serializer, lexer, binary reader/writer, input
|
||||
# adapters, json_pointer) plus vendored Doctest itself (~208
|
||||
# distinct sites measured 2026-07-08 on clang trunk) all use
|
||||
# raw pointer arithmetic / libc string calls by necessity.
|
||||
# -Wno-unsafe-buffer-usage Otherwise Doctest would not compile.
|
||||
# -Wno-missing-noreturn We found no way to silence this warning otherwise, see PR #4871
|
||||
|
||||
set(CLANG_CXXFLAGS
|
||||
-Werror
|
||||
@@ -21,4 +18,5 @@ set(CLANG_CXXFLAGS
|
||||
-Wno-padded
|
||||
-Wno-covered-switch-default
|
||||
-Wno-unsafe-buffer-usage
|
||||
-Wno-missing-noreturn
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"archive": "JSON_for_Modern_C++.tgz",
|
||||
"author": {
|
||||
"name": "Niels Lohmann",
|
||||
"link": "https://nlohmann.me"
|
||||
"link": "https://twitter.com/nlohmann"
|
||||
},
|
||||
"aliases": ["nlohmann/json"]
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ Unlike the [`parse()`](parse.md) function, this function neither throws an excep
|
||||
- a C-style array of characters
|
||||
- a pointer to a null-terminated string of single byte characters (throws if null)
|
||||
- a `std::string`
|
||||
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
||||
|
||||
`IteratorType`
|
||||
: a compatible iterator type, for instance.
|
||||
@@ -110,8 +109,7 @@ A UTF-8 byte order mark is silently ignored.
|
||||
- Added in version 3.0.0.
|
||||
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
||||
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
|
||||
- Added `ignore_trailing_commas` in version 3.13.0.
|
||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||
- Added `ignore_trailing_commas` in version 3.12.x.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
|
||||
@@ -115,22 +115,7 @@ basic_json(basic_json&& other) noexcept;
|
||||
|
||||
Function [`array()`](array.md) and [`object()`](object.md) force array and object creation from initializer lists,
|
||||
respectively.
|
||||
|
||||
!!! warning "Brace initialization yields arrays"
|
||||
|
||||
Because this constructor takes an `initializer_list_t`, brace-initializing a `json`/`ordered_json` from
|
||||
another `json` value wraps it in a single-element array rather than copying it:
|
||||
|
||||
```cpp
|
||||
json j1 = "hello";
|
||||
json j2{j1}; // [!] j2 is ["hello"], NOT a copy of j1
|
||||
json j3(j1); // j3 is "hello" -- parentheses copy as expected
|
||||
```
|
||||
|
||||
See the FAQ entry on [brace initialization](../../home/faq.md#brace-initialization-yields-arrays) for the
|
||||
full explanation, an opt-in macro to change this behavior, and how to explicitly create a single-element
|
||||
array (`json::array({value})`) if that is what you want.
|
||||
|
||||
|
||||
6. Constructs a JSON array value by creating `cnt` copies of a passed value. In case `cnt` is `0`, an empty array is
|
||||
created.
|
||||
|
||||
@@ -420,9 +405,7 @@ basic_json(basic_json&& other) noexcept;
|
||||
1. Since version 1.0.0.
|
||||
2. Since version 1.0.0.
|
||||
3. Since version 2.1.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.
|
||||
4. Since version 3.2.0.
|
||||
5. Since version 1.0.0.
|
||||
6. Since version 1.0.0.
|
||||
7. Since version 1.0.0.
|
||||
|
||||
@@ -37,14 +37,6 @@ represent a byte array in modern C++.
|
||||
`BinaryType`
|
||||
: container type to store arrays
|
||||
|
||||
Although not formally expressed as a C++ concept, `BinaryType` must be default-constructible,
|
||||
copy/move-constructible, and support `push_back()`, `.data()`, and `.size()`, because
|
||||
[`byte_container_with_subtype`](../byte_container_with_subtype/index.md) derives directly from it. Its
|
||||
`value_type` must additionally be exactly one byte wide (e.g., `std::uint8_t`/`char`/`std::byte`): the binary
|
||||
serializers (CBOR, MessagePack, BSON, UBJSON) read and write the container's raw bytes via
|
||||
`reinterpret_cast`, which is only correct for byte-sized elements -- a container like
|
||||
`#!cpp std::vector<std::intptr_t>` will not work as `BinaryType`.
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
# <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.
|
||||
@@ -92,4 +92,4 @@ std::string format_as(const BasicJsonType& j)
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.13.0.
|
||||
- Added in version 3.12.x.
|
||||
|
||||
@@ -29,8 +29,7 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
||||
- a `FILE` pointer
|
||||
- a C-style array of characters
|
||||
- a pointer to a null-terminated string of single byte characters
|
||||
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
||||
|
||||
`IteratorType`
|
||||
: a compatible iterator type
|
||||
@@ -102,4 +101,3 @@ Linear in the size of the input.
|
||||
## Version history
|
||||
|
||||
- Added in version 3.11.0.
|
||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||
|
||||
@@ -29,8 +29,7 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
||||
- a `FILE` pointer
|
||||
- a C-style array of characters
|
||||
- a pointer to a null-terminated string of single byte characters
|
||||
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
||||
|
||||
`IteratorType`
|
||||
: a compatible iterator type
|
||||
@@ -102,7 +101,6 @@ Linear in the size of the input.
|
||||
## Version history
|
||||
|
||||
- Added in version 3.4.0.
|
||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
||||
- a `FILE` pointer
|
||||
- a C-style array of characters
|
||||
- a pointer to a null-terminated string of single byte characters
|
||||
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
||||
|
||||
`IteratorType`
|
||||
: a compatible iterator type
|
||||
@@ -112,7 +111,6 @@ Linear in the size of the input.
|
||||
- Changed to consume input adapters, removed `start_index` parameter, and added `strict` parameter in version 3.0.0.
|
||||
- Added `allow_exceptions` parameter in version 3.2.0.
|
||||
- Added `tag_handler` parameter in version 3.9.0.
|
||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
||||
- a `FILE` pointer
|
||||
- a C-style array of characters
|
||||
- a pointer to a null-terminated string of single byte characters
|
||||
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
||||
|
||||
`IteratorType`
|
||||
: a compatible iterator type
|
||||
@@ -104,7 +103,6 @@ Linear in the size of the input.
|
||||
- Parameter `start_index` since version 2.1.1.
|
||||
- Changed to consume input adapters, removed `start_index` parameter, and added `strict` parameter in version 3.0.0.
|
||||
- Added `allow_exceptions` parameter in version 3.2.0.
|
||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
||||
- a `FILE` pointer
|
||||
- a C-style array of characters
|
||||
- a pointer to a null-terminated string of single byte characters
|
||||
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
||||
|
||||
`IteratorType`
|
||||
: a compatible iterator type
|
||||
@@ -103,7 +102,6 @@ Linear in the size of the input.
|
||||
|
||||
- Added in version 3.1.0.
|
||||
- Added `allow_exceptions` parameter in version 3.2.0.
|
||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
|
||||
@@ -114,13 +114,6 @@ overload (3).
|
||||
See [Number conversion](../../features/types/number_handling.md#number-conversion)
|
||||
for more information.
|
||||
|
||||
!!! note "`std::optional` conversions"
|
||||
|
||||
Prior to version 3.13.0, `#!cpp get<std::optional<T>>()` (and other conversions to `std::optional<T>`) failed to
|
||||
compile in every configuration, due to an internal implementation bug that made the `from_json` overload for
|
||||
`std::optional` unreachable regardless of the [`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md)
|
||||
setting. This has been fixed.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
# <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.
|
||||
@@ -46,17 +46,6 @@ for (auto& [key, val] : j_object.items())
|
||||
}
|
||||
```
|
||||
|
||||
If you need to name the type of the dereferenced element explicitly (e.g., to write a standalone function that
|
||||
takes it as a parameter, or to use `items()` with `std::for_each`), use `decltype`:
|
||||
|
||||
```cpp
|
||||
using element_type = decltype(*j_object.items().begin());
|
||||
```
|
||||
|
||||
The per-element type (`iteration_proxy_value`) lives in the library's internal `detail` namespace and is
|
||||
intentionally unspecified as a stable, named type -- `decltype` is the supported way to obtain it, but its exact
|
||||
name/definition may change between versions.
|
||||
|
||||
## Return value
|
||||
|
||||
iteration proxy object wrapping the current value with an interface to use in range-based for loops
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
# <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.
|
||||
@@ -63,8 +63,7 @@ behavior:
|
||||
object will agree on the name-value mappings.
|
||||
- When the names within an object are not unique, it is unspecified which one of the values for a given key will be
|
||||
chosen. For instance, `#!json {"key": 2, "key": 1}` could be equal to either `#!json {"key": 1}` or
|
||||
`#!json {"key": 2}`. To reject duplicate keys instead of silently resolving them one way or another, see
|
||||
[this parsing recipe](../../features/parsing/parser_callbacks.md#recipe-rejecting-duplicate-object-keys).
|
||||
`#!json {"key": 2}`.
|
||||
- Internally, name/value pairs are stored in lexicographical order of the names. Objects will also be serialized (see
|
||||
[`dump`](dump.md)) in this order. For instance, `#!json {"b": 1, "a": 2}` and `#!json {"a": 2, "b": 1}` will be stored
|
||||
and serialized as `#!json {"a": 2, "b": 1}`.
|
||||
|
||||
@@ -51,5 +51,3 @@ Linear.
|
||||
## Version history
|
||||
|
||||
- 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.
|
||||
|
||||
@@ -124,15 +124,6 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
||||
filled with `#!json null`.
|
||||
- The special value `-` is treated as a synonym for the index past the end.
|
||||
|
||||
!!! note "Creating intermediate levels that don't exist yet"
|
||||
|
||||
When the JSON pointer traverses intermediate levels that don't exist at all yet (not just a missing
|
||||
leaf), each missing level is created as an array or an object depending on whether the corresponding
|
||||
pointer token parses as a non-negative integer: a numeric token creates an array, a non-numeric token
|
||||
creates an object. For example, on an initially `#!json null` value, `/foo/0/0/0` creates nested arrays,
|
||||
while `/foo/one/one/one` creates nested objects. This is not specified by the JSON Pointer RFC; it is
|
||||
this library's own, intentional disambiguation rule. See also [JSON Pointer](../../features/json_pointer.md).
|
||||
|
||||
## Examples
|
||||
|
||||
??? example "Example: (1) access specified array element"
|
||||
@@ -260,6 +251,5 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
||||
1. Added in version 1.0.0.
|
||||
2. Added in version 1.0.0. Added overloads for `T* key` in version 1.1.0. Removed overloads for `T* key` (replaced by 3)
|
||||
in version 3.11.0.
|
||||
3. Added in version 3.11.0. Fixed in version 3.13.0 to consistently accept `std::string_view`-convertible keys, as
|
||||
already supported by [`at`](at.md), [`value`](value.md), [`find`](find.md), and other lookup functions.
|
||||
3. Added in version 3.11.0.
|
||||
4. Added in version 2.0.0.
|
||||
|
||||
@@ -85,8 +85,3 @@ Linear in the size of the JSON value.
|
||||
- Since version 1.0.0.
|
||||
- Macros `JSON_EXPLICIT`/[`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md) added
|
||||
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)).
|
||||
|
||||
@@ -19,8 +19,10 @@ class basic_json {
|
||||
};
|
||||
```
|
||||
|
||||
1. Compares two JSON values for inequality. Returns `#!cpp !(lhs == rhs)` (until C++20) or `#!cpp !(*this == rhs)` (since C++20).
|
||||
- This means the comparison is simply the logical negation of `operator==`, including for special values like `NaN` and `discarded`.
|
||||
1. Compares two JSON values for inequality according to the following rules:
|
||||
- The comparison always yields `#!cpp false` if (1) either operand is discarded, or (2) either operand is `NaN` and
|
||||
the other operand is either `NaN` or any other number.
|
||||
- Otherwise, returns the result of `#!cpp !(lhs == rhs)` (until C++20) or `#!cpp !(*this == rhs)` (since C++20).
|
||||
|
||||
2. Compares a JSON value and a scalar or a scalar and a JSON value for inequality by converting the scalar to a JSON
|
||||
value and comparing both JSON values according to 1.
|
||||
@@ -52,12 +54,13 @@ Linear.
|
||||
|
||||
## Notes
|
||||
|
||||
!!! note "Comparing `NaN` and `discarded`"
|
||||
!!! note "Comparing `NaN`"
|
||||
|
||||
Since `operator!=` is defined as `!(a == b)`, the behavior for special values follows that of `operator==`:
|
||||
|
||||
- For `NaN` values: `NaN == NaN` yields `#!cpp false`, so `NaN != NaN` yields `#!cpp true`.
|
||||
- For `discarded` values: `discarded == x` yields `#!cpp false` for any `x`, so `discarded != x` yields `#!cpp true`.
|
||||
`NaN` values are unordered within the domain of numbers.
|
||||
The following comparisons all yield `#!cpp false`:
|
||||
1. Comparing a `NaN` with itself.
|
||||
2. Comparing a `NaN` with another `NaN`.
|
||||
3. Comparing a `NaN` and any other number.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -91,7 +94,5 @@ Linear.
|
||||
|
||||
## Version history
|
||||
|
||||
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. Changed in version 3.13.0 to remove
|
||||
special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`.
|
||||
2. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. Changed in version 3.13.0 to remove
|
||||
special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`.
|
||||
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0.
|
||||
2. Added in version 1.0.0. Added C++20 member functions in version 3.11.0.
|
||||
|
||||
@@ -34,8 +34,7 @@ static basic_json parse(IteratorType first, IteratorType last,
|
||||
- a C-style array of characters
|
||||
- a pointer to a null-terminated string of single byte characters (throws if null)
|
||||
- a `std::string`
|
||||
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
||||
|
||||
`IteratorType`
|
||||
: a compatible iterator type, for instance.
|
||||
@@ -236,8 +235,7 @@ Invalid Unicode escapes and unpaired surrogates in the input are reported as
|
||||
- Overload for contiguous containers (1) added in version 2.0.3.
|
||||
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
||||
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
|
||||
- Added `ignore_trailing_commas` in version 3.13.0.
|
||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||
- Added `ignore_trailing_commas` in version 3.12.x.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
|
||||
@@ -74,4 +74,4 @@ is thrown. In any case, the original value is not changed: the patch is applied
|
||||
|
||||
- Added in version 2.0.0.
|
||||
- Added [`out_of_range.411`](../../home/exceptions.md#jsonexceptionout_of_range411) and stopped relying on an internal assertion when an "add" operation's
|
||||
target location has a non-object/non-array parent in version 3.13.0.
|
||||
target location has a non-object/non-array parent in version 3.12.x.
|
||||
|
||||
@@ -71,4 +71,4 @@ function throws an exception.
|
||||
|
||||
- Added in version 3.11.0.
|
||||
- Added [`out_of_range.411`](../../home/exceptions.md#jsonexceptionout_of_range411) and stopped relying on an internal assertion when an "add" operation's
|
||||
target location has a non-object/non-array parent in version 3.13.0.
|
||||
target location has a non-object/non-array parent in version 3.12.x.
|
||||
|
||||
@@ -39,8 +39,8 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index
|
||||
- a `FILE` pointer
|
||||
- a C-style array of characters
|
||||
- a pointer to a null-terminated string of single byte characters
|
||||
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
|
||||
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of
|
||||
iterators.
|
||||
|
||||
`IteratorType`
|
||||
: a compatible iterator type for overload (2); a pair of character iterators whose `value_type` is an integral type
|
||||
@@ -126,8 +126,7 @@ A UTF-8 byte order mark is silently ignored.
|
||||
|
||||
- Added in version 3.2.0.
|
||||
- Ignoring comments via `ignore_comments` added in version 3.9.0.
|
||||
- Added `ignore_trailing_commas` in version 3.13.0.
|
||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||
- Added `ignore_trailing_commas` in version 3.12.x.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
|
||||
@@ -54,4 +54,4 @@ provides `<format>`, controlled by the [`JSON_HAS_STD_FORMAT`](../macros/json_ha
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.13.0.
|
||||
- Added in version 3.12.x.
|
||||
|
||||
@@ -6,9 +6,18 @@ namespace std {
|
||||
}
|
||||
```
|
||||
|
||||
Return a hash value for a JSON object. The hash function tries to rely on `std::hash` where possible. Furthermore, the
|
||||
type of the JSON value is taken into account to have different hash values for `#!json null`, `#!cpp 0`, `#!cpp 0U`, and
|
||||
`#!cpp false`, etc.
|
||||
Return a hash value for a JSON object. The hash function tries to rely on `std::hash` where possible. To satisfy the
|
||||
`std::hash` contract, numeric JSON values that compare equal must hash to the same value. This means:
|
||||
|
||||
- `json(42)`, `json(42u)`, and `json(42.0)` all hash to the same value
|
||||
- `json(0)`, `json(0u)`, and `json(0.0)` all hash to the same value
|
||||
|
||||
Different types hash differently for non-numeric types (e.g., `#!json null`, `#!cpp false`, and strings all have distinct hashes).
|
||||
|
||||
**Edge case:** For very large integers outside the exact representable range of the floating-point type (beyond ~2^53 for
|
||||
typical `double`), the hash values for integer and floating-point values may differ, even if the floating-point value
|
||||
was obtained by casting the integer (due to precision loss). This is a documented limitation arising from how the
|
||||
comparison operator normalizes numeric types.
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
@@ -18,11 +18,6 @@ JSON class into byte-sized characters during deserialization.
|
||||
: the container to store strings (e.g., `std::string`). Note this container is used for keys/names in objects, see
|
||||
[object_t](object_t.md).
|
||||
|
||||
`StringType` must have a `char`-compatible `value_type`: the library relies on UTF-8/`char`-based storage and
|
||||
processing internally, so `std::wstring`, `std::u16string`, and `std::u32string` are **not** valid choices for
|
||||
`StringType`. To work with wide-character data, convert it to/from UTF-8 at the boundary instead -- see the
|
||||
FAQ's [wide string handling](../../home/faq.md#wide-string-handling) section for a conversion recipe.
|
||||
|
||||
## Notes
|
||||
|
||||
#### Default type
|
||||
|
||||
@@ -21,12 +21,6 @@ a string representation of the type ([`value_t`](value_t.md)):
|
||||
| array | `"array"` |
|
||||
| binary | `"binary"` |
|
||||
| discarded | `"discarded"` |
|
||||
| invalid (corrupted value) | `"invalid"` |
|
||||
|
||||
!!! note "The \"invalid\" type"
|
||||
|
||||
The `"invalid"` return value indicates a corrupted JSON value — this can occur if an enum value falls outside the
|
||||
range of valid `value_t` values. This is useful for diagnosing data corruption or internal errors.
|
||||
|
||||
## Exception safety
|
||||
|
||||
@@ -58,4 +52,3 @@ Constant.
|
||||
- Part of the public API version since 2.1.0.
|
||||
- Changed return value to `const char*` and added `noexcept` in version 3.0.0.
|
||||
- Added support for binary type in version 3.8.0.
|
||||
- Added `"invalid"` return value for corrupted JSON values in version 3.13.0.
|
||||
|
||||
@@ -17,8 +17,6 @@ ValueType value(const json_pointer& ptr,
|
||||
const ValueType& default_value) const;
|
||||
```
|
||||
|
||||
This is equivalent to Python's `dict.get(key, default)`.
|
||||
|
||||
1. Returns either a copy of an object's element at the specified key `key` or a given default value if no element with
|
||||
key `key` exists.
|
||||
|
||||
@@ -186,6 +184,4 @@ changes to any JSON value.
|
||||
|
||||
1. Added in version 1.0.0. Changed parameter `default_value` type from `const ValueType&` to `ValueType&&` in version 3.11.0.
|
||||
2. Added in version 3.11.0. Made `ValueType` the first template parameter in version 3.11.2.
|
||||
3. Added in version 2.0.2. Extended to work with arrays in version 3.13.0, including fixing an issue where resolving
|
||||
`ptr` through an array unexpectedly threw `out_of_range` instead of returning the resolved element (or
|
||||
`default_value`, as documented).
|
||||
3. Added in version 2.0.2. Extended to work with arrays in version 3.12.x.
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,45 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,45 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,28 +0,0 @@
|
||||
# <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.
|
||||
@@ -36,4 +36,4 @@ Constant.
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.13.0.
|
||||
- Added in version 3.12.x.
|
||||
|
||||
@@ -32,4 +32,4 @@ Linear in the number of reference tokens in the `json_pointer`.
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.13.0.
|
||||
- Added in version 3.12.x.
|
||||
|
||||
@@ -35,4 +35,4 @@ Linear in the number of reference tokens in the `json_pointer`.
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.13.0.
|
||||
- Added in version 3.12.x.
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,33 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,30 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,30 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,30 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,29 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,30 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,22 +0,0 @@
|
||||
# <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.
|
||||
@@ -92,4 +92,4 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.13.0.
|
||||
- Added in version 3.12.x.
|
||||
|
||||
@@ -44,4 +44,4 @@ The default value is detected based on preprocessor macros such as `#!cpp __cplu
|
||||
|
||||
- Added in version 3.10.5.
|
||||
- Added `JSON_HAS_CPP_23` in version 3.12.0.
|
||||
- Added `JSON_HAS_CPP_26` in version 3.13.0.
|
||||
- Added `JSON_HAS_CPP_26` in version 3.12.x.
|
||||
|
||||
@@ -19,20 +19,6 @@ The default value is detected based on the preprocessor macros `#!cpp __cpp_lib_
|
||||
`#!cpp __cpp_lib_experimental_filesystem`, `#!cpp __has_include(<filesystem>)`, or
|
||||
`#!cpp __has_include(<experimental/filesystem>)`.
|
||||
|
||||
!!! info "Known compiler/stdlib exclusions"
|
||||
|
||||
Even when the feature-test macro indicates filesystem support is available, the library disables it on the following broken toolchains:
|
||||
|
||||
- **MinGW + GCC 8** — disabled entirely (broken `std::filesystem` implementation; [MinGW-w64 bug 737](https://sourceforge.net/p/mingw-w64/bugs/737/))
|
||||
- **GCC (non-Clang) < 8** — disabled (no filesystem support)
|
||||
- **Clang < 7** — disabled (no filesystem support)
|
||||
- **MSVC < 19.14** — disabled (no filesystem support)
|
||||
- **iOS < 13** — disabled (no filesystem support)
|
||||
- **macOS < Catalina (10.15)** — disabled (no filesystem support)
|
||||
|
||||
If `JSON_HAS_FILESYSTEM` or `JSON_HAS_EXPERIMENTAL_FILESYSTEM` is `0` despite `__cpp_lib_filesystem` being defined, one
|
||||
of the exclusions above likely applies to your toolchain.
|
||||
|
||||
## Notes
|
||||
|
||||
- Note that older compilers or older versions of libstdc++ also require the library `stdc++fs` to be linked to for
|
||||
|
||||
@@ -13,20 +13,6 @@ The default value is detected based on the preprocessor macro `#!cpp __cpp_lib_r
|
||||
|
||||
When the macro is not defined, the library will define it to its default value.
|
||||
|
||||
!!! info "Known compiler/stdlib exclusions"
|
||||
|
||||
Even when the feature-test macro `__cpp_lib_ranges` indicates ranges support is available, the library disables it on
|
||||
the following incomplete or broken toolchains:
|
||||
|
||||
- **GCC 11.1.0** — disabled (the shipped `<ranges>` header has a syntax error; [issue #4440](https://github.com/nlohmann/json/issues/4440))
|
||||
- **libstdc++ < 11** — disabled (incomplete C++20 ranges support; [issue #4440](https://github.com/nlohmann/json/issues/4440))
|
||||
- **Clang < 16 with libstdc++** — disabled (incomplete ranges support; [issue #4440](https://github.com/nlohmann/json/issues/4440))
|
||||
- **libc++ < 160000** — disabled (incomplete C++20 ranges support; [issue #4440](https://github.com/nlohmann/json/issues/4440))
|
||||
- **nvcc (CUDA) 12.0.x and 12.1.x** — disabled (the `enable_borrowed_range` variable-template syntax triggers a parse error
|
||||
under these two toolkit versions; fixed in CUDA 12.2; [issue #3907](https://github.com/nlohmann/json/issues/3907))
|
||||
|
||||
If `JSON_HAS_RANGES` is `0` despite `__cpp_lib_ranges` being defined, one of the exclusions above likely applies to your toolchain.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
@@ -38,4 +38,4 @@ When the macro is not defined, the library will define it to its default value.
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.13.0.
|
||||
- Added in version 3.12.x.
|
||||
|
||||
@@ -62,9 +62,6 @@ See the examples below for the concrete generated code.
|
||||
|
||||
- The current implementation is limited to at most 63 member variables. If you want to serialize/deserialize types
|
||||
with more than 63 member variables, you need to define the `to_json`/`from_json` functions manually.
|
||||
- These macros always produce object-style (named-key) JSON, one key per member. There is no macro variant
|
||||
that serializes a struct's members positionally into a JSON array; for that, write `to_json`/`from_json` by
|
||||
hand, building/reading a `json::array()` of the members in order.
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
@@ -63,9 +63,6 @@ See the examples below for the concrete generated code.
|
||||
|
||||
- The current implementation is limited to at most 63 member variables. If you want to serialize/deserialize types
|
||||
with more than 63 member variables, you need to define the `to_json`/`from_json` functions manually.
|
||||
- These macros always produce object-style (named-key) JSON, one key per member. There is no macro variant
|
||||
that serializes a struct's members positionally into a JSON array; for that, write `to_json`/`from_json` by
|
||||
hand, building/reading a `json::array()` of the members in order.
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
@@ -75,4 +75,4 @@ For further information please refer to the corresponding macros without `WITH_N
|
||||
|
||||
## Version history
|
||||
|
||||
1. Added in version 3.13.0.
|
||||
1. Added in version 3.12.x.
|
||||
|
||||
@@ -102,4 +102,4 @@ inline void from_json(const BasicJsonType& j, type& e);
|
||||
|
||||
## Version history
|
||||
|
||||
Added in version 3.13.0.
|
||||
Added in version 3.12.x.
|
||||
|
||||
@@ -33,18 +33,6 @@ A UTF-8 byte order mark is silently ignored.
|
||||
Invalid Unicode escapes and unpaired surrogates in the input are reported as
|
||||
[`parse_error.101`](../home/exceptions.md#jsonexceptionparse_error101) with a detailed message.
|
||||
|
||||
`operator>>` parses exactly one JSON value and leaves the stream positioned right after it, so it can be called
|
||||
repeatedly to read a sequence of concatenated JSON values from the same stream:
|
||||
|
||||
```cpp
|
||||
json j1, j2;
|
||||
input >> j1; // parses the first value, stream now positioned right after it
|
||||
input >> j2; // parses the next value
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
This function replaces function `#!cpp std::istream& operator<<(basic_json& j, std::istream& i)` which has
|
||||
|
||||
@@ -64,4 +64,4 @@ Linear.
|
||||
|
||||
- Added in version 1.0.0.
|
||||
- Moved to namespace `nlohmann::literals::json_literals` in 3.11.0.
|
||||
- Added `char8_t*` overload in 3.13.0.
|
||||
- Added `char8_t*` overload in 3.12.x.
|
||||
|
||||
@@ -63,4 +63,4 @@ Linear.
|
||||
|
||||
- Added in version 2.0.0.
|
||||
- Moved to namespace `nlohmann::literals::json_literals` in 3.11.0.
|
||||
- Added `char8_t*` overload in 3.13.0.
|
||||
- Added `char8_t*` overload in 3.12.x.
|
||||
|
||||
@@ -8,7 +8,7 @@ This type preserves the insertion order of object keys.
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
The type is based on [`ordered_map`](ordered_map/index.md) which in turn uses a `std::vector` to store object elements.
|
||||
The type is based on [`ordered_map`](ordered_map.md) which in turn uses a `std::vector` to store object elements.
|
||||
Therefore, adding object elements can yield a reallocation in which case all iterators (including the
|
||||
[`end()`](basic_json/end.md) iterator) and all references to the elements are invalidated. Also, any iterator or
|
||||
reference after the insertion point will point to the same index, which is now a different value.
|
||||
@@ -31,7 +31,7 @@ reference after the insertion point will point to the same index, which is now a
|
||||
|
||||
## See also
|
||||
|
||||
- [ordered_map](ordered_map/index.md)
|
||||
- [ordered_map](ordered_map.md)
|
||||
- [Object Order](../features/object_order.md)
|
||||
|
||||
## Version history
|
||||
|
||||
@@ -6,7 +6,7 @@ template<class Key, class T, class IgnoredLess = std::less<Key>,
|
||||
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)
|
||||
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
|
||||
@@ -32,12 +32,12 @@ case all iterators (including the `end()` iterator) and all references to the el
|
||||
|
||||
- **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>`)
|
||||
- **Container** - 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
|
||||
- **key_compare** - key comparison function
|
||||
```cpp
|
||||
std::equal_to<Key> // until C++14
|
||||
|
||||
@@ -46,16 +46,15 @@ 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)
|
||||
- (constructor)
|
||||
- (destructor)
|
||||
- **emplace**
|
||||
- **operator\[\]**
|
||||
- **at**
|
||||
- **erase**
|
||||
- **count**
|
||||
- **find**
|
||||
- **insert**
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -75,9 +74,9 @@ std::equal_to<> // since C++14
|
||||
|
||||
## See also
|
||||
|
||||
- [ordered_json](../ordered_json.md)
|
||||
- [ordered_json](ordered_json.md)
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](../ordered_json.md).
|
||||
- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](ordered_json.md).
|
||||
- Added **key_compare** member in version 3.11.0.
|
||||
@@ -1,28 +0,0 @@
|
||||
# <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).
|
||||
@@ -1,61 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,53 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,58 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,75 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,56 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,63 +0,0 @@
|
||||
# <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).
|
||||
@@ -1,34 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,32 +0,0 @@
|
||||
# <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).
|
||||
@@ -1,62 +0,0 @@
|
||||
# <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.
|
||||
@@ -1,66 +0,0 @@
|
||||
# <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).
|
||||
@@ -1,17 +0,0 @@
|
||||
# <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).
|
||||
@@ -10,10 +10,6 @@ violations will result in a failed build.
|
||||
|
||||
Any compiler with complete C++11 support can compile the library without warnings.
|
||||
|
||||
Note: C++20 modules support may hit compiler-specific issues not covered by the general compiler matrix below. See [Modules](../features/modules.md#known-issues) for known issues and workarounds.
|
||||
|
||||
Note: Some modern features (like C++20 ranges or filesystem support) may be disabled on specific broken or incomplete toolchains even when standard feature-test macros indicate support. See [`JSON_HAS_RANGES`](../api/macros/json_has_ranges.md) and [`JSON_HAS_FILESYSTEM`](../api/macros/json_has_filesystem.md) for details on known exclusions.
|
||||
|
||||
- [x] The library is compiled with 50+ different C++ compilers with different operating systems and platforms,
|
||||
including the oldest versions known to compile the library.
|
||||
|
||||
@@ -66,14 +62,12 @@ 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.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 |
|
||||
| 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.6.3 (nvcc) | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
||||
| CUDA 11.0.221 (nvcc) | x86_64 | Ubuntu 20.04 LTS | GitHub |
|
||||
| Emscripten 4.0.6 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||
| GNU 4.8.5 | x86_64 | Ubuntu 20.04 LTS | GitHub |
|
||||
| GNU 4.9.3 | x86_64 | Ubuntu 20.04 LTS | GitHub |
|
||||
| GNU 5.5.0 | x86_64 | Ubuntu 20.04 LTS | GitHub |
|
||||
| GNU 6.4.0 | x86_64 | Ubuntu 20.04 LTS | GitHub |
|
||||
| GNU 4.8.5 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||
| GNU 4.9.3 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||
| GNU 5.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||
| GNU 6.4.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||
| GNU 7.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||
| GNU 8.5.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||
| GNU 9.3.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||
@@ -90,7 +84,7 @@ Note: Some modern features (like C++20 ranges or filesystem support) may be disa
|
||||
| GNU 15.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||
| GNU 16.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||
| GNU 16.1.0 | arm64 | Linux 6.1.100 | Cirrus CI |
|
||||
| icpc (ICC) 2021.10.0 20230609 | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
||||
| icpc (ICC) 2021.5.0 20211109 | x86_64 | Ubuntu 20.04.3 LTS | GitHub |
|
||||
| icpx (Intel oneAPI DPC++/C++) 2025.3.2 | x86_64 | Ubuntu 24.04 LTS | GitHub |
|
||||
| nvc++ (NVIDIA HPC SDK) 25.5-0 | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
||||
| MSVC 19.0.24241.7 | x86 | Windows 8.1 | AppVeyor |
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
draft2 size: 4
|
||||
draft3 size: 6
|
||||
@@ -1,11 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
true
|
||||
@@ -1,15 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
c1 == c2: true
|
||||
c1 == c3: false
|
||||
@@ -1,15 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
c1 != c2: false
|
||||
c1 != c3: true
|
||||
@@ -1,10 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
true
|
||||
@@ -1,13 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
["a",1,2.0,false]
|
||||
@@ -1,10 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
true
|
||||
@@ -1,10 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
true
|
||||
@@ -1,10 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
true
|
||||
@@ -1,10 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
true
|
||||
@@ -1,10 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
true
|
||||
@@ -1,10 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user