Merge branch 'develop' into derived_macros

# Conflicts:
#	single_include/nlohmann/json_fwd.hpp
This commit is contained in:
Niccolò Iardella 2023-10-18 15:57:39 +02:00
commit de59860312
No known key found for this signature in database
GPG Key ID: C13339F3B7755DA3
67 changed files with 259 additions and 129 deletions

View File

@ -43,8 +43,10 @@ Checks: '*,
-misc-non-private-member-variables-in-classes, -misc-non-private-member-variables-in-classes,
-modernize-concat-nested-namespaces, -modernize-concat-nested-namespaces,
-modernize-type-traits, -modernize-type-traits,
-modernize-use-constraints,
-modernize-use-nodiscard, -modernize-use-nodiscard,
-modernize-use-trailing-return-type, -modernize-use-trailing-return-type,
-performance-enum-size,
-readability-function-cognitive-complexity, -readability-function-cognitive-complexity,
-readability-function-size, -readability-function-size,
-readability-identifier-length, -readability-identifier-length,

View File

@ -29,6 +29,7 @@ jobs:
uses: egor-tensin/setup-mingw@v2 uses: egor-tensin/setup-mingw@v2
with: with:
platform: ${{ matrix.architecture }} platform: ${{ matrix.architecture }}
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
- name: Run CMake - name: Run CMake
run: cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On run: cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
- name: Build - name: Build

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.1...3.14)
## ##
## PROJECT ## PROJECT

View File

@ -41,7 +41,7 @@ int main()
// try to use an array index with leading '0' // try to use an array index with leading '0'
json::reference ref = j.at("/array/01"_json_pointer); json::reference ref = j.at("/array/01"_json_pointer);
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -52,7 +52,7 @@ int main()
// try to use an array index that is not a number // try to use an array index that is not a number
json::reference ref = j.at("/array/one"_json_pointer); json::reference ref = j.at("/array/one"_json_pointer);
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -63,7 +63,7 @@ int main()
// try to use an invalid array index // try to use an invalid array index
json::reference ref = j.at("/array/4"_json_pointer); json::reference ref = j.at("/array/4"_json_pointer);
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -74,7 +74,7 @@ int main()
// try to use the array index '-' // try to use the array index '-'
json::reference ref = j.at("/array/-"_json_pointer); json::reference ref = j.at("/array/-"_json_pointer);
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -85,7 +85,7 @@ int main()
// try to use a JSON pointer to a nonexistent object key // try to use a JSON pointer to a nonexistent object key
json::const_reference ref = j.at("/foo"_json_pointer); json::const_reference ref = j.at("/foo"_json_pointer);
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -96,7 +96,7 @@ int main()
// try to use a JSON pointer that cannot be resolved // try to use a JSON pointer that cannot be resolved
json::reference ref = j.at("/number/foo"_json_pointer); json::reference ref = j.at("/number/foo"_json_pointer);
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -29,7 +29,7 @@ int main()
// try to use an array index that is not a number // try to use an array index that is not a number
json::const_reference ref = j.at("/array/one"_json_pointer); json::const_reference ref = j.at("/array/one"_json_pointer);
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -40,7 +40,7 @@ int main()
// try to use an invalid array index // try to use an invalid array index
json::const_reference ref = j.at("/array/4"_json_pointer); json::const_reference ref = j.at("/array/4"_json_pointer);
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -51,7 +51,7 @@ int main()
// try to use the array index '-' // try to use the array index '-'
json::const_reference ref = j.at("/array/-"_json_pointer); json::const_reference ref = j.at("/array/-"_json_pointer);
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -62,7 +62,7 @@ int main()
// try to use a JSON pointer to a nonexistent object key // try to use a JSON pointer to a nonexistent object key
json::const_reference ref = j.at("/foo"_json_pointer); json::const_reference ref = j.at("/foo"_json_pointer);
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -73,7 +73,7 @@ int main()
// try to use a JSON pointer that cannot be resolved // try to use a JSON pointer that cannot be resolved
json::const_reference ref = j.at("/number/foo"_json_pointer); json::const_reference ref = j.at("/number/foo"_json_pointer);
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -31,7 +31,7 @@ int main()
json str = "I am a string"; json str = "I am a string";
str.at("the good"sv) = "Another string"; str.at("the good"sv) = "Another string";
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -42,7 +42,7 @@ int main()
// try to write at a nonexisting key using string_view // try to write at a nonexisting key using string_view
object.at("the fast"sv) = "il rapido"; object.at("the fast"sv) = "il rapido";
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -25,7 +25,7 @@ int main()
const json str = "I am a string"; const json str = "I am a string";
std::cout << str.at("the good"sv) << '\n'; std::cout << str.at("the good"sv) << '\n';
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -36,7 +36,7 @@ int main()
// try to read from a nonexisting key using string_view // try to read from a nonexisting key using string_view
std::cout << object.at("the fast"sv) << '\n'; std::cout << object.at("the fast"sv) << '\n';
} }
catch (json::out_of_range) catch (const json::out_of_range)
{ {
std::cout << "out of range" << '\n'; std::cout << "out of range" << '\n';
} }

View File

@ -29,7 +29,7 @@ int main()
json str = "I am a string"; json str = "I am a string";
str.at("the good") = "Another string"; str.at("the good") = "Another string";
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -40,7 +40,7 @@ int main()
// try to write at a nonexisting key // try to write at a nonexisting key
object.at("the fast") = "il rapido"; object.at("the fast") = "il rapido";
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -23,7 +23,7 @@ int main()
const json str = "I am a string"; const json str = "I am a string";
std::cout << str.at("the good") << '\n'; std::cout << str.at("the good") << '\n';
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -34,7 +34,7 @@ int main()
// try to read from a nonexisting key // try to read from a nonexisting key
std::cout << object.at("the fast") << '\n'; std::cout << object.at("the fast") << '\n';
} }
catch (json::out_of_range) catch (const json::out_of_range)
{ {
std::cout << "out of range" << '\n'; std::cout << "out of range" << '\n';
} }

View File

