mirror of
https://github.com/nlohmann/json.git
synced 2026-06-23 12:44:18 +00:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6496e13b07 | |||
| 36e5ecf66d | |||
| fbec662afa | |||
| 456478b3c5 | |||
| 5f09b502b6 | |||
| 43e4db6141 | |||
| ea60d40f4a | |||
| 3c4c69a24e | |||
| 295732a817 | |||
| 944267f522 | |||
| cebb4e052a | |||
| 6708f22cd4 | |||
| aafad2be1f | |||
| 8c20571136 | |||
| 183390c10b | |||
| c8ea63a31b | |||
| 15acf260ca | |||
| a43347e1f9 | |||
| 5681e55da8 | |||
| 9f81beb5e2 | |||
| c0d511ea50 | |||
| 1e99a0273f | |||
| 528bc96d7e | |||
| 1c98ce869c | |||
| 6df60b0448 | |||
| 272ebdc900 | |||
| 79a9d00e15 | |||
| a4d13c92ba | |||
| 60bba02cc6 |
@@ -38,13 +38,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_EXE_LINKER_FLAGS="/STACK:4000000" -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||||
if: matrix.build_type == 'Release' && matrix.architecture == 'x64'
|
if: matrix.build_type == 'Release' && matrix.architecture == 'x64'
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||||
if: matrix.build_type == 'Release' && matrix.architecture != 'x64'
|
if: matrix.build_type == 'Release' && matrix.architecture != 'x64'
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_EXE_LINKER_FLAGS="/STACK:4000000" -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
- name: build
|
- name: build
|
||||||
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
|
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
|
||||||
@@ -76,7 +76,7 @@ jobs:
|
|||||||
run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||||
if: matrix.build_type == 'Release'
|
if: matrix.build_type == 'Release'
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_EXE_LINKER_FLAGS="/STACK:4000000" -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||||
if: matrix.build_type == 'Debug'
|
if: matrix.build_type == 'Debug'
|
||||||
- name: build
|
- name: build
|
||||||
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
|
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
|
||||||
@@ -89,7 +89,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -S . -B build -G "Visual Studio 16 2019" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 16 2019" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX" -DCMAKE_EXE_LINKER_FLAGS="/STACK:4000000"
|
||||||
- name: build
|
- name: build
|
||||||
run: cmake --build build --config Release --parallel 10
|
run: cmake --build build --config Release --parallel 10
|
||||||
- name: test
|
- name: test
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[](https://github.com/nlohmann/json/releases)
|
[](https://github.com/nlohmann/json/releases)
|
||||||
|
|
||||||
[](https://app.travis-ci.com/nlohmann/json)
|
[](https://travis-ci.org/nlohmann/json)
|
||||||
[](https://ci.appveyor.com/project/nlohmann/json)
|
[](https://ci.appveyor.com/project/nlohmann/json)
|
||||||
[](https://github.com/nlohmann/json/actions?query=workflow%3AUbuntu)
|
[](https://github.com/nlohmann/json/actions?query=workflow%3AUbuntu)
|
||||||
[](https://github.com/nlohmann/json/actions?query=workflow%3AmacOS)
|
[](https://github.com/nlohmann/json/actions?query=workflow%3AmacOS)
|
||||||
@@ -1238,7 +1238,7 @@ endif()
|
|||||||
|
|
||||||
### Package Managers
|
### Package Managers
|
||||||
|
|
||||||
:beer: If you are using OS X and [Homebrew](https://brew.sh), just type `brew install nlohmann-json` and you're set. If you want the bleeding edge rather than the latest release, use `brew install nlohmann-json --HEAD`. See [nlohmann-json](https://formulae.brew.sh/formula/nlohmann-json) for more information.
|
:beer: If you are using OS X and [Homebrew](https://brew.sh), just type `brew tap nlohmann/json` and `brew install nlohmann-json` and you're set. If you want the bleeding edge rather than the latest release, use `brew install nlohmann-json --HEAD`.
|
||||||
|
|
||||||
If you are using the [Meson Build System](https://mesonbuild.com), add this source tree as a [meson subproject](https://mesonbuild.com/Subprojects.html#using-a-subproject). You may also use the `include.zip` published in this project's [Releases](https://github.com/nlohmann/json/releases) to reduce the size of the vendored source tree. Alternatively, you can get a wrap file by downloading it from [Meson WrapDB](https://wrapdb.mesonbuild.com/nlohmann_json), or simply use `meson wrap install nlohmann_json`. Please see the meson project for any issues regarding the packaging.
|
If you are using the [Meson Build System](https://mesonbuild.com), add this source tree as a [meson subproject](https://mesonbuild.com/Subprojects.html#using-a-subproject). You may also use the `include.zip` published in this project's [Releases](https://github.com/nlohmann/json/releases) to reduce the size of the vendored source tree. Alternatively, you can get a wrap file by downloading it from [Meson WrapDB](https://wrapdb.mesonbuild.com/nlohmann_json), or simply use `meson wrap install nlohmann_json`. Please see the meson project for any issues regarding the packaging.
|
||||||
|
|
||||||
@@ -1252,7 +1252,7 @@ If you are using [hunter](https://github.com/cpp-pm/hunter) on your project for
|
|||||||
|
|
||||||
If you are using [Buckaroo](https://buckaroo.pm), you can install this library's module with `buckaroo add github.com/buckaroo-pm/nlohmann-json`. Please file issues [here](https://github.com/buckaroo-pm/nlohmann-json). There is a demo repo [here](https://github.com/njlr/buckaroo-nholmann-json-example).
|
If you are using [Buckaroo](https://buckaroo.pm), you can install this library's module with `buckaroo add github.com/buckaroo-pm/nlohmann-json`. Please file issues [here](https://github.com/buckaroo-pm/nlohmann-json). There is a demo repo [here](https://github.com/njlr/buckaroo-nholmann-json-example).
|
||||||
|
|
||||||
If you are using [vcpkg](https://github.com/Microsoft/vcpkg/) on your project for external dependencies, then you can install the [nlohmann-json package](https://github.com/Microsoft/vcpkg/tree/master/ports/nlohmann-json) with `vcpkg install nlohmann-json` and follow the then displayed descriptions. Please see the vcpkg project for any issues regarding the packaging.
|
If you are using [vcpkg](https://github.com/Microsoft/vcpkg/) on your project for external dependencies, then you can use the [nlohmann-json package](https://github.com/Microsoft/vcpkg/tree/master/ports/nlohmann-json). Please see the vcpkg project for any issues regarding the packaging.
|
||||||
|
|
||||||
If you are using [cget](https://cget.readthedocs.io/en/latest/), you can install the latest development version with `cget install nlohmann/json`. A specific version can be installed with `cget install nlohmann/json@v3.1.0`. Also, the multiple header version can be installed by adding the `-DJSON_MultipleHeaders=ON` flag (i.e., `cget install nlohmann/json -DJSON_MultipleHeaders=ON`).
|
If you are using [cget](https://cget.readthedocs.io/en/latest/), you can install the latest development version with `cget install nlohmann/json`. A specific version can be installed with `cget install nlohmann/json@v3.1.0`. Also, the multiple header version can be installed by adding the `-DJSON_MultipleHeaders=ON` flag (i.e., `cget install nlohmann/json -DJSON_MultipleHeaders=ON`).
|
||||||
|
|
||||||
|
|||||||
+9
-8
@@ -6,6 +6,7 @@ environment:
|
|||||||
configuration: Debug
|
configuration: Debug
|
||||||
platform: x86
|
platform: x86
|
||||||
CXX_FLAGS: "/W4 /WX"
|
CXX_FLAGS: "/W4 /WX"
|
||||||
|
LINKER_FLAGS: ""
|
||||||
CMAKE_OPTIONS: ""
|
CMAKE_OPTIONS: ""
|
||||||
GENERATOR: Visual Studio 14 2015
|
GENERATOR: Visual Studio 14 2015
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ environment:
|
|||||||
configuration: Release
|
configuration: Release
|
||||||
platform: x86
|
platform: x86
|
||||||
CXX_FLAGS: "/W4 /WX"
|
CXX_FLAGS: "/W4 /WX"
|
||||||
|
LINKER_FLAGS: ""
|
||||||
CMAKE_OPTIONS: ""
|
CMAKE_OPTIONS: ""
|
||||||
GENERATOR: Visual Studio 14 2015
|
GENERATOR: Visual Studio 14 2015
|
||||||
|
|
||||||
@@ -21,6 +23,7 @@ environment:
|
|||||||
platform: x86
|
platform: x86
|
||||||
name: with_win_header
|
name: with_win_header
|
||||||
CXX_FLAGS: "/W4 /WX"
|
CXX_FLAGS: "/W4 /WX"
|
||||||
|
LINKER_FLAGS: ""
|
||||||
CMAKE_OPTIONS: ""
|
CMAKE_OPTIONS: ""
|
||||||
GENERATOR: Visual Studio 14 2015
|
GENERATOR: Visual Studio 14 2015
|
||||||
|
|
||||||
@@ -28,6 +31,7 @@ environment:
|
|||||||
configuration: Release
|
configuration: Release
|
||||||
platform: x86
|
platform: x86
|
||||||
CXX_FLAGS: "/permissive- /std:c++latest /utf-8 /W4 /WX"
|
CXX_FLAGS: "/permissive- /std:c++latest /utf-8 /W4 /WX"
|
||||||
|
LINKER_FLAGS: ""
|
||||||
CMAKE_OPTIONS: ""
|
CMAKE_OPTIONS: ""
|
||||||
GENERATOR: Visual Studio 15 2017
|
GENERATOR: Visual Studio 15 2017
|
||||||
|
|
||||||
@@ -35,6 +39,7 @@ environment:
|
|||||||
configuration: Release
|
configuration: Release
|
||||||
platform: x86
|
platform: x86
|
||||||
CXX_FLAGS: "/W4 /WX"
|
CXX_FLAGS: "/W4 /WX"
|
||||||
|
LINKER_FLAGS: ""
|
||||||
CMAKE_OPTIONS: "-DJSON_ImplicitConversions=OFF"
|
CMAKE_OPTIONS: "-DJSON_ImplicitConversions=OFF"
|
||||||
GENERATOR: Visual Studio 16 2019
|
GENERATOR: Visual Studio 16 2019
|
||||||
|
|
||||||
@@ -42,13 +47,15 @@ environment:
|
|||||||
configuration: Release
|
configuration: Release
|
||||||
platform: x64
|
platform: x64
|
||||||
CXX_FLAGS: "/W4 /WX"
|
CXX_FLAGS: "/W4 /WX"
|
||||||
|
LINKER_FLAGS: ""
|
||||||
CMAKE_OPTIONS: ""
|
CMAKE_OPTIONS: ""
|
||||||
GENERATOR: Visual Studio 14 2015
|
GENERATOR: Visual Studio 14 2015
|
||||||
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||||
configuration: Release
|
configuration: Release
|
||||||
platform: x64
|
platform: x64
|
||||||
CXX_FLAGS: "/permissive- /std:c++latest /Zc:__cplusplus /utf-8 /W4 /WX"
|
CXX_FLAGS: "/permissive- /std:c++latest /Zc:__cplusplus /utf-8 /F4000000 /W4 /WX"
|
||||||
|
LINKER_FLAGS: "/STACK:4000000"
|
||||||
CMAKE_OPTIONS: ""
|
CMAKE_OPTIONS: ""
|
||||||
GENERATOR: Visual Studio 15 2017
|
GENERATOR: Visual Studio 15 2017
|
||||||
|
|
||||||
@@ -63,7 +70,7 @@ before_build:
|
|||||||
# for with_win_header build, inject the inclusion of Windows.h to the single-header library
|
# for with_win_header build, inject the inclusion of Windows.h to the single-header library
|
||||||
- ps: if ($env:name -Eq "with_win_header") { $header_path = "single_include\nlohmann\json.hpp" }
|
- ps: if ($env:name -Eq "with_win_header") { $header_path = "single_include\nlohmann\json.hpp" }
|
||||||
- ps: if ($env:name -Eq "with_win_header") { "#include <Windows.h>`n" + (Get-Content $header_path | Out-String) | Set-Content $header_path }
|
- ps: if ($env:name -Eq "with_win_header") { "#include <Windows.h>`n" + (Get-Content $header_path | Out-String) | Set-Content $header_path }
|
||||||
- cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On "%CMAKE_OPTIONS%"
|
- cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_EXE_LINKER_FLAGS="%LINKER_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On "%CMAKE_OPTIONS%"
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- cmake --build . --config "%configuration%"
|
- cmake --build . --config "%configuration%"
|
||||||
@@ -75,9 +82,3 @@ test_script:
|
|||||||
# occasional timeouts on AppVeyor.
|
# occasional timeouts on AppVeyor.
|
||||||
# More info: https://github.com/nlohmann/json/pull/1570
|
# More info: https://github.com/nlohmann/json/pull/1570
|
||||||
- if "%configuration%"=="Debug" ctest --exclude-regex "test-unicode" -C "%configuration%" -V -j
|
- if "%configuration%"=="Debug" ctest --exclude-regex "test-unicode" -C "%configuration%" -V -j
|
||||||
|
|
||||||
# only build PRs and commits to develop branch
|
|
||||||
# (see https://help.appveyor.com/discussions/questions/55079-two-builds-per-commit-to-pull-request)
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- develop
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ super-linear complexity.
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example "Parsing from a character array"
|
??? example "Parsing from a charater array"
|
||||||
|
|
||||||
The example below demonstrates the `parse()` function reading from an array.
|
The example below demonstrates the `parse()` function reading from an array.
|
||||||
|
|
||||||
|
|||||||
@@ -11,16 +11,18 @@ Throughout this page, we will describe how to compile the example file `example.
|
|||||||
If you are using OS X and [Homebrew](http://brew.sh), just type
|
If you are using OS X and [Homebrew](http://brew.sh), just type
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
brew tap nlohmann/json
|
||||||
brew install nlohmann-json
|
brew install nlohmann-json
|
||||||
```
|
```
|
||||||
|
|
||||||
and you're set. If you want the bleeding edge rather than the latest release, use
|
and you're set. If you want the bleeding edge rather than the latest release, use
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
brew tap nlohmann/json
|
||||||
brew install nlohmann-json --HEAD
|
brew install nlohmann-json --HEAD
|
||||||
```
|
```
|
||||||
|
|
||||||
instead. See [nlohmann-json](https://formulae.brew.sh/formula/nlohmann-json) for more information.
|
instead.
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
|
|
||||||
@@ -35,6 +37,7 @@ instead. See [nlohmann-json](https://formulae.brew.sh/formula/nlohmann-json) for
|
|||||||
2. Install the package
|
2. Install the package
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
brew tap nlohmann/json
|
||||||
brew install nlohmann-json
|
brew install nlohmann-json
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -107,40 +110,7 @@ If you are using [Buckaroo](https://buckaroo.pm), you can install this library's
|
|||||||
|
|
||||||
## vcpkg
|
## vcpkg
|
||||||
|
|
||||||
If you are using [vcpkg](https://github.com/Microsoft/vcpkg/) on your project for external dependencies, then you can install the [nlohmann-json package](https://github.com/Microsoft/vcpkg/tree/master/ports/nlohmann-json) with `vcpkg install nlohmann-json` and follow the then displayed descriptions. Please see the vcpkg project for any issues regarding the packaging.
|
If you are using [vcpkg](https://github.com/Microsoft/vcpkg/) on your project for external dependencies, then you can use the [nlohmann-json package](https://github.com/Microsoft/vcpkg/tree/master/ports/nlohmann-json). Please see the vcpkg project for any issues regarding the packaging.
|
||||||
|
|
||||||
??? example
|
|
||||||
|
|
||||||
1. Create the following files:
|
|
||||||
|
|
||||||
=== "CMakeLists.txt"
|
|
||||||
|
|
||||||
```cmake
|
|
||||||
--8<-- "integration/vcpkg/CMakeLists.txt"
|
|
||||||
```
|
|
||||||
|
|
||||||
=== "example.cpp"
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
--8<-- "integration/vcpkg/example.cpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Install package:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
vcpkg install nlohmann-json
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Build:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
mkdir build
|
|
||||||
cd build
|
|
||||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
|
|
||||||
cmake --build .
|
|
||||||
```
|
|
||||||
|
|
||||||
Note you need to adjust `/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake` to your system.
|
|
||||||
|
|
||||||
## cget
|
## cget
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
project(json_example)
|
|
||||||
cmake_minimum_required(VERSION 2.8.12)
|
|
||||||
|
|
||||||
find_package(nlohmann_json CONFIG REQUIRED)
|
|
||||||
|
|
||||||
add_executable(json_example example.cpp)
|
|
||||||
target_link_libraries(json_example PRIVATE nlohmann_json::nlohmann_json)
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
std::cout << json::meta() << std::endl;
|
|
||||||
}
|
|
||||||
@@ -94,7 +94,7 @@ struct external_constructor<value_t::binary>
|
|||||||
{
|
{
|
||||||
j.m_value.destroy(j.m_type);
|
j.m_value.destroy(j.m_type);
|
||||||
j.m_type = value_t::binary;
|
j.m_type = value_t::binary;
|
||||||
j.m_value = typename BasicJsonType::binary_t(std::move(b));
|
j.m_value = typename BasicJsonType::binary_t(std::move(b));;
|
||||||
j.assert_invariant();
|
j.assert_invariant();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <functional> // hash
|
#include <functional> // hash
|
||||||
|
|
||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
#include <nlohmann/detail/value_t.hpp>
|
|
||||||
|
|
||||||
namespace nlohmann
|
namespace nlohmann
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -436,24 +436,6 @@ struct is_constructible_tuple : std::false_type {};
|
|||||||
template<typename T1, typename... Args>
|
template<typename T1, typename... Args>
|
||||||
struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
|
struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
|
||||||
|
|
||||||
// a naive helper to check if a type is an ordered_map (exploits the fact that
|
|
||||||
// ordered_map inherits capacity() from std::vector)
|
|
||||||
template <typename T>
|
|
||||||
struct is_ordered_map
|
|
||||||
{
|
|
||||||
using one = char;
|
|
||||||
|
|
||||||
struct two
|
|
||||||
{
|
|
||||||
char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename C> static one test( decltype(&C::capacity) ) ;
|
|
||||||
template <typename C> static two test(...);
|
|
||||||
|
|
||||||
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
|
||||||
};
|
|
||||||
|
|
||||||
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
|
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
|
||||||
template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 >
|
template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 >
|
||||||
T conditional_static_cast(U value)
|
T conditional_static_cast(U value)
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class binary_writer
|
|||||||
case value_t::discarded:
|
case value_t::discarded:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));
|
JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1336,21 +1336,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ordered_json uses a vector internally, so pointers could have
|
|
||||||
// been invalidated; see https://github.com/nlohmann/json/issues/2962
|
|
||||||
#ifdef JSON_HEDLEY_MSVC_VERSION
|
|
||||||
#pragma warning(push )
|
|
||||||
#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr
|
|
||||||
#endif
|
|
||||||
if (detail::is_ordered_map<object_t>::value)
|
|
||||||
{
|
|
||||||
set_parents();
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
#ifdef JSON_HEDLEY_MSVC_VERSION
|
|
||||||
#pragma warning( pop )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
j.m_parent = this;
|
j.m_parent = this;
|
||||||
#else
|
#else
|
||||||
static_cast<void>(j);
|
static_cast<void>(j);
|
||||||
|
|||||||
@@ -3845,24 +3845,6 @@ struct is_constructible_tuple : std::false_type {};
|
|||||||
template<typename T1, typename... Args>
|
template<typename T1, typename... Args>
|
||||||
struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
|
struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
|
||||||
|
|
||||||
// a naive helper to check if a type is an ordered_map (exploits the fact that
|
|
||||||
// ordered_map inherits capacity() from std::vector)
|
|
||||||
template <typename T>
|
|
||||||
struct is_ordered_map
|
|
||||||
{
|
|
||||||
using one = char;
|
|
||||||
|
|
||||||
struct two
|
|
||||||
{
|
|
||||||
char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename C> static one test( decltype(&C::capacity) ) ;
|
|
||||||
template <typename C> static two test(...);
|
|
||||||
|
|
||||||
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
|
||||||
};
|
|
||||||
|
|
||||||
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
|
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
|
||||||
template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 >
|
template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 >
|
||||||
T conditional_static_cast(U value)
|
T conditional_static_cast(U value)
|
||||||
@@ -4620,7 +4602,7 @@ struct external_constructor<value_t::binary>
|
|||||||
{
|
{
|
||||||
j.m_value.destroy(j.m_type);
|
j.m_value.destroy(j.m_type);
|
||||||
j.m_type = value_t::binary;
|
j.m_type = value_t::binary;
|
||||||
j.m_value = typename BasicJsonType::binary_t(std::move(b));
|
j.m_value = typename BasicJsonType::binary_t(std::move(b));;
|
||||||
j.assert_invariant();
|
j.assert_invariant();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -5187,8 +5169,6 @@ class byte_container_with_subtype : public BinaryType
|
|||||||
|
|
||||||
// #include <nlohmann/detail/macro_scope.hpp>
|
// #include <nlohmann/detail/macro_scope.hpp>
|
||||||
|
|
||||||
// #include <nlohmann/detail/value_t.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace nlohmann
|
namespace nlohmann
|
||||||
{
|
{
|
||||||
@@ -13635,7 +13615,7 @@ class binary_writer
|
|||||||
case value_t::discarded:
|
case value_t::discarded:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));
|
JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18737,21 +18717,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ordered_json uses a vector internally, so pointers could have
|
|
||||||
// been invalidated; see https://github.com/nlohmann/json/issues/2962
|
|
||||||
#ifdef JSON_HEDLEY_MSVC_VERSION
|
|
||||||
#pragma warning(push )
|
|
||||||
#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr
|
|
||||||
#endif
|
|
||||||
if (detail::is_ordered_map<object_t>::value)
|
|
||||||
{
|
|
||||||
set_parents();
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
#ifdef JSON_HEDLEY_MSVC_VERSION
|
|
||||||
#pragma warning( pop )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
j.m_parent = this;
|
j.m_parent = this;
|
||||||
#else
|
#else
|
||||||
static_cast<void>(j);
|
static_cast<void>(j);
|
||||||
|
|||||||
+12
-12
@@ -100,23 +100,23 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|||||||
#target_compile_definitions(test-disabled_exceptions PUBLIC _HAS_EXCEPTIONS=0)
|
#target_compile_definitions(test-disabled_exceptions PUBLIC _HAS_EXCEPTIONS=0)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# avoid stack overflow, see https://github.com/nlohmann/json/issues/2955
|
add_executable(json_unit EXCLUDE_FROM_ALL $<TARGET_OBJECTS:doctest_main> ${files})
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
target_compile_definitions(json_unit PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
|
||||||
set_property(TARGET test-cbor APPEND_STRING PROPERTY LINK_FLAGS " /STACK:4000000")
|
target_compile_options(json_unit PRIVATE
|
||||||
set_property(TARGET test-msgpack APPEND_STRING PROPERTY LINK_FLAGS " /STACK:4000000")
|
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
|
||||||
set_property(TARGET test-ubjson APPEND_STRING PROPERTY LINK_FLAGS " /STACK:4000000")
|
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
|
||||||
endif()
|
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
||||||
|
)
|
||||||
|
target_include_directories(json_unit PRIVATE ${CMAKE_BINARY_DIR}/include thirdparty/doctest thirdparty/fifo_map)
|
||||||
|
target_link_libraries(json_unit ${NLOHMANN_JSON_TARGET_NAME})
|
||||||
|
add_dependencies(json_unit download_test_data)
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# Test the generated build configs
|
# Test the generated build configs
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
# these tests depend on the generated file nlohmann_jsonConfig.cmake
|
add_subdirectory(cmake_import)
|
||||||
if (JSON_Install)
|
add_subdirectory(cmake_import_minver)
|
||||||
add_subdirectory(cmake_import)
|
|
||||||
add_subdirectory(cmake_import_minver)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory(cmake_add_subdirectory)
|
add_subdirectory(cmake_add_subdirectory)
|
||||||
add_subdirectory(cmake_fetch_content)
|
add_subdirectory(cmake_fetch_content)
|
||||||
add_subdirectory(cmake_target_include_directories)
|
add_subdirectory(cmake_target_include_directories)
|
||||||
|
|||||||
@@ -174,14 +174,4 @@ TEST_CASE("Better diagnostics")
|
|||||||
j_obj["key"] = j_arr;
|
j_obj["key"] = j_arr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Regression test for issue #2962 - JSON_DIAGNOSTICS assertion for ordered_json")
|
|
||||||
{
|
|
||||||
nlohmann::ordered_json j;
|
|
||||||
nlohmann::ordered_json j2;
|
|
||||||
const std::string value;
|
|
||||||
j["first"] = value;
|
|
||||||
j["second"] = value;
|
|
||||||
j2["something"] = j;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ SOFTWARE.
|
|||||||
|
|
||||||
#define JSON_TESTS_PRIVATE
|
#define JSON_TESTS_PRIVATE
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using json = nlohmann::json;
|
using nlohmann::json;
|
||||||
using ordered_json = nlohmann::ordered_json;
|
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -660,25 +659,6 @@ TEST_CASE("regression tests 2")
|
|||||||
{
|
{
|
||||||
static_assert(std::is_copy_assignable<nlohmann::ordered_json>::value, "");
|
static_assert(std::is_copy_assignable<nlohmann::ordered_json>::value, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("issue #2958 - Inserting in unordered json using a pointer retains the leading slash")
|
|
||||||
{
|
|
||||||
std::string p = "/root";
|
|
||||||
|
|
||||||
// matching types
|
|
||||||
json test1;
|
|
||||||
test1[json::json_pointer(p)] = json::object();
|
|
||||||
CHECK(test1.dump() == "{\"root\":{}}");
|
|
||||||
|
|
||||||
ordered_json test2;
|
|
||||||
test2[ordered_json::json_pointer(p)] = json::object();
|
|
||||||
CHECK(test2.dump() == "{\"root\":{}}");
|
|
||||||
|
|
||||||
// mixed type - the JSON Pointer is implicitly converted into a string "/root"
|
|
||||||
ordered_json test3;
|
|
||||||
test3[json::json_pointer(p)] = json::object();
|
|
||||||
CHECK(test3.dump() == "{\"/root\":{}}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||||
|
|||||||
+1
-1
@@ -148,7 +148,7 @@ static bool ParseOneFlag(const char *Param) {
|
|||||||
int Val = MyStol(Str);
|
int Val = MyStol(Str);
|
||||||
*FlagDescriptions[F].IntFlag = Val;
|
*FlagDescriptions[F].IntFlag = Val;
|
||||||
if (Flags.verbosity >= 2)
|
if (Flags.verbosity >= 2)
|
||||||
Printf("Flag: %s %d\n", Name, Val);
|
Printf("Flag: %s %d\n", Name, Val);;
|
||||||
return true;
|
return true;
|
||||||
} else if (FlagDescriptions[F].UIntFlag) {
|
} else if (FlagDescriptions[F].UIntFlag) {
|
||||||
unsigned int Val = std::stoul(Str);
|
unsigned int Val = std::stoul(Str);
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,5 @@
|
|||||||
import gdb
|
import gdb
|
||||||
|
import re
|
||||||
|
|
||||||
class JsonValuePrinter:
|
class JsonValuePrinter:
|
||||||
"Print a json-value"
|
"Print a json-value"
|
||||||
@@ -12,8 +13,7 @@ class JsonValuePrinter:
|
|||||||
return self.val
|
return self.val
|
||||||
|
|
||||||
def json_lookup_function(val):
|
def json_lookup_function(val):
|
||||||
name = val.type.strip_typedefs().name
|
if re.search("^nlohmann::basic_json<.*>$", val.type.strip_typedefs().name):
|
||||||
if name and name.startswith("nlohmann::basic_json<") and name.endswith(">"):
|
|
||||||
t = str(val['m_type'])
|
t = str(val['m_type'])
|
||||||
if t.startswith("nlohmann::detail::value_t::"):
|
if t.startswith("nlohmann::detail::value_t::"):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user