From cfd5a8131ba7a8877942171ab63c9911c96d58b0 Mon Sep 17 00:00:00 2001 From: Daniel Hwangbo Date: Sun, 30 Nov 2025 03:43:13 +0000 Subject: [PATCH 1/3] Fix json::update() with merge_objects==true error Signed-off-by: Daniel Hwangbo --- include/nlohmann/json.hpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index d4502a5c96..0eee39508a 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3478,16 +3478,30 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (it2 != m_data.m_value.object->end()) { it2->second.update(it.value(), true); + + // Repair the child's subtree. + #if JSON_DIAGNOSTICS + it2->second.set_parents(); + #endif continue; } } - m_data.m_value.object->operator[](it.key()) = it.value(); -#if JSON_DIAGNOSTICS - m_data.m_value.object->operator[](it.key()).m_parent = this; -#endif + + // Insert/Overwrite logic + auto& ref = m_data.m_value.object->operator[](it.key()); + ref = it.value(); + + // We must traverse the entire tree of 'this' and reset everyone's parent + // because the old pointers are now invalid. + #if JSON_DIAGNOSTICS + set_parents(); + #endif } + + #if JSON_DIAGNOSTICS + set_parents(); + #endif } - /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ void swap(reference other) noexcept ( From fb023fee1eba9b3f8155c5fced99e89b9711f4e0 Mon Sep 17 00:00:00 2001 From: Daniel Hwangbo Date: Sun, 30 Nov 2025 04:23:35 +0000 Subject: [PATCH 2/3] Add C++20 ranges constructor Signed-off-by: Daniel Hwangbo --- include/nlohmann/json.hpp | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 0eee39508a..cf7df47bc9 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1033,6 +1033,51 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } + //////////////////////////////////////////////////////////////////////////// + // PATCH START: C++20 Range Constructor (Strict Version) + //////////////////////////////////////////////////////////////////////////// + + /// @brief create a JSON value from a C++20 Range/View + /// @note This allows nlohmann::json j(myView) where myView has .begin()/.end() + /// @param[in] r range to read from + template ::type, basic_json>::value && + + // 2. It must not be a JSON reference + !detail::is_json_ref::value && + + // 3. CRITICAL FIX: It must NOT be a String. + // (Prevents ambiguity with the existing string constructor) + !std::is_constructible::type>::value && + + // 4. It must NOT be a type the library already supports (like std::vector) + !detail::is_compatible_type::type>::value, + + int>::type = 0, + + // 5. It MUST have .begin() and .end() + typename = decltype(std::declval().begin()), + typename = decltype(std::declval().end()) + > + basic_json(Range&& r) + { + // Construct an array from any range by converting each element + // to a `basic_json` and appending it. This avoids calling the + // iterator-pair constructor which only accepts internal json + // iterators and would be a mismatch for arbitrary ranges + // (for example, views from ). + m_data.m_type = value_t::array; + m_data.m_value.array = create(); + for (auto&& el : r) + { + m_data.m_value.array->emplace_back(el); + } + set_parents(); + assert_invariant(); + } + /// @brief construct a JSON container given an iterator range /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ template < class InputIT, typename std::enable_if < From 1cd971b90f155d3c98417253a2386f9e2b99ac06 Mon Sep 17 00:00:00 2001 From: Daniel Hwangbo Date: Sun, 7 Dec 2025 21:44:14 +0000 Subject: [PATCH 3/3] Fix amalgamate Signed-off-by: Daniel Hwangbo --- include/nlohmann/json.hpp | 328 +++++++++++++++++++------------------- 1 file changed, 164 insertions(+), 164 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index cf7df47bc9..673bfcb06f 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -338,7 +338,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec basic_json, default_object_comparator_t, AllocatorType>>; + basic_json >>>; /// @brief a type for an array /// @sa https://json.nlohmann.me/api/basic_json/array_t/ @@ -544,7 +544,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec json_value(array_t&& value) : array(create(std::move(value))) {} /// constructor for binary arrays - json_value(const typename binary_t::container_type& value) : binary(create(value)) {} + json_value(const typename binary_t::container_type & value) : binary(create(value)) {} /// constructor for rvalue binary arrays json_value(typename binary_t::container_type&& value) : binary(create(std::move(value))) {} @@ -1040,28 +1040,28 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief create a JSON value from a C++20 Range/View /// @note This allows nlohmann::json j(myView) where myView has .begin()/.end() /// @param[in] r range to read from - template ::type, basic_json>::value && - - // 2. It must not be a JSON reference - !detail::is_json_ref::value && - - // 3. CRITICAL FIX: It must NOT be a String. - // (Prevents ambiguity with the existing string constructor) - !std::is_constructible::type>::value && - - // 4. It must NOT be a type the library already supports (like std::vector) - !detail::is_compatible_type::type>::value, - - int>::type = 0, - - // 5. It MUST have .begin() and .end() - typename = decltype(std::declval().begin()), - typename = decltype(std::declval().end()) - > - basic_json(Range&& r) + template < typename Range, + typename std::enable_if < + // 1. It must not be a basic_json object itself + !std::is_same::type, basic_json>::value && + + // 2. It must not be a JSON reference + !detail::is_json_ref::value && + + // 3. CRITICAL FIX: It must NOT be a String. + // (Prevents ambiguity with the existing string constructor) + !std::is_constructible::type>::value && + + // 4. It must NOT be a type the library already supports (like std::vector) + !detail::is_compatible_type::type>::value, + + int >::type = 0, + + // 5. It MUST have .begin() and .end() + typename = decltype(std::declval().begin()), + typename = decltype(std::declval().end()) + > + basic_json(Range && r) { // Construct an array from any range by converting each element // to a `basic_json` and appending it. This avoids calling the @@ -1191,7 +1191,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec template, - std::is_same>::value, int> = 0 > + std::is_same>::value, int> = 0 > basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {} /// @brief copy constructor @@ -1955,18 +1955,18 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::negation>, detail::negation>, detail::negation>>, - detail::negation>, - detail::negation>, - detail::negation>>, + detail::negation>, + detail::negation>, + detail::negation>>, #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914)) - detail::negation>, + detail::negation>, #endif #if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI - detail::negation>, + detail::negation>, #endif - detail::is_detected_lazy - >::value, int >::type = 0 > - JSON_EXPLICIT operator ValueType() const + detail::is_detected_lazy + >::value, int >::type = 0 > + JSON_EXPLICIT operator ValueType() const { // delegate the call to get<>() const return get(); @@ -2282,12 +2282,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec private: template using is_comparable_with_object_key = detail::is_comparable < - object_comparator_t, const typename object_t::key_type&, KeyType >; + object_comparator_t, const typename object_t::key_type&, KeyType >; template using value_return_type = std::conditional < - detail::is_c_string_uncvref::value, - string_t, typename std::decay::type >; + detail::is_c_string_uncvref::value, + string_t, typename std::decay::type >; public: /// @brief access specified object element with default value @@ -3523,11 +3523,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (it2 != m_data.m_value.object->end()) { it2->second.update(it.value(), true); - + // Repair the child's subtree. - #if JSON_DIAGNOSTICS - it2->second.set_parents(); - #endif +#if JSON_DIAGNOSTICS + it2->second.set_parents(); +#endif continue; } } @@ -3535,17 +3535,17 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // Insert/Overwrite logic auto& ref = m_data.m_value.object->operator[](it.key()); ref = it.value(); - + // We must traverse the entire tree of 'this' and reset everyone's parent // because the old pointers are now invalid. - #if JSON_DIAGNOSTICS - set_parents(); - #endif - } - - #if JSON_DIAGNOSTICS +#if JSON_DIAGNOSTICS set_parents(); - #endif +#endif + } + +#if JSON_DIAGNOSTICS + set_parents(); +#endif } /// @brief exchanges the values /// @sa https://json.nlohmann.me/api/basic_json/swap/ @@ -4062,7 +4062,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #ifndef JSON_NO_IO /// @brief serialize to stream /// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/ - friend std::ostream& operator<<(std::ostream& o, const basic_json& j) + friend std::ostream & operator<<(std::ostream& o, const basic_json& j) { // read width member and use it as the indentation parameter if nonzero const bool pretty_print = o.width() > 0; @@ -4084,7 +4084,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// operator<<(std::ostream&, const basic_json&) instead; that is, /// replace calls like `j >> o;` with `o << j;`. 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) { return o << j; } @@ -4280,14 +4280,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// operator>>(std::istream&, basic_json&) instead; that is, /// replace calls like `j << i;` with `i >> j;`. 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) { return operator>>(i, j); } /// @brief deserialize from stream /// @sa https://json.nlohmann.me/api/basic_json/operator_gtgt/ - friend std::istream& operator>>(std::istream& i, basic_json& j) + friend std::istream & operator>>(std::istream& i, basic_json& j) { parser(detail::input_adapter(i)).parse(false, j); return i; @@ -4347,10 +4347,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { } - data(size_type cnt, const basic_json& val) + data(size_type cnt, const basic_json & val) : m_type(value_t::array) { - m_value.array = create(cnt, val); + m_value.array = create < array_t > (cnt, val); } data() noexcept = default; @@ -4399,133 +4399,133 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec public: /// @brief create a CBOR serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_cbor/ - static std::vector to_cbor(const basic_json& j) + static std::vector < std::uint8_t > to_cbor(const basic_json& j) { - std::vector result; + std::vector < std::uint8_t > result; to_cbor(j, result); return result; } /// @brief create a CBOR serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_cbor/ - static void to_cbor(const basic_json& j, detail::output_adapter o) + static void to_cbor(const basic_json& j, detail::output_adapter < std::uint8_t > o) { - binary_writer(o).write_cbor(j); + binary_writer < std::uint8_t > (o).write_cbor(j); } /// @brief create a CBOR serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_cbor/ - static void to_cbor(const basic_json& j, detail::output_adapter o) + static void to_cbor(const basic_json& j, detail::output_adapter < char > o) { - binary_writer(o).write_cbor(j); + binary_writer < char > (o).write_cbor(j); } /// @brief create a MessagePack serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/ - static std::vector to_msgpack(const basic_json& j) + static std::vector < std::uint8_t > to_msgpack(const basic_json& j) { - std::vector result; + std::vector < std::uint8_t > result; to_msgpack(j, result); return result; } /// @brief create a MessagePack serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/ - static void to_msgpack(const basic_json& j, detail::output_adapter o) + static void to_msgpack(const basic_json& j, detail::output_adapter < std::uint8_t > o) { - binary_writer(o).write_msgpack(j); + binary_writer < std::uint8_t > (o).write_msgpack(j); } /// @brief create a MessagePack serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/ - static void to_msgpack(const basic_json& j, detail::output_adapter o) + static void to_msgpack(const basic_json& j, detail::output_adapter < char > o) { - binary_writer(o).write_msgpack(j); + binary_writer < char > (o).write_msgpack(j); } /// @brief create a UBJSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ - static std::vector to_ubjson(const basic_json& j, + static std::vector < std::uint8_t > to_ubjson(const basic_json& j, const bool use_size = false, const bool use_type = false) { - std::vector result; + std::vector < std::uint8_t > result; to_ubjson(j, result, use_size, use_type); return result; } /// @brief create a UBJSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ - static void to_ubjson(const basic_json& j, detail::output_adapter o, + static void to_ubjson(const basic_json& j, detail::output_adapter < std::uint8_t > o, const bool use_size = false, const bool use_type = false) { - binary_writer(o).write_ubjson(j, use_size, use_type); + binary_writer < std::uint8_t > (o).write_ubjson(j, use_size, use_type); } /// @brief create a UBJSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ - static void to_ubjson(const basic_json& j, detail::output_adapter o, + static void to_ubjson(const basic_json& j, detail::output_adapter < char > o, const bool use_size = false, const bool use_type = false) { - binary_writer(o).write_ubjson(j, use_size, use_type); + binary_writer < char > (o).write_ubjson(j, use_size, use_type); } /// @brief create a BJData serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ - static std::vector to_bjdata(const basic_json& j, + static std::vector < std::uint8_t > to_bjdata(const basic_json& j, const bool use_size = false, const bool use_type = false, const bjdata_version_t version = bjdata_version_t::draft2) { - std::vector result; + std::vector < std::uint8_t > result; to_bjdata(j, result, use_size, use_type, version); return result; } /// @brief create a BJData serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ - static void to_bjdata(const basic_json& j, detail::output_adapter o, + static void to_bjdata(const basic_json& j, detail::output_adapter < std::uint8_t > o, const bool use_size = false, const bool use_type = false, const bjdata_version_t version = bjdata_version_t::draft2) { - binary_writer(o).write_ubjson(j, use_size, use_type, true, true, version); + binary_writer < std::uint8_t > (o).write_ubjson(j, use_size, use_type, true, true, version); } /// @brief create a BJData serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ - static void to_bjdata(const basic_json& j, detail::output_adapter o, + static void to_bjdata(const basic_json& j, detail::output_adapter < char > o, const bool use_size = false, const bool use_type = false, const bjdata_version_t version = bjdata_version_t::draft2) { - binary_writer(o).write_ubjson(j, use_size, use_type, true, true, version); + binary_writer < char > (o).write_ubjson(j, use_size, use_type, true, true, version); } /// @brief create a BSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bson/ - static std::vector to_bson(const basic_json& j) + static std::vector < std::uint8_t > to_bson(const basic_json& j) { - std::vector result; + std::vector < std::uint8_t > result; to_bson(j, result); return result; } /// @brief create a BSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bson/ - static void to_bson(const basic_json& j, detail::output_adapter o) + static void to_bson(const basic_json& j, detail::output_adapter < std::uint8_t > o) { - binary_writer(o).write_bson(j); + binary_writer < std::uint8_t > (o).write_bson(j); } /// @brief create a BSON serialization of a given JSON value /// @sa https://json.nlohmann.me/api/basic_json/to_bson/ - static void to_bson(const basic_json& j, detail::output_adapter o) + static void to_bson(const basic_json& j, detail::output_adapter < char > o) { - binary_writer(o).write_bson(j); + binary_writer < char > (o).write_bson(j); } /// @brief create a JSON value from an input in CBOR format /// @sa https://json.nlohmann.me/api/basic_json/from_cbor/ - template + template < typename InputType > JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_cbor(InputType&& i, const bool strict = true, @@ -4533,15 +4533,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) { basic_json result; - auto ia = detail::input_adapter(std::forward(i)); - detail::json_sax_dom_parser sdp(result, allow_exceptions); - const bool res = binary_reader(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved] + auto ia = detail::input_adapter(std::forward < InputType > (i)); + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } /// @brief create a JSON value from an input in CBOR format /// @sa https://json.nlohmann.me/api/basic_json/from_cbor/ - template + template < typename IteratorType > JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_cbor(IteratorType first, IteratorType last, const bool strict = true, @@ -4550,12 +4550,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; auto ia = detail::input_adapter(std::move(first), std::move(last)); - detail::json_sax_dom_parser sdp(result, allow_exceptions); - const bool res = binary_reader(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved] + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } - template + template < typename T > JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len)) static basic_json from_cbor(const T* ptr, std::size_t len, @@ -4575,30 +4575,30 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; auto ia = i.get(); - detail::json_sax_dom_parser sdp(result, allow_exceptions); + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - const bool res = binary_reader(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved] + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } /// @brief create a JSON value from an input in MessagePack format /// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/ - template + template < typename InputType > JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_msgpack(InputType&& i, const bool strict = true, const bool allow_exceptions = true) { basic_json result; - auto ia = detail::input_adapter(std::forward(i)); - detail::json_sax_dom_parser sdp(result, allow_exceptions); - const bool res = binary_reader(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved] + auto ia = detail::input_adapter(std::forward < InputType > (i)); + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } /// @brief create a JSON value from an input in MessagePack format /// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/ - template + template < typename IteratorType > JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_msgpack(IteratorType first, IteratorType last, const bool strict = true, @@ -4606,12 +4606,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; auto ia = detail::input_adapter(std::move(first), std::move(last)); - detail::json_sax_dom_parser sdp(result, allow_exceptions); - const bool res = binary_reader(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved] + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } - template + template < typename T > JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len)) static basic_json from_msgpack(const T* ptr, std::size_t len, @@ -4629,30 +4629,30 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; auto ia = i.get(); - detail::json_sax_dom_parser sdp(result, allow_exceptions); + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - const bool res = binary_reader(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved] + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } /// @brief create a JSON value from an input in UBJSON format /// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/ - template + template < typename InputType > JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_ubjson(InputType&& i, const bool strict = true, const bool allow_exceptions = true) { basic_json result; - auto ia = detail::input_adapter(std::forward(i)); - detail::json_sax_dom_parser sdp(result, allow_exceptions); - const bool res = binary_reader(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved] + auto ia = detail::input_adapter(std::forward < InputType > (i)); + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } /// @brief create a JSON value from an input in UBJSON format /// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/ - template + template < typename IteratorType > JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_ubjson(IteratorType first, IteratorType last, const bool strict = true, @@ -4660,12 +4660,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; auto ia = detail::input_adapter(std::move(first), std::move(last)); - detail::json_sax_dom_parser sdp(result, allow_exceptions); - const bool res = binary_reader(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved] + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } - template + template < typename T > JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len)) static basic_json from_ubjson(const T* ptr, std::size_t len, @@ -4683,30 +4683,30 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; auto ia = i.get(); - detail::json_sax_dom_parser sdp(result, allow_exceptions); + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - const bool res = binary_reader(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved] + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } /// @brief create a JSON value from an input in BJData format /// @sa https://json.nlohmann.me/api/basic_json/from_bjdata/ - template + template < typename InputType > JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bjdata(InputType&& i, const bool strict = true, const bool allow_exceptions = true) { basic_json result; - auto ia = detail::input_adapter(std::forward(i)); - detail::json_sax_dom_parser sdp(result, allow_exceptions); - const bool res = binary_reader(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); // cppcheck-suppress[accessMoved] + auto ia = detail::input_adapter(std::forward < InputType > (i)); + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } /// @brief create a JSON value from an input in BJData format /// @sa https://json.nlohmann.me/api/basic_json/from_bjdata/ - template + template < typename IteratorType > JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bjdata(IteratorType first, IteratorType last, const bool strict = true, @@ -4714,29 +4714,29 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; auto ia = detail::input_adapter(std::move(first), std::move(last)); - detail::json_sax_dom_parser sdp(result, allow_exceptions); - const bool res = binary_reader(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); // cppcheck-suppress[accessMoved] + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } /// @brief create a JSON value from an input in BSON format /// @sa https://json.nlohmann.me/api/basic_json/from_bson/ - template + template < typename InputType > JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bson(InputType&& i, const bool strict = true, const bool allow_exceptions = true) { basic_json result; - auto ia = detail::input_adapter(std::forward(i)); - detail::json_sax_dom_parser sdp(result, allow_exceptions); - const bool res = binary_reader(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved] + auto ia = detail::input_adapter(std::forward < InputType > (i)); + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } /// @brief create a JSON value from an input in BSON format /// @sa https://json.nlohmann.me/api/basic_json/from_bson/ - template + template < typename IteratorType > JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bson(IteratorType first, IteratorType last, const bool strict = true, @@ -4744,12 +4744,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; auto ia = detail::input_adapter(std::move(first), std::move(last)); - detail::json_sax_dom_parser sdp(result, allow_exceptions); - const bool res = binary_reader(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved] + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } - template + template < typename T > JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len)) static basic_json from_bson(const T* ptr, std::size_t len, @@ -4767,9 +4767,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; auto ia = i.get(); - detail::json_sax_dom_parser sdp(result, allow_exceptions); + detail::json_sax_dom_parser < basic_json, decltype(ia) > sdp(result, allow_exceptions); // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - const bool res = binary_reader(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved] + const bool res = binary_reader < decltype(ia) > (std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved] return res ? result : basic_json(value_t::discarded); } /// @} @@ -4788,9 +4788,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return ptr.get_unchecked(this); } - template::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) - reference operator[](const ::nlohmann::json_pointer& ptr) + template < typename BasicJsonType, detail::enable_if_t < detail::is_basic_json::value, int > = 0 > + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer < basic_json::string_t > ) // NOLINT(readability/alt_tokens) + reference operator[](const ::nlohmann::json_pointer < BasicJsonType > & ptr) { return ptr.get_unchecked(this); } @@ -4802,9 +4802,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return ptr.get_unchecked(this); } - template::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) - const_reference operator[](const ::nlohmann::json_pointer& ptr) const + template < typename BasicJsonType, detail::enable_if_t < detail::is_basic_json::value, int > = 0 > + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer < basic_json::string_t > ) // NOLINT(readability/alt_tokens) + const_reference operator[](const ::nlohmann::json_pointer < BasicJsonType > & ptr) const { return ptr.get_unchecked(this); } @@ -4816,9 +4816,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return ptr.get_checked(this); } - template::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) - reference at(const ::nlohmann::json_pointer& ptr) + template < typename BasicJsonType, detail::enable_if_t < detail::is_basic_json::value, int > = 0 > + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer < basic_json::string_t > ) // NOLINT(readability/alt_tokens) + reference at(const ::nlohmann::json_pointer < BasicJsonType > & ptr) { return ptr.get_checked(this); } @@ -4830,9 +4830,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return ptr.get_checked(this); } - template::value, int> = 0> - JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer) // NOLINT(readability/alt_tokens) - const_reference at(const ::nlohmann::json_pointer& ptr) const + template < typename BasicJsonType, detail::enable_if_t < detail::is_basic_json::value, int > = 0 > + JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer < basic_json::string_t > ) // NOLINT(readability/alt_tokens) + const_reference at(const ::nlohmann::json_pointer < BasicJsonType > & ptr) const { return ptr.get_checked(this); } @@ -4942,7 +4942,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } else { - const auto idx = json_pointer::template array_index(last_path); + const auto idx = json_pointer::template array_index < basic_json_t > (last_path); if (JSON_HEDLEY_UNLIKELY(idx > parent.size())) { // avoid undefined behavior @@ -4950,7 +4950,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } // default case: insert add offset - parent.insert(parent.begin() + static_cast(idx), val); + parent.insert(parent.begin() + static_cast < difference_type > (idx), val); } break; } @@ -4993,7 +4993,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec else if (parent.is_array()) { // note erase performs range check - parent.erase(json_pointer::template array_index(last_path)); + parent.erase(json_pointer::template array_index < basic_json_t > (last_path)); } }; @@ -5042,8 +5042,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } // collect mandatory members - const auto op = get_value("op", "op", true).template get(); - const auto path = get_value(op, "path", true).template get(); + const auto op = get_value("op", "op", true).template get < string_t > (); + const auto path = get_value(op, "path", true).template get < string_t > (); json_pointer ptr(path); switch (get_op(op)) @@ -5069,7 +5069,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec case patch_operations::move: { - const auto from_path = get_value("move", "from", true).template get(); + const auto from_path = get_value("move", "from", true).template get < string_t > (); json_pointer from_ptr(from_path); // the "from" location must exist - use at() @@ -5086,7 +5086,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec case patch_operations::copy: { - const auto from_path = get_value("copy", "from", true).template get(); + const auto from_path = get_value("copy", "from", true).template get < string_t > (); const json_pointer from_ptr(from_path); // the "from" location must exist - use at() @@ -5176,7 +5176,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec while (i < source.size() && i < target.size()) { // recursive call to compare array values at index i - auto temp_diff = diff(source[i], target[i], detail::concat(path, '/', detail::to_string(i))); + auto temp_diff = diff(source[i], target[i], detail::concat < string_t > (path, '/', detail::to_string < string_t > (i))); result.insert(result.end(), temp_diff.begin(), temp_diff.end()); ++i; } @@ -5185,7 +5185,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // in a second pass, traverse the remaining elements // remove my remaining elements - const auto end_index = static_cast(result.size()); + const auto end_index = static_cast < difference_type > (result.size()); while (i < source.size()) { // add operations in reverse order to avoid invalid @@ -5193,7 +5193,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec result.insert(result.begin() + end_index, object( { {"op", "remove"}, - {"path", detail::concat(path, '/', detail::to_string(i))} + {"path", detail::concat < string_t > (path, '/', detail::to_string < string_t > (i))} })); ++i; } @@ -5204,7 +5204,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec result.push_back( { {"op", "add"}, - {"path", detail::concat(path, "/-")}, + {"path", detail::concat < string_t > (path, "/-")}, {"value", target[i]} }); ++i; @@ -5219,7 +5219,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec for (auto it = source.cbegin(); it != source.cend(); ++it) { // escape the key name to be used in a JSON patch - const auto path_key = detail::concat(path, '/', detail::escape(it.key())); + const auto path_key = detail::concat < string_t > (path, '/', detail::escape(it.key())); if (target.find(it.key()) != target.end()) { @@ -5243,7 +5243,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (source.find(it.key()) == source.end()) { // found a key that is not in this -> add it - const auto path_key = detail::concat(path, '/', detail::escape(it.key())); + const auto path_key = detail::concat < string_t > (path, '/', detail::escape(it.key())); result.push_back( { {"op", "add"}, {"path", path_key}, @@ -5346,8 +5346,8 @@ JSON_HEDLEY_NON_NULL(1) JSON_HEDLEY_NON_NULL(1) inline nlohmann::json operator""_json(const char8_t* s, std::size_t n) { - return nlohmann::json::parse(reinterpret_cast(s), - reinterpret_cast(s) + n); + return nlohmann::json::parse(reinterpret_cast < const char* > (s), + reinterpret_cast < const char* > (s) + n); } #endif @@ -5367,7 +5367,7 @@ JSON_HEDLEY_NON_NULL(1) #if defined(__cpp_char8_t) inline nlohmann::json::json_pointer operator""_json_pointer(const char8_t* s, std::size_t n) { - return nlohmann::json::json_pointer(std::string(reinterpret_cast(s), n)); + return nlohmann::json::json_pointer(std::string(reinterpret_cast < const char* > (s), n)); } #endif @@ -5385,7 +5385,7 @@ namespace std // NOLINT(cert-dcl58-cpp) /// @brief hash value for JSON objects /// @sa https://json.nlohmann.me/api/basic_json/std_hash/ NLOHMANN_BASIC_JSON_TPL_DECLARATION -struct hash // NOLINT(cert-dcl58-cpp) +struct hash < nlohmann::NLOHMANN_BASIC_JSON_TPL > // NOLINT(cert-dcl58-cpp) { std::size_t operator()(const nlohmann::NLOHMANN_BASIC_JSON_TPL& j) const { @@ -5394,8 +5394,8 @@ struct hash // NOLINT(cert-dcl58-cpp) }; // specialization for std::less -template<> -struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679 +template < > +struct less < ::nlohmann::detail::value_t > // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679 { /*! @brief compare two value_t enum values @@ -5419,8 +5419,8 @@ struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', /// @sa https://json.nlohmann.me/api/basic_json/std_swap/ NLOHMANN_BASIC_JSON_TPL_DECLARATION inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) - is_nothrow_move_constructible::value&& // NOLINT(misc-redundant-expression,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) - is_nothrow_move_assignable::value) + is_nothrow_move_constructible < nlohmann::NLOHMANN_BASIC_JSON_TPL >::value&& // NOLINT(misc-redundant-expression,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) + is_nothrow_move_assignable < nlohmann::NLOHMANN_BASIC_JSON_TPL >::value) { j1.swap(j2); }