@ -24,7 +24,7 @@ int main()
json str = "I am a string"; json str = "I am a string";
str.at(0) = "Another string"; str.at(0) = "Another string";
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -35,7 +35,7 @@ int main()
// try to write beyond the array limit // try to write beyond the array limit
array.at(5) = "sixth"; array.at(5) = "sixth";
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -18,7 +18,7 @@ int main()
const json str = "I am a string"; const json str = "I am a string";
std::cout << str.at(0) << '\n'; std::cout << str.at(0) << '\n';
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -29,7 +29,7 @@ int main()
// try to read beyond the array limit // try to read beyond the array limit
std::cout << array.at(5) << '\n'; std::cout << array.at(5) << '\n';
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -31,7 +31,7 @@ int main()
json j_null; json j_null;
j_null.back(); j_null.back();
} }
catch (json::invalid_iterator& e) catch (const json::invalid_iterator& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -25,7 +25,7 @@ int main()
{ {
json j_invalid(j_number.begin() + 1, j_number.end()); json j_invalid(j_number.begin() + 1, j_number.end());
} }
catch (json::invalid_iterator& e) catch (const json::invalid_iterator& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -13,7 +13,7 @@ int main()
{ {
auto b_throw_on_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::error); auto b_throw_on_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::error);
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
} }

View File

