mirror of
https://github.com/nlohmann/json.git
synced 2026-10-05 22:20:30 +00:00
- binary_reader: cast the result of -1 - number back to number_integer_t,
because a number_integer_t narrower than int is promoted to int, which
GCC's -Warith-conversion rejects (ci_test_gcc, ci_test_standards_gcc)
- JSON_DELETE_DEPRECATED_FUNCTIONS: declare the deleted stream operators
as function templates at namespace scope, because GCC < 5 rejects deleted
friend functions ("can't initialize friend function") and Clang 7-9 report
a redefinition when a class template has a deleted friend function
- docs: give the examples of JSON_USE_OBJECTS_FOR_ENUM_KEYED_MAPS "Example:"
titles and add the page to the docset (style_check)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -250,6 +250,7 @@ INSERT INTO searchIndex(name, type, path) VALUES ('JSON_TRY_USER', 'Macro', 'api
|
|||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_GLOBAL_UDLS', 'Macro', 'api/macros/json_use_global_udls/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_GLOBAL_UDLS', 'Macro', 'api/macros/json_use_global_udls/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_IMPLICIT_CONVERSIONS', 'Macro', 'api/macros/json_use_implicit_conversions/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_IMPLICIT_CONVERSIONS', 'Macro', 'api/macros/json_use_implicit_conversions/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON', 'Macro', 'api/macros/json_use_legacy_discarded_value_comparison/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON', 'Macro', 'api/macros/json_use_legacy_discarded_value_comparison/index.html');
|
||||||
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_OBJECTS_FOR_ENUM_KEYED_MAPS', 'Macro', 'api/macros/json_use_objects_for_enum_keyed_maps/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_SIMDUTF', 'Macro', 'api/macros/json_use_simdutf/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_USE_SIMDUTF', 'Macro', 'api/macros/json_use_simdutf/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('Macros', 'Macro', 'api/macros/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('Macros', 'Macro', 'api/macros/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE', 'Macro', 'api/macros/nlohmann_define_derived_type/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE', 'Macro', 'api/macros/nlohmann_define_derived_type/index.html');
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example "Default behavior (macro not defined)"
|
??? example "Example: default behavior (macro not defined)"
|
||||||
|
|
||||||
Without the macro, a map with enum keys is stored as an array of pairs:
|
Without the macro, a map with enum keys is stored as an array of pairs:
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ The default value is `0` (disabled — existing behavior is preserved).
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
??? example "Objects for enum-keyed maps (macro defined to 1)"
|
??? example "Example: objects for enum-keyed maps (macro defined to 1)"
|
||||||
|
|
||||||
With the macro, the same map is stored as an object:
|
With the macro, the same map is stored as an object:
|
||||||
|
|
||||||
|
|||||||
@@ -662,10 +662,11 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the value is -1 - number, which fits into number_integer_t
|
// the value is -1 - number, which fits into number_integer_t
|
||||||
// whenever number does
|
// whenever number does; the outer cast undoes the integral promotion
|
||||||
|
// for number_integer_t types narrower than int
|
||||||
if (JSON_HEDLEY_LIKELY(value_in_range_of<number_integer_t>(number)))
|
if (JSON_HEDLEY_LIKELY(value_in_range_of<number_integer_t>(number)))
|
||||||
{
|
{
|
||||||
return sax->number_integer(static_cast<number_integer_t>(-1) - static_cast<number_integer_t>(number));
|
return sax->number_integer(conditional_static_cast<number_integer_t>(static_cast<number_integer_t>(-1) - static_cast<number_integer_t>(number)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// like the lexer does for JSON text, store a value too small for
|
// like the lexer does for JSON text, store a value too small for
|
||||||
|
|||||||
@@ -5319,6 +5319,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !JSON_DELETE_DEPRECATED_FUNCTIONS
|
||||||
|
// the deleted version is a function template after the class, because
|
||||||
|
// GCC < 5 and Clang < 10 reject deleted friend functions in class templates
|
||||||
/// @brief serialize to stream
|
/// @brief serialize to stream
|
||||||
/// @sa https://json.nlohmann.me/api/operator_ltlt/
|
/// @sa https://json.nlohmann.me/api/operator_ltlt/
|
||||||
/// @deprecated This function is deprecated since 3.0.0 and will be removed in
|
/// @deprecated This function is deprecated since 3.0.0 and will be removed in
|
||||||
@@ -5327,9 +5330,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
/// replace calls like `j >> o;` with `o << j;`.
|
/// replace calls like `j >> o;` with `o << j;`.
|
||||||
JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&))
|
JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&))
|
||||||
friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
|
friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
|
||||||
#if JSON_DELETE_DEPRECATED_FUNCTIONS
|
|
||||||
= delete;
|
|
||||||
#else
|
|
||||||
{
|
{
|
||||||
return o << j;
|
return o << j;
|
||||||
}
|
}
|
||||||
@@ -5507,6 +5507,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
#ifndef JSON_NO_IO
|
#ifndef JSON_NO_IO
|
||||||
|
#if !JSON_DELETE_DEPRECATED_FUNCTIONS
|
||||||
|
// the deleted version is a function template after the class, because
|
||||||
|
// GCC < 5 and Clang < 10 reject deleted friend functions in class templates
|
||||||
/// @brief deserialize from stream
|
/// @brief deserialize from stream
|
||||||
/// @sa https://json.nlohmann.me/api/operator_gtgt/
|
/// @sa https://json.nlohmann.me/api/operator_gtgt/
|
||||||
/// @deprecated This stream operator is deprecated since 3.0.0 and will be removed in
|
/// @deprecated This stream operator is deprecated since 3.0.0 and will be removed in
|
||||||
@@ -5515,9 +5518,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
/// replace calls like `j << i;` with `i >> j;`.
|
/// replace calls like `j << i;` with `i >> j;`.
|
||||||
JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&))
|
JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&))
|
||||||
friend std::istream& operator<<(basic_json& j, std::istream& i)
|
friend std::istream& operator<<(basic_json& j, std::istream& i)
|
||||||
#if JSON_DELETE_DEPRECATED_FUNCTIONS
|
|
||||||
= delete;
|
|
||||||
#else
|
|
||||||
{
|
{
|
||||||
return operator>>(i, j);
|
return operator>>(i, j);
|
||||||
}
|
}
|
||||||
@@ -7178,6 +7178,18 @@ std::string format_as(const NLOHMANN_BASIC_JSON_TPL& j)
|
|||||||
return j.dump();
|
return j.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if JSON_DELETE_DEPRECATED_FUNCTIONS && !defined(JSON_NO_IO)
|
||||||
|
/// @brief serialize to stream (deleted; use operator<<(std::ostream&, const basic_json&))
|
||||||
|
/// @sa https://json.nlohmann.me/api/operator_ltlt/
|
||||||
|
NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||||
|
std::ostream& operator>>(const NLOHMANN_BASIC_JSON_TPL& j, std::ostream& o) = delete;
|
||||||
|
|
||||||
|
/// @brief deserialize from stream (deleted; use operator>>(std::istream&, basic_json&))
|
||||||
|
/// @sa https://json.nlohmann.me/api/operator_gtgt/
|
||||||
|
NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||||
|
std::istream& operator<<(NLOHMANN_BASIC_JSON_TPL& j, std::istream& i) = delete;
|
||||||
|
#endif
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
|
|
||||||
///////////////////////
|
///////////////////////
|
||||||
|
|||||||
@@ -14353,10 +14353,11 @@ class binary_reader
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the value is -1 - number, which fits into number_integer_t
|
// the value is -1 - number, which fits into number_integer_t
|
||||||
// whenever number does
|
// whenever number does; the outer cast undoes the integral promotion
|
||||||
|
// for number_integer_t types narrower than int
|
||||||
if (JSON_HEDLEY_LIKELY(value_in_range_of<number_integer_t>(number)))
|
if (JSON_HEDLEY_LIKELY(value_in_range_of<number_integer_t>(number)))
|
||||||
{
|
{
|
||||||
return sax->number_integer(static_cast<number_integer_t>(-1) - static_cast<number_integer_t>(number));
|
return sax->number_integer(conditional_static_cast<number_integer_t>(static_cast<number_integer_t>(-1) - static_cast<number_integer_t>(number)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// like the lexer does for JSON text, store a value too small for
|
// like the lexer does for JSON text, store a value too small for
|
||||||
@@ -32469,6 +32470,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !JSON_DELETE_DEPRECATED_FUNCTIONS
|
||||||
|
// the deleted version is a function template after the class, because
|
||||||
|
// GCC < 5 and Clang < 10 reject deleted friend functions in class templates
|
||||||
/// @brief serialize to stream
|
/// @brief serialize to stream
|
||||||
/// @sa https://json.nlohmann.me/api/operator_ltlt/
|
/// @sa https://json.nlohmann.me/api/operator_ltlt/
|
||||||
/// @deprecated This function is deprecated since 3.0.0 and will be removed in
|
/// @deprecated This function is deprecated since 3.0.0 and will be removed in
|
||||||
@@ -32477,9 +32481,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
/// replace calls like `j >> o;` with `o << j;`.
|
/// replace calls like `j >> o;` with `o << j;`.
|
||||||
JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&))
|
JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&))
|
||||||
friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
|
friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
|
||||||
#if JSON_DELETE_DEPRECATED_FUNCTIONS
|
|
||||||
= delete;
|
|
||||||
#else
|
|
||||||
{
|
{
|
||||||
return o << j;
|
return o << j;
|
||||||
}
|
}
|
||||||
@@ -32657,6 +32658,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
#ifndef JSON_NO_IO
|
#ifndef JSON_NO_IO
|
||||||
|
#if !JSON_DELETE_DEPRECATED_FUNCTIONS
|
||||||
|
// the deleted version is a function template after the class, because
|
||||||
|
// GCC < 5 and Clang < 10 reject deleted friend functions in class templates
|
||||||
/// @brief deserialize from stream
|
/// @brief deserialize from stream
|
||||||
/// @sa https://json.nlohmann.me/api/operator_gtgt/
|
/// @sa https://json.nlohmann.me/api/operator_gtgt/
|
||||||
/// @deprecated This stream operator is deprecated since 3.0.0 and will be removed in
|
/// @deprecated This stream operator is deprecated since 3.0.0 and will be removed in
|
||||||
@@ -32665,9 +32669,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
/// replace calls like `j << i;` with `i >> j;`.
|
/// replace calls like `j << i;` with `i >> j;`.
|
||||||
JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&))
|
JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&))
|
||||||
friend std::istream& operator<<(basic_json& j, std::istream& i)
|
friend std::istream& operator<<(basic_json& j, std::istream& i)
|
||||||
#if JSON_DELETE_DEPRECATED_FUNCTIONS
|
|
||||||
= delete;
|
|
||||||
#else
|
|
||||||
{
|
{
|
||||||
return operator>>(i, j);
|
return operator>>(i, j);
|
||||||
}
|
}
|
||||||
@@ -34328,6 +34329,18 @@ std::string format_as(const NLOHMANN_BASIC_JSON_TPL& j)
|
|||||||
return j.dump();
|
return j.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if JSON_DELETE_DEPRECATED_FUNCTIONS && !defined(JSON_NO_IO)
|
||||||
|
/// @brief serialize to stream (deleted; use operator<<(std::ostream&, const basic_json&))
|
||||||
|
/// @sa https://json.nlohmann.me/api/operator_ltlt/
|
||||||
|
NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||||
|
std::ostream& operator>>(const NLOHMANN_BASIC_JSON_TPL& j, std::ostream& o) = delete;
|
||||||
|
|
||||||
|
/// @brief deserialize from stream (deleted; use operator>>(std::istream&, basic_json&))
|
||||||
|
/// @sa https://json.nlohmann.me/api/operator_gtgt/
|
||||||
|
NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||||
|
std::istream& operator<<(NLOHMANN_BASIC_JSON_TPL& j, std::istream& i) = delete;
|
||||||
|
#endif
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
|
|
||||||
///////////////////////
|
///////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user