@ -26,7 +26,7 @@ int main()
// try to use an array index with leading '0' // try to use an array index with leading '0'
j.contains("/array/01"_json_pointer); j.contains("/array/01"_json_pointer);
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -36,7 +36,7 @@ int main()
// try to use an array index that is not a number // try to use an array index that is not a number
j.contains("/array/one"_json_pointer); j.contains("/array/one"_json_pointer);
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -15,7 +15,7 @@ int main()
{ {
int housenumber = j["address"]["housenumber"]; int housenumber = j["address"]["housenumber"];
} }
catch (json::exception& e) catch (const json::exception& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -13,7 +13,7 @@ int main()
{ {
int housenumber = j["address"]["housenumber"]; int housenumber = j["address"]["housenumber"];
} }
catch (json::exception& e) catch (const json::exception& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -35,7 +35,7 @@ int main()
{ {
std::cout << j_invalid.dump() << std::endl; std::cout << j_invalid.dump() << std::endl;
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
} }

View File

@ -11,7 +11,7 @@ int main()
{ {
std::cout << j_invalid.dump() << std::endl; std::cout << j_invalid.dump() << std::endl;
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
} }

View File

@ -11,7 +11,7 @@ int main()
json j = {{"foo", "bar"}}; json j = {{"foo", "bar"}};
json k = j.at("non-existing"); json k = j.at("non-existing");
} }
catch (json::exception& e) catch (const json::exception& e)
{ {
// output exception information // output exception information
std::cout << "message: " << e.what() << '\n' std::cout << "message: " << e.what() << '\n'

View File

@ -20,7 +20,7 @@ int main()
{ {
auto r3 = value.get_ref<json::number_float_t&>(); auto r3 = value.get_ref<json::number_float_t&>();
} }
catch (json::type_error& ex) catch (const json::type_error& ex)
{ {
std::cout << ex.what() << '\n'; std::cout << ex.what() << '\n';
} }

View File

@ -12,7 +12,7 @@ int main()
json::iterator it = j.begin(); json::iterator it = j.begin();
auto k = it.key(); auto k = it.key();
} }
catch (json::invalid_iterator& e) catch (const json::invalid_iterator& e)
{ {
// output exception information // output exception information
std::cout << "message: " << e.what() << '\n' std::cout << "message: " << e.what() << '\n'

View File

@ -20,7 +20,7 @@ int main()
{ {
json::json_pointer p9("foo"); json::json_pointer p9("foo");
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -30,7 +30,7 @@ int main()
{ {
json::json_pointer p10("/foo/~"); json::json_pointer p10("/foo/~");
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }
@ -40,7 +40,7 @@ int main()
{ {
json::json_pointer p11("/foo/~3"); json::json_pointer p11("/foo/~3");
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -53,7 +53,7 @@ int main()
{ {
auto p3 = j3.template get<ns::person>(); auto p3 = j3.template get<ns::person>();
} }
catch (json::exception& e) catch (const json::exception& e)
{ {
std::cout << "deserialization failed: " << e.what() << std::endl; std::cout << "deserialization failed: " << e.what() << std::endl;
} }

View File

@ -41,7 +41,7 @@ int main()
{ {
auto p3 = j3.template get<ns::person>(); auto p3 = j3.template get<ns::person>();
} }
catch (json::exception& e) catch (const json::exception& e)
{ {
std::cout << "deserialization failed: " << e.what() << std::endl; std::cout << "deserialization failed: " << e.what() << std::endl;
} }

View File

@ -46,7 +46,7 @@ int main()
{ {
auto p3 = j3.template get<ns::person>(); auto p3 = j3.template get<ns::person>();
} }
catch (json::exception& e) catch (const json::exception& e)
{ {
std::cout << "deserialization failed: " << e.what() << std::endl; std::cout << "deserialization failed: " << e.what() << std::endl;
} }

View File

@ -34,7 +34,7 @@ int main()
{ {
auto p3 = j3.template get<ns::person>(); auto p3 = j3.template get<ns::person>();
} }
catch (json::exception& e) catch (const json::exception& e)
{ {
std::cout << "deserialization failed: " << e.what() << std::endl; std::cout << "deserialization failed: " << e.what() << std::endl;
} }

View File

@ -21,7 +21,7 @@ int main()
// can only create an object from a list of pairs // can only create an object from a list of pairs
json j_invalid_object = json::object({{ "one", 1, 2 }}); json j_invalid_object = json::object({{ "one", 1, 2 }});
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -53,7 +53,7 @@ int main()
{ {
bool v1 = json_types["string"]; bool v1 = json_types["string"];
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
std::cout << e.what() << '\n'; std::cout << e.what() << '\n';
} }

View File

@ -21,7 +21,7 @@ int main()
}])"_json; }])"_json;
value.patch(patch); value.patch(patch);
} }
catch (json::other_error& e) catch (const json::other_error& e)
{ {
// output exception information // output exception information
std::cout << "message: " << e.what() << '\n' std::cout << "message: " << e.what() << '\n'

View File

@ -11,7 +11,7 @@ int main()
json j = {1, 2, 3, 4}; json j = {1, 2, 3, 4};
j.at(4) = 10; j.at(4) = 10;
} }
catch (json::out_of_range& e) catch (const json::out_of_range& e)
{ {
// output exception information // output exception information
std::cout << "message: " << e.what() << '\n' std::cout << "message: " << e.what() << '\n'

View File

@ -17,7 +17,7 @@ int main()
{ {
json j = json::parse(text); json j = json::parse(text);
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
} }

View File

@ -10,7 +10,7 @@ int main()
// parsing input with a syntax error // parsing input with a syntax error
json::parse("[1,2,3,]"); json::parse("[1,2,3,]");
} }
catch (json::parse_error& e) catch (const json::parse_error& e)
{ {
// output exception information // output exception information
std::cout << "message: " << e.what() << '\n' std::cout << "message: " << e.what() << '\n'

View File

@ -11,7 +11,7 @@ int main()
json j = "string"; json j = "string";
j.push_back("another string"); j.push_back("another string");
} }
catch (json::type_error& e) catch (const json::type_error& e)
{ {
// output exception information // output exception information
std::cout << "message: " << e.what() << '\n' std::cout << "message: " << e.what() << '\n'

View File

@ -14,7 +14,7 @@ template<
template<typename U> class AllocatorType = std::allocator, template<typename U> class AllocatorType = std::allocator,
template<typename T, typename SFINAE = void> class JSONSerializer = adl_serializer, template<typename T, typename SFINAE = void> class JSONSerializer = adl_serializer,
class BinaryType = std::vector<std::uint8_t>, class BinaryType = std::vector<std::uint8_t>,
class CustomBaseClass = void> class CustomBaseClass = void
> >
class basic_json; class basic_json;
``` ```

View File

@ -0,0 +1,31 @@
# JSON_HAS_STATIC_RTTI
```cpp
#define JSON_HAS_STATIC_RTTI /* value */
```
This macro indicates whether the standard library has any support for RTTI (run time type information).
Possible values are `1` when supported or `0` when unsupported.
## Default definition
The default value is detected based on the preprocessor macro `#!cpp _HAS_STATIC_RTTI`.
When the macro is not defined, the library will define it to its default value.
## Examples
??? example
The code below forces the library to enable support for libraries with RTTI dependence:
```cpp
#define JSON_HAS_STATIC_RTTI 1
#include <nlohmann/json.hpp>
...
```
## Version history
- Added in version ?.

View File

@ -59,7 +59,7 @@ See examples below for the concrete generated code.
Consider the following complete example: Consider the following complete example:
```cpp hl_lines="21" ```cpp hl_lines="22"
--8<-- "examples/nlohmann_define_type_intrusive_macro.cpp" --8<-- "examples/nlohmann_define_type_intrusive_macro.cpp"
``` ```
@ -80,7 +80,7 @@ See examples below for the concrete generated code.
The macro is equivalent to: The macro is equivalent to:
```cpp hl_lines="21 22 23 24 25 26 27 28 29 30 31 32 33" ```cpp hl_lines="22 23 24 25 26 27 28 29 30 31 32 33 34"
--8<-- "examples/nlohmann_define_type_intrusive_explicit.cpp" --8<-- "examples/nlohmann_define_type_intrusive_explicit.cpp"
``` ```
@ -88,7 +88,7 @@ See examples below for the concrete generated code.
Consider the following complete example: Consider the following complete example:
```cpp hl_lines="21" ```cpp hl_lines="22"
--8<-- "examples/nlohmann_define_type_intrusive_with_default_macro.cpp" --8<-- "examples/nlohmann_define_type_intrusive_with_default_macro.cpp"
``` ```
@ -108,7 +108,7 @@ See examples below for the concrete generated code.
The macro is equivalent to: The macro is equivalent to:
```cpp hl_lines="21 22 23 24 25 26 27 28 29 30 31 32 33 34" ```cpp hl_lines="21 22 23 24 25 26 27 28 29 30 31 32 33 34 35"
--8<-- "examples/nlohmann_define_type_intrusive_with_default_explicit.cpp" --8<-- "examples/nlohmann_define_type_intrusive_with_default_explicit.cpp"
``` ```

View File

@ -60,7 +60,7 @@ See examples below for the concrete generated code.
Consider the following complete example: Consider the following complete example:
```cpp hl_lines="15" ```cpp hl_lines="16"
--8<-- "examples/nlohmann_define_type_non_intrusive_macro.cpp" --8<-- "examples/nlohmann_define_type_non_intrusive_macro.cpp"
``` ```
@ -80,7 +80,7 @@ See examples below for the concrete generated code.
The macro is equivalent to: The macro is equivalent to:
```cpp hl_lines="15 16 17 18 19 20 21 22 23 24 25 26 27" ```cpp hl_lines="16 17 18 19 20 21 22 23 24 25 26 27 28"
--8<-- "examples/nlohmann_define_type_non_intrusive_explicit.cpp" --8<-- "examples/nlohmann_define_type_non_intrusive_explicit.cpp"
``` ```
@ -88,7 +88,7 @@ See examples below for the concrete generated code.
Consider the following complete example: Consider the following complete example:
```cpp hl_lines="20" ```cpp hl_lines="21"
--8<-- "examples/nlohmann_define_type_non_intrusive_with_default_macro.cpp" --8<-- "examples/nlohmann_define_type_non_intrusive_with_default_macro.cpp"
``` ```
@ -109,7 +109,7 @@ See examples below for the concrete generated code.
The macro is equivalent to: The macro is equivalent to:
```cpp hl_lines="20 21 22 23 24 25 26 27 28 29 30 31 32 33" ```cpp hl_lines="21 22 23 24 25 26 27 28 29 30 31 32 33 34"
--8<-- "examples/nlohmann_define_type_non_intrusive_with_default_explicit.cpp" --8<-- "examples/nlohmann_define_type_non_intrusive_with_default_explicit.cpp"
``` ```

View File

@ -1,7 +1,7 @@
# <small>nlohmann::</small>operator""_json # <small>nlohmann::</small>operator""_json
```cpp ```cpp
json operator "" _json(const char* s, std::size_t n); json operator ""_json(const char* s, std::size_t n);
``` ```
This operator implements a user-defined string literal for JSON objects. It can be used by adding `#!cpp _json` to a This operator implements a user-defined string literal for JSON objects. It can be used by adding `#!cpp _json` to a
@ -9,7 +9,7 @@ string literal and returns a [`json`](json.md) object if no parse error occurred
It is recommended to bring the operator into scope using any of the following lines: It is recommended to bring the operator into scope using any of the following lines:
```cpp ```cpp
using nlohmann::literals::operator "" _json; using nlohmann::literals::operator ""_json;
using namespace nlohmann::literals; using namespace nlohmann::literals;
using namespace nlohmann::json_literals; using namespace nlohmann::json_literals;
using namespace nlohmann::literals::json_literals; using namespace nlohmann::literals::json_literals;

View File

@ -1,7 +1,7 @@
# <small>nlohmann::</small>operator""_json_pointer # <small>nlohmann::</small>operator""_json_pointer
```cpp ```cpp
json_pointer operator "" _json_pointer(const char* s, std::size_t n); json_pointer operator ""_json_pointer(const char* s, std::size_t n);
``` ```
This operator implements a user-defined string literal for JSON Pointers. It can be used by adding `#!cpp _json_pointer` This operator implements a user-defined string literal for JSON Pointers. It can be used by adding `#!cpp _json_pointer`
@ -9,7 +9,7 @@ to a string literal and returns a [`json_pointer`](json_pointer/index.md) object
It is recommended to bring the operator into scope using any of the following lines: It is recommended to bring the operator into scope using any of the following lines:
```cpp ```cpp
using nlohmann::literals::operator "" _json_pointer; using nlohmann::literals::operator ""_json_pointer;
using namespace nlohmann::literals; using namespace nlohmann::literals;
using namespace nlohmann::json_literals; using namespace nlohmann::json_literals;
using namespace nlohmann::literals::json_literals; using namespace nlohmann::literals::json_literals;

View File

@ -292,7 +292,7 @@ struct wide_string_input_helper<BaseInputAdapter, 2>
} }
}; };
// Wraps another input apdater to convert wide character types into individual bytes. // Wraps another input adapter to convert wide character types into individual bytes.
template<typename BaseInputAdapter, typename WideCharType> template<typename BaseInputAdapter, typename WideCharType>
class wide_string_input_adapter class wide_string_input_adapter
{ {

View File

@ -222,7 +222,7 @@ class lexer : public lexer_base<BasicJsonType>
for (auto range = ranges.begin(); range != ranges.end(); ++range) for (auto range = ranges.begin(); range != ranges.end(); ++range)
{ {
get(); get();
if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) // NOLINT(bugprone-inc-dec-in-conditions)
{ {
add(current); add(current);
} }

View File

@ -133,6 +133,14 @@
#endif #endif
#endif #endif
#ifndef JSON_HAS_STATIC_RTTI
#if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
#define JSON_HAS_STATIC_RTTI 1
#else
#define JSON_HAS_STATIC_RTTI 0
#endif
#endif
#ifdef JSON_HAS_CPP_17 #ifdef JSON_HAS_CPP_17
#define JSON_INLINE_VARIABLE inline #define JSON_INLINE_VARIABLE inline
#else #else

View File

@ -38,6 +38,7 @@
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#undef JSON_HAS_THREE_WAY_COMPARISON #undef JSON_HAS_THREE_WAY_COMPARISON
#undef JSON_HAS_RANGES #undef JSON_HAS_RANGES
#undef JSON_HAS_STATIC_RTTI
#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#endif #endif

View File

@ -62,7 +62,9 @@
#include <nlohmann/ordered_map.hpp> #include <nlohmann/ordered_map.hpp>
#if defined(JSON_HAS_CPP_17) #if defined(JSON_HAS_CPP_17)
#include <any> #if JSON_HAS_STATIC_RTTI
#include <any>
#endif
#include <string_view> #include <string_view>
#endif #endif
@ -906,7 +908,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
bool is_an_object = std::all_of(init.begin(), init.end(), bool is_an_object = std::all_of(init.begin(), init.end(),
[](const detail::json_ref<basic_json>& element_ref) [](const detail::json_ref<basic_json>& element_ref)
{ {
return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string(); // The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int;
// (many string types can be constructed from 0 via its null-pointer guise, so we get a
// broken call to op[key_type], the wrong semantics and a 4804 warning on Windows)
return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
}); });
// adjust type if type deduction is not wanted // adjust type if type deduction is not wanted
@ -1883,7 +1888,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914)) #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
detail::negation<std::is_same<ValueType, std::string_view>>, detail::negation<std::is_same<ValueType, std::string_view>>,
#endif #endif
#if defined(JSON_HAS_CPP_17) #if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
detail::negation<std::is_same<ValueType, std::any>>, detail::negation<std::is_same<ValueType, std::any>>,
#endif #endif
detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType> detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
@ -5159,7 +5164,11 @@ inline namespace json_literals
/// @brief user-defined string literal for JSON values /// @brief user-defined string literal for JSON values
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/ /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/
JSON_HEDLEY_NON_NULL(1) JSON_HEDLEY_NON_NULL(1)
inline nlohmann::json operator "" _json(const char* s, std::size_t n) #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
inline nlohmann::json operator ""_json(const char* s, std::size_t n)
#else
inline nlohmann::json operator "" _json(const char* s, std::size_t n)
#endif
{ {
return nlohmann::json::parse(s, s + n); return nlohmann::json::parse(s, s + n);
} }
@ -5167,7 +5176,11 @@ inline nlohmann::json operator "" _json(const char* s, std::size_t n)
/// @brief user-defined string literal for JSON pointer /// @brief user-defined string literal for JSON pointer
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/
JSON_HEDLEY_NON_NULL(1) JSON_HEDLEY_NON_NULL(1)
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n) #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
inline nlohmann::json::json_pointer operator ""_json_pointer(const char* s, std::size_t n)
#else
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
#endif
{ {
return nlohmann::json::json_pointer(std::string(s, n)); return nlohmann::json::json_pointer(std::string(s, n));
} }
@ -5231,8 +5244,13 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC
} // namespace std } // namespace std
#if JSON_USE_GLOBAL_UDLS #if JSON_USE_GLOBAL_UDLS
using nlohmann::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
using nlohmann::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) using nlohmann::literals::json_literals::operator ""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers)
using nlohmann::literals::json_literals::operator ""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers)
#else
using nlohmann::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers)
using nlohmann::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers)
#endif
#endif #endif
#include <nlohmann/detail/macro_unscope.hpp> #include <nlohmann/detail/macro_unscope.hpp>

View File

@ -41,6 +41,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <utility> #include <utility>
// #include <nlohmann/detail/abi_macros.hpp> // #include <nlohmann/detail/abi_macros.hpp>
@ -53,6 +54,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// This file contains all macro definitions affecting or depending on the ABI // This file contains all macro definitions affecting or depending on the ABI
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
@ -154,6 +156,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <algorithm> // transform #include <algorithm> // transform
#include <array> // array #include <array> // array
#include <forward_list> // forward_list #include <forward_list> // forward_list
@ -176,6 +179,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cstddef> // nullptr_t #include <cstddef> // nullptr_t
#include <exception> // exception #include <exception> // exception
#if JSON_DIAGNOSTICS #if JSON_DIAGNOSTICS
@ -195,6 +199,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <array> // array #include <array> // array
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdint> // uint8_t #include <cstdint> // uint8_t
@ -210,6 +215,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <utility> // declval, pair #include <utility> // declval, pair
// #include <nlohmann/detail/meta/detected.hpp> // #include <nlohmann/detail/meta/detected.hpp>
// __ _____ _____ _____ // __ _____ _____ _____
@ -221,6 +227,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <type_traits> #include <type_traits>
// #include <nlohmann/detail/meta/void_t.hpp> // #include <nlohmann/detail/meta/void_t.hpp>
@ -233,6 +240,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// #include <nlohmann/detail/abi_macros.hpp> // #include <nlohmann/detail/abi_macros.hpp>
@ -2477,6 +2485,14 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#endif #endif
#endif #endif
#ifndef JSON_HAS_STATIC_RTTI
#if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
#define JSON_HAS_STATIC_RTTI 1
#else
#define JSON_HAS_STATIC_RTTI 0
#endif
#endif
#ifdef JSON_HAS_CPP_17 #ifdef JSON_HAS_CPP_17
#define JSON_INLINE_VARIABLE inline #define JSON_INLINE_VARIABLE inline
#else #else
@ -2951,6 +2967,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// #include <nlohmann/detail/abi_macros.hpp> // #include <nlohmann/detail/abi_macros.hpp>
@ -3025,6 +3042,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cstddef> // size_t #include <cstddef> // size_t
// #include <nlohmann/detail/abi_macros.hpp> // #include <nlohmann/detail/abi_macros.hpp>
@ -3067,6 +3085,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <array> // array #include <array> // array
#include <cstddef> // size_t #include <cstddef> // size_t
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type #include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
@ -3239,6 +3258,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <limits> // numeric_limits #include <limits> // numeric_limits
#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type #include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
#include <utility> // declval #include <utility> // declval
@ -3254,6 +3274,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <iterator> // random_access_iterator_tag #include <iterator> // random_access_iterator_tag
// #include <nlohmann/detail/abi_macros.hpp> // #include <nlohmann/detail/abi_macros.hpp>
@ -3321,6 +3342,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/detail/macro_scope.hpp>
@ -3340,6 +3362,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/detail/macro_scope.hpp>
@ -4157,6 +4180,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cstring> // strlen #include <cstring> // strlen
#include <string> // string #include <string> // string
#include <utility> // forward #include <utility> // forward
@ -4542,6 +4566,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// #include <nlohmann/detail/abi_macros.hpp> // #include <nlohmann/detail/abi_macros.hpp>
@ -4565,6 +4590,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/detail/macro_scope.hpp>
@ -5070,6 +5096,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <algorithm> // copy #include <algorithm> // copy
#include <iterator> // begin, end #include <iterator> // begin, end
#include <string> // string #include <string> // string
@ -5089,6 +5116,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cstddef> // size_t #include <cstddef> // size_t
#include <iterator> // input_iterator_tag #include <iterator> // input_iterator_tag
#include <string> // string, to_string #include <string> // string, to_string
@ -5809,6 +5837,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cstdint> // uint8_t, uint64_t #include <cstdint> // uint8_t, uint64_t
#include <tuple> // tie #include <tuple> // tie
#include <utility> // move #include <utility> // move
@ -5920,6 +5949,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cstdint> // uint8_t #include <cstdint> // uint8_t
#include <cstddef> // size_t #include <cstddef> // size_t
#include <functional> // hash #include <functional> // hash
@ -6052,6 +6082,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <algorithm> // generate_n #include <algorithm> // generate_n
#include <array> // array #include <array> // array
#include <cmath> // ldexp #include <cmath> // ldexp
@ -6077,6 +6108,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <array> // array #include <array> // array
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstring> // strlen #include <cstring> // strlen
@ -6363,7 +6395,7 @@ struct wide_string_input_helper<BaseInputAdapter, 2>
} }
}; };
// Wraps another input apdater to convert wide character types into individual bytes. // Wraps another input adapter to convert wide character types into individual bytes.
template<typename BaseInputAdapter, typename WideCharType> template<typename BaseInputAdapter, typename WideCharType>
class wide_string_input_adapter class wide_string_input_adapter
{ {
@ -6571,6 +6603,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cstddef> #include <cstddef>
#include <string> // string #include <string> // string
#include <utility> // move #include <utility> // move
@ -7302,6 +7335,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <array> // array #include <array> // array
#include <clocale> // localeconv #include <clocale> // localeconv
#include <cstddef> // size_t #include <cstddef> // size_t
@ -7519,7 +7553,7 @@ class lexer : public lexer_base<BasicJsonType>
for (auto range = ranges.begin(); range != ranges.end(); ++range) for (auto range = ranges.begin(); range != ranges.end(); ++range)
{ {
get(); get();
if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) // NOLINT(bugprone-inc-dec-in-conditions)
{ {
add(current); add(current);
} }
@ -8940,6 +8974,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cstdint> // size_t #include <cstdint> // size_t
#include <utility> // declval #include <utility> // declval
#include <string> // string #include <string> // string
@ -12091,6 +12126,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cmath> // isfinite #include <cmath> // isfinite
#include <cstdint> // uint8_t #include <cstdint> // uint8_t
#include <functional> // function #include <functional> // function
@ -12607,6 +12643,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// #include <nlohmann/detail/abi_macros.hpp> // #include <nlohmann/detail/abi_macros.hpp>
// #include <nlohmann/detail/iterators/primitive_iterator.hpp> // #include <nlohmann/detail/iterators/primitive_iterator.hpp>
@ -12619,6 +12656,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cstddef> // ptrdiff_t #include <cstddef> // ptrdiff_t
#include <limits> // numeric_limits #include <limits> // numeric_limits
@ -12777,6 +12815,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next #include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next
#include <type_traits> // conditional, is_const, remove_const #include <type_traits> // conditional, is_const, remove_const
@ -13538,6 +13577,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <cstddef> // ptrdiff_t #include <cstddef> // ptrdiff_t
#include <iterator> // reverse_iterator #include <iterator> // reverse_iterator
#include <utility> // declval #include <utility> // declval
@ -13706,6 +13746,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <algorithm> // all_of #include <algorithm> // all_of
#include <cctype> // isdigit #include <cctype> // isdigit
#include <cerrno> // errno, ERANGE #include <cerrno> // errno, ERANGE
@ -14700,6 +14741,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <initializer_list> #include <initializer_list>
#include <utility> #include <utility>
@ -14791,6 +14833,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <algorithm> // reverse #include <algorithm> // reverse
#include <array> // array #include <array> // array
#include <map> // map #include <map> // map
@ -14816,6 +14859,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <algorithm> // copy #include <algorithm> // copy
#include <cstddef> // size_t #include <cstddef> // size_t
#include <iterator> // back_inserter #include <iterator> // back_inserter
@ -16784,6 +16828,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <algorithm> // reverse, remove, fill, find, none_of #include <algorithm> // reverse, remove, fill, find, none_of
#include <array> // array #include <array> // array
#include <clocale> // localeconv, lconv #include <clocale> // localeconv, lconv
@ -16808,6 +16853,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <array> // array #include <array> // array
#include <cmath> // signbit, isfinite #include <cmath> // signbit, isfinite
#include <cstdint> // intN_t, uintN_t #include <cstdint> // intN_t, uintN_t
@ -18902,6 +18948,7 @@ NLOHMANN_JSON_NAMESPACE_END
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <functional> // equal_to, less #include <functional> // equal_to, less
#include <initializer_list> // initializer_list #include <initializer_list> // initializer_list
#include <iterator> // input_iterator_tag, iterator_traits #include <iterator> // input_iterator_tag, iterator_traits
@ -19256,7 +19303,9 @@ NLOHMANN_JSON_NAMESPACE_END
#if defined(JSON_HAS_CPP_17) #if defined(JSON_HAS_CPP_17)
#include <any> #if JSON_HAS_STATIC_RTTI
#include <any>
#endif
#include <string_view> #include <string_view>
#endif #endif
@ -20100,7 +20149,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
bool is_an_object = std::all_of(init.begin(), init.end(), bool is_an_object = std::all_of(init.begin(), init.end(),
[](const detail::json_ref<basic_json>& element_ref) [](const detail::json_ref<basic_json>& element_ref)
{ {
return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string(); // The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int;
// (many string types can be constructed from 0 via its null-pointer guise, so we get a
// broken call to op[key_type], the wrong semantics and a 4804 warning on Windows)
return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
}); });
// adjust type if type deduction is not wanted // adjust type if type deduction is not wanted
@ -21077,7 +21129,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914)) #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
detail::negation<std::is_same<ValueType, std::string_view>>, detail::negation<std::is_same<ValueType, std::string_view>>,
#endif #endif
#if defined(JSON_HAS_CPP_17) #if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
detail::negation<std::is_same<ValueType, std::any>>, detail::negation<std::is_same<ValueType, std::any>>,
#endif #endif
detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType> detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
@ -24353,7 +24405,11 @@ inline namespace json_literals
/// @brief user-defined string literal for JSON values /// @brief user-defined string literal for JSON values
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/ /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/
JSON_HEDLEY_NON_NULL(1) JSON_HEDLEY_NON_NULL(1)
inline nlohmann::json operator "" _json(const char* s, std::size_t n) #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
inline nlohmann::json operator ""_json(const char* s, std::size_t n)
#else
inline nlohmann::json operator "" _json(const char* s, std::size_t n)
#endif
{ {
return nlohmann::json::parse(s, s + n); return nlohmann::json::parse(s, s + n);
} }
@ -24361,7 +24417,11 @@ inline nlohmann::json operator "" _json(const char* s, std::size_t n)
/// @brief user-defined string literal for JSON pointer /// @brief user-defined string literal for JSON pointer
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/
JSON_HEDLEY_NON_NULL(1) JSON_HEDLEY_NON_NULL(1)
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n) #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
inline nlohmann::json::json_pointer operator ""_json_pointer(const char* s, std::size_t n)
#else
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
#endif
{ {
return nlohmann::json::json_pointer(std::string(s, n)); return nlohmann::json::json_pointer(std::string(s, n));
} }
@ -24425,8 +24485,13 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC
} // namespace std } // namespace std
#if JSON_USE_GLOBAL_UDLS #if JSON_USE_GLOBAL_UDLS
using nlohmann::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
using nlohmann::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) using nlohmann::literals::json_literals::operator ""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers)
using nlohmann::literals::json_literals::operator ""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers)
#else
using nlohmann::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers)
using nlohmann::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers)
#endif
#endif #endif
// #include <nlohmann/detail/macro_unscope.hpp> // #include <nlohmann/detail/macro_unscope.hpp>
@ -24439,6 +24504,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// restore clang diagnostic settings // restore clang diagnostic settings
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic pop #pragma clang diagnostic pop
@ -24469,6 +24535,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#undef JSON_HAS_THREE_WAY_COMPARISON #undef JSON_HAS_THREE_WAY_COMPARISON
#undef JSON_HAS_RANGES #undef JSON_HAS_RANGES
#undef JSON_HAS_STATIC_RTTI
#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#endif #endif
@ -24482,6 +24549,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#undef JSON_HEDLEY_ALWAYS_INLINE #undef JSON_HEDLEY_ALWAYS_INLINE
#undef JSON_HEDLEY_ARM_VERSION #undef JSON_HEDLEY_ARM_VERSION
#undef JSON_HEDLEY_ARM_VERSION_CHECK #undef JSON_HEDLEY_ARM_VERSION_CHECK
@ -24632,4 +24700,5 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC
#undef JSON_HEDLEY_FALL_THROUGH #undef JSON_HEDLEY_FALL_THROUGH
#endif // INCLUDE_NLOHMANN_JSON_HPP_ #endif // INCLUDE_NLOHMANN_JSON_HPP_

View File

@ -25,6 +25,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// This file contains all macro definitions affecting or depending on the ABI // This file contains all macro definitions affecting or depending on the ABI
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13...3.14)
option(JSON_Valgrind "Execute test suite with Valgrind." OFF) option(JSON_Valgrind "Execute test suite with Valgrind." OFF)
option(JSON_FastTests "Skip expensive/slow tests." OFF) option(JSON_FastTests "Skip expensive/slow tests." OFF)

View File

@ -5491,7 +5491,7 @@ struct wide_string_input_helper<BaseInputAdapter, 2>
} }
}; };
// Wraps another input apdater to convert wide character types into individual bytes. // Wraps another input adapter to convert wide character types into individual bytes.
template<typename BaseInputAdapter, typename WideCharType> template<typename BaseInputAdapter, typename WideCharType>
class wide_string_input_adapter class wide_string_input_adapter
{ {

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.11) cmake_minimum_required(VERSION 3.11...3.14)
project(JSON_Benchmarks LANGUAGES CXX) project(JSON_Benchmarks LANGUAGES CXX)
# set compiler flags # set compiler flags

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.1...3.14)
project(DummyImport CXX) project(DummyImport CXX)

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.11) cmake_minimum_required(VERSION 3.11...3.14)
project(DummyImport CXX) project(DummyImport CXX)

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.1...3.14)
project(DummyImport CXX) project(DummyImport CXX)

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.1...3.14)
project(DummyImportMinVer CXX) project(DummyImportMinVer CXX)

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.1...3.14)
project(DummyImport CXX) project(DummyImport CXX)

View File

@ -45,7 +45,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
// step 2.1: round trip without adding size annotations to container types // step 2.1: round trip without adding size annotations to container types
std::vector<uint8_t> const vec2 = json::to_bjdata(j1, false, false); std::vector<uint8_t> const vec2 = json::to_bjdata(j1, false, false);
// step 2.2: round trip with adding size annotations but without adding type annonations to container types // step 2.2: round trip with adding size annotations but without adding type annotations to container types
std::vector<uint8_t> const vec3 = json::to_bjdata(j1, true, false); std::vector<uint8_t> const vec3 = json::to_bjdata(j1, true, false);
// step 2.3: round trip with adding size as well as type annotations to container types // step 2.3: round trip with adding size as well as type annotations to container types

View File

@ -45,7 +45,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
// step 2.1: round trip without adding size annotations to container types // step 2.1: round trip without adding size annotations to container types
std::vector<uint8_t> const vec2 = json::to_ubjson(j1, false, false); std::vector<uint8_t> const vec2 = json::to_ubjson(j1, false, false);
// step 2.2: round trip with adding size annotations but without adding type annonations to container types // step 2.2: round trip with adding size annotations but without adding type annotations to container types
std::vector<uint8_t> const vec3 = json::to_ubjson(j1, true, false); std::vector<uint8_t> const vec3 = json::to_ubjson(j1, true, false);
// step 2.3: round trip with adding size as well as type annotations to container types // step 2.3: round trip with adding size as well as type annotations to container types

View File

@ -339,13 +339,13 @@ TEST_CASE("BJData")
std::vector<int32_t> const numbers std::vector<int32_t> const numbers
{ {
-32769, -32769,
-100000, -100000,
-1000000, -1000000,
-10000000, -10000000,
-100000000, -100000000,
-1000000000, -1000000000,
-2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378
}; };
for (const auto i : numbers) for (const auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i)

View File

@ -562,7 +562,7 @@ TEST_CASE("BSON")
} }
} }
SECTION("Examples from http://bsonspec.org/faq.html") SECTION("Examples from https://bsonspec.org/faq.html")
{ {
SECTION("Example 1") SECTION("Example 1")
{ {

View File

@ -241,13 +241,13 @@ TEST_CASE("CBOR")
const std::vector<int64_t> numbers const std::vector<int64_t> numbers
{ {
-65537, -65537,
-100000, -100000,
-1000000, -1000000,
-10000000, -10000000,
-100000000, -100000000,
-1000000000, -1000000000,
-4294967296, -4294967296,
}; };
for (const auto i : numbers) for (const auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i)
@ -1962,7 +1962,7 @@ TEST_CASE("CBOR regressions")
CHECK(false); CHECK(false);
} }
} }
catch (const json::parse_error&) catch (const json::parse_error&) // NOLINT(bugprone-empty-catch)
{ {
// parse errors are ok, because input may be random bytes // parse errors are ok, because input may be random bytes
} }

View File

@ -542,13 +542,13 @@ TEST_CASE("parser class")
CHECK(parser_helper("9007199254740991").get<int64_t>() == 9007199254740991); CHECK(parser_helper("9007199254740991").get<int64_t>() == 9007199254740991);
} }
SECTION("over the edge cases") // issue #178 - Integer conversion to unsigned (incorrect handling of 64 bit integers) SECTION("over the edge cases") // issue #178 - Integer conversion to unsigned (incorrect handling of 64-bit integers)
{ {
// While RFC8259, Section 6 specifies a preference for support // While RFC8259, Section 6 specifies a preference for support
// for ranges in range of IEEE 754-2008 binary64 (double precision) // for ranges in range of IEEE 754-2008 binary64 (double precision)
// this does not accommodate 64 bit integers without loss of accuracy. // this does not accommodate 64-bit integers without loss of accuracy.
// As 64 bit integers are now widely used in software, it is desirable // As 64-bit integers are now widely used in software, it is desirable
// to expand support to to the full 64 bit (signed and unsigned) range // to expand support to the full 64 bit (signed and unsigned) range
// i.e. -(2**63) -> (2**64)-1. // i.e. -(2**63) -> (2**64)-1.
// -(2**63) ** Note: compilers see negative literals as negated positive numbers (hence the -1)) // -(2**63) ** Note: compilers see negative literals as negated positive numbers (hence the -1))
@ -822,7 +822,7 @@ TEST_CASE("parser class")
CHECK(accept_helper("9007199254740991")); CHECK(accept_helper("9007199254740991"));
} }
SECTION("over the edge cases") // issue #178 - Integer conversion to unsigned (incorrect handling of 64 bit integers) SECTION("over the edge cases") // issue #178 - Integer conversion to unsigned (incorrect handling of 64-bit integers)
{ {
// While RFC8259, Section 6 specifies a preference for support // While RFC8259, Section 6 specifies a preference for support
// for ranges in range of IEEE 754-2008 binary64 (double precision) // for ranges in range of IEEE 754-2008 binary64 (double precision)

View File

@ -1521,9 +1521,9 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
CHECK(j.value("foo", cpstr) == "bar"); CHECK(j.value("foo", cpstr) == "bar");
CHECK(j.value("foo", castr) == "bar"); CHECK(j.value("foo", castr) == "bar");
CHECK(j.value("foo", str) == "bar"); CHECK(j.value("foo", str) == "bar");
// this test is in fact different than the one below, // this test is in fact different from the one below,
// because of 0 considering const char * overloads // because of 0 considering const char * overloads
// where as any other number does not // whereas any other number does not
CHECK(j.value("baz", 0) == 42); CHECK(j.value("baz", 0) == 42);
CHECK(j.value("baz", 47) == 42); CHECK(j.value("baz", 47) == 42);
CHECK(j.value("baz", integer) == 42); CHECK(j.value("baz", integer) == 42);

View File

@ -123,8 +123,7 @@ TEST_CASE("JSON pointers")
CHECK(j.contains(json::json_pointer("/a~1b"))); CHECK(j.contains(json::json_pointer("/a~1b")));
CHECK(j.contains(json::json_pointer("/m~0n"))); CHECK(j.contains(json::json_pointer("/m~0n")));
// unescaped access // unescaped access to nonexisting values yield object creation
// access to nonexisting values yield object creation
CHECK(!j.contains(json::json_pointer("/a/b"))); CHECK(!j.contains(json::json_pointer("/a/b")));
CHECK_NOTHROW(j[json::json_pointer("/a/b")] = 42); CHECK_NOTHROW(j[json::json_pointer("/a/b")] = 42);
CHECK(j.contains(json::json_pointer("/a/b"))); CHECK(j.contains(json::json_pointer("/a/b")));

View File

@ -479,11 +479,11 @@ TEST_CASE("MessagePack")
std::vector<int32_t> const numbers std::vector<int32_t> const numbers
{ {
-32769, -32769,
-65536, -65536,
-77777, -77777,
-1048576, -1048576,
-2147483648LL, -2147483648LL,
}; };
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i)
@ -1124,7 +1124,7 @@ TEST_CASE("MessagePack")
// Checking against an expected vector byte by byte is // Checking against an expected vector byte by byte is
// difficult, because no assumption on the order of key/value // difficult, because no assumption on the order of key/value
// pairs are made. We therefore only check the prefix (type and // pairs are made. We therefore only check the prefix (type and
// size and the overall size. The rest is then handled in the // size) and the overall size. The rest is then handled in the
// roundtrip check. // roundtrip check.
CHECK(result.size() == 67); // 1 type, 2 size, 16*4 content CHECK(result.size() == 67); // 1 type, 2 size, 16*4 content
CHECK(result[0] == 0xde); // map 16 CHECK(result[0] == 0xde); // map 16
@ -1153,7 +1153,7 @@ TEST_CASE("MessagePack")
// Checking against an expected vector byte by byte is // Checking against an expected vector byte by byte is
// difficult, because no assumption on the order of key/value // difficult, because no assumption on the order of key/value
// pairs are made. We therefore only check the prefix (type and // pairs are made. We therefore only check the prefix (type and
// size and the overall size. The rest is then handled in the // size) and the overall size. The rest is then handled in the
// roundtrip check. // roundtrip check.
CHECK(result.size() == 458757); // 1 type, 4 size, 65536*7 content CHECK(result.size() == 458757); // 1 type, 4 size, 65536*7 content
CHECK(result[0] == 0xdf); // map 32 CHECK(result[0] == 0xdf); // map 32

View File

@ -51,7 +51,7 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-1")
const nlohmann::json j = Foo {1, 0}; const nlohmann::json j = Foo {1, 0};
std::cout << j.dump() << "\n"; std::cout << j.dump() << "\n";
} }
catch (...) catch (...) // NOLINT(bugprone-empty-catch)
{ {
// just ignore the exception in this POC // just ignore the exception in this POC
} }
@ -64,7 +64,7 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-2")
const nlohmann::json j = Foo {1, 1}; const nlohmann::json j = Foo {1, 1};
std::cout << j.dump() << "\n"; std::cout << j.dump() << "\n";
} }
catch (...) catch (...) // NOLINT(bugprone-empty-catch)
{ {
// just ignore the exception in this POC // just ignore the exception in this POC
} }
@ -77,7 +77,7 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-2")
const nlohmann::json j = Foo {1, 2}; const nlohmann::json j = Foo {1, 2};
std::cout << j.dump() << "\n"; std::cout << j.dump() << "\n";
} }
catch (...) catch (...) // NOLINT(bugprone-empty-catch)
{ {
// just ignore the exception in this POC // just ignore the exception in this POC
} }

View File

@ -442,7 +442,7 @@ TEST_CASE("Markus Kuhn's UTF-8 decoder capability and stress test")
SECTION("4.1 Examples of an overlong ASCII character") SECTION("4.1 Examples of an overlong ASCII character")
{ {
// With a safe UTF-8 decoder, all of the following five overlong // With a safe UTF-8 decoder, all the following five overlong
// representations of the ASCII character slash ("/") should be rejected // representations of the ASCII character slash ("/") should be rejected
// like a malformed UTF-8 sequence, for instance by substituting it with // like a malformed UTF-8 sequence, for instance by substituting it with
// a replacement character. If you see a slash below, you do not have a // a replacement character. If you see a slash below, you do not have a

View File

@ -393,7 +393,7 @@ template <
} }
/// swaps the contents /// swaps the contents
void swap(fifo_map& other) void swap(fifo_map& other) // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
{ {
std::swap(m_map, other.m_map); std::swap(m_map, other.m_map);
std::swap(m_compare, other.m_compare); std::swap(m_compare, other.m_compare);
@ -520,7 +520,7 @@ template <
namespace std // NOLINT(cert-dcl58-cpp,-warnings-as-errors) namespace std // NOLINT(cert-dcl58-cpp,-warnings-as-errors)
{ {
template <class Key, class T, class Compare, class Allocator> template <class Key, class T, class Compare, class Allocator>
inline void swap(nlohmann::fifo_map<Key, T, Compare, Allocator>& m1, // NOLINT(cert-dcl58-cpp) inline void swap(nlohmann::fifo_map<Key, T, Compare, Allocator>& m1, // NOLINT(cert-dcl58-cpp,cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
nlohmann::fifo_map<Key, T, Compare, Allocator>& m2) nlohmann::fifo_map<Key, T, Compare, Allocator>& m2)
{ {
m1.swap(m2); m1.swap(m2);