From d21abfc35e37082b126e4623a3bdafe16a7d21b0 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Sat, 7 Oct 2023 15:26:14 +0200 Subject: [PATCH 01/14] Replace scalar type comparison restriction with one extended for compatible types. --- include/nlohmann/json.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index f7fac1fb40..2e733b5d23 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3694,9 +3694,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template - requires std::is_scalar_v - bool operator==(ScalarType rhs) const noexcept + template < typename CompatibleType, + typename U = detail::uncvref_t, + detail::enable_if_t < + !detail::is_basic_json::value && detail::is_compatible_type::value, int > = 0 > + bool operator==(CompatibleType rhs) const noexcept { return *this == basic_json(rhs); } From 1eb5d38f1cb3a5ec07014a839d77a18fbeeba4c7 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Sun, 8 Oct 2023 13:12:54 +0200 Subject: [PATCH 02/14] Create a concept for compatible types and use it instead of SFINAE. --- include/nlohmann/detail/meta/type_traits.hpp | 5 +++++ include/nlohmann/json.hpp | 7 ++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index d2788bbd7d..68f4f24341 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -684,6 +684,11 @@ inline constexpr bool value_in_range_of(T val) template using bool_constant = std::integral_constant; +#ifdef JSON_HAS_CPP_20 +template +concept CompatibleType = !is_basic_json>::value && is_compatible_type>::value; +#endif + /////////////////////////////////////////////////////////////////////////////// // is_c_string /////////////////////////////////////////////////////////////////////////////// diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 2e733b5d23..84d41ab98e 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3694,11 +3694,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template < typename CompatibleType, - typename U = detail::uncvref_t, - detail::enable_if_t < - !detail::is_basic_json::value && detail::is_compatible_type::value, int > = 0 > - bool operator==(CompatibleType rhs) const noexcept + template T> + bool operator==(T rhs) const noexcept { return *this == basic_json(rhs); } From 4b37136030df426992791bdfe74b5c13243f835a Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Sun, 8 Oct 2023 13:27:34 +0200 Subject: [PATCH 03/14] Run amalgamate script --- include/nlohmann/detail/meta/type_traits.hpp | 4 +- single_include/nlohmann/json.hpp | 52 +++----------------- single_include/nlohmann/json_fwd.hpp | 1 - tests/src/unit-bjdata.cpp | 14 +++--- tests/src/unit-cbor.cpp | 14 +++--- tests/src/unit-msgpack.cpp | 10 ++-- 6 files changed, 28 insertions(+), 67 deletions(-) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 68f4f24341..9851de430e 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -685,8 +685,8 @@ template using bool_constant = std::integral_constant; #ifdef JSON_HAS_CPP_20 -template -concept CompatibleType = !is_basic_json>::value && is_compatible_type>::value; + template + concept CompatibleType = !is_basic_json>::value && is_compatible_type>::value; #endif /////////////////////////////////////////////////////////////////////////////// diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 14bc07d5fe..55c0cdfb87 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -41,7 +41,6 @@ // SPDX-License-Identifier: MIT - #include // #include @@ -54,7 +53,6 @@ // SPDX-License-Identifier: MIT - // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK @@ -156,7 +154,6 @@ // SPDX-License-Identifier: MIT - #include // transform #include // array #include // forward_list @@ -179,7 +176,6 @@ // SPDX-License-Identifier: MIT - #include // nullptr_t #include // exception #if JSON_DIAGNOSTICS @@ -199,7 +195,6 @@ // SPDX-License-Identifier: MIT - #include // array #include // size_t #include // uint8_t @@ -215,7 +210,6 @@ // SPDX-License-Identifier: MIT - #include // declval, pair // #include // __ _____ _____ _____ @@ -227,7 +221,6 @@ // SPDX-License-Identifier: MIT - #include // #include @@ -240,7 +233,6 @@ // SPDX-License-Identifier: MIT - // #include @@ -2940,7 +2932,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include @@ -3015,7 +3006,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // size_t // #include @@ -3058,7 +3048,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // array #include // size_t #include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type @@ -3231,7 +3220,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // numeric_limits #include // false_type, is_constructible, is_integral, is_same, true_type #include // declval @@ -3247,7 +3235,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // random_access_iterator_tag // #include @@ -3315,7 +3302,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include @@ -3335,7 +3321,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include @@ -4091,6 +4076,11 @@ inline constexpr bool value_in_range_of(T val) template using bool_constant = std::integral_constant; +#ifdef JSON_HAS_CPP_20 + template + concept CompatibleType = !is_basic_json>::value && is_compatible_type>::value; +#endif + /////////////////////////////////////////////////////////////////////////////// // is_c_string /////////////////////////////////////////////////////////////////////////////// @@ -4153,7 +4143,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // strlen #include // string #include // forward @@ -4539,7 +4528,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include @@ -4563,7 +4551,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include @@ -5069,7 +5056,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // copy #include // begin, end #include // string @@ -5089,7 +5075,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // size_t #include // input_iterator_tag #include // string, to_string @@ -5810,7 +5795,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // uint8_t, uint64_t #include // tie #include // move @@ -5922,7 +5906,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // uint8_t #include // size_t #include // hash @@ -6055,7 +6038,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // generate_n #include // array #include // ldexp @@ -6081,7 +6063,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // array #include // size_t #include // strlen @@ -6576,7 +6557,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include #include // string #include // move @@ -7308,7 +7288,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // array #include // localeconv #include // size_t @@ -8947,7 +8926,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // size_t #include // declval #include // string @@ -12099,7 +12077,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // isfinite #include // uint8_t #include // function @@ -12616,7 +12593,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include // #include @@ -12629,7 +12605,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // ptrdiff_t #include // numeric_limits @@ -12788,7 +12763,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next #include // conditional, is_const, remove_const @@ -13550,7 +13524,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // ptrdiff_t #include // reverse_iterator #include // declval @@ -13719,7 +13692,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // all_of #include // isdigit #include // errno, ERANGE @@ -14714,7 +14686,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include #include @@ -14806,7 +14777,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // reverse #include // array #include // map @@ -14832,7 +14802,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // copy #include // size_t #include // back_inserter @@ -16801,7 +16770,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // reverse, remove, fill, find, none_of #include // array #include // localeconv, lconv @@ -16826,7 +16794,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // array #include // signbit, isfinite #include // intN_t, uintN_t @@ -18921,7 +18888,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // equal_to, less #include // initializer_list #include // input_iterator_tag, iterator_traits @@ -22908,9 +22874,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template - requires std::is_scalar_v - bool operator==(ScalarType rhs) const noexcept + template T> + bool operator==(T rhs) const noexcept { return *this == basic_json(rhs); } @@ -24477,7 +24442,6 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC // SPDX-License-Identifier: MIT - // restore clang diagnostic settings #if defined(__clang__) #pragma clang diagnostic pop @@ -24522,7 +24486,6 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC // SPDX-License-Identifier: MIT - #undef JSON_HEDLEY_ALWAYS_INLINE #undef JSON_HEDLEY_ARM_VERSION #undef JSON_HEDLEY_ARM_VERSION_CHECK @@ -24673,5 +24636,4 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC #undef JSON_HEDLEY_FALL_THROUGH - #endif // INCLUDE_NLOHMANN_JSON_HPP_ diff --git a/single_include/nlohmann/json_fwd.hpp b/single_include/nlohmann/json_fwd.hpp index 98070dfc95..7a0c8a82ad 100644 --- a/single_include/nlohmann/json_fwd.hpp +++ b/single_include/nlohmann/json_fwd.hpp @@ -25,7 +25,6 @@ // SPDX-License-Identifier: MIT - // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 919ddf84fa..1aa3c22b0e 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -339,13 +339,13 @@ TEST_CASE("BJData") std::vector const numbers { -32769, - -100000, - -1000000, - -10000000, - -100000000, - -1000000000, - -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 - }; + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 + }; for (const auto i : numbers) { CAPTURE(i) diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index 0bf33e13d0..9e9f999aef 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -241,13 +241,13 @@ TEST_CASE("CBOR") const std::vector numbers { -65537, - -100000, - -1000000, - -10000000, - -100000000, - -1000000000, - -4294967296, - }; + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -4294967296, + }; for (const auto i : numbers) { CAPTURE(i) diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index ff4a25f4fb..1686cc4a54 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -479,11 +479,11 @@ TEST_CASE("MessagePack") std::vector const numbers { -32769, - -65536, - -77777, - -1048576, - -2147483648LL, - }; + -65536, + -77777, + -1048576, + -2147483648LL, + }; for (auto i : numbers) { CAPTURE(i) From 828bac981a1976c087038c8c8de26be98873f568 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Sun, 8 Oct 2023 13:56:55 +0200 Subject: [PATCH 04/14] Add check for comparison from left to right. --- tests/src/unit-comparison.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/src/unit-comparison.cpp b/tests/src/unit-comparison.cpp index 7f990d2526..37b51ff03e 100644 --- a/tests/src/unit-comparison.cpp +++ b/tests/src/unit-comparison.cpp @@ -356,6 +356,7 @@ TEST_CASE("lexicographical comparison operators") CAPTURE(i) CAPTURE(j) CHECK((j_values[i] == j_values[j]) == expected_eq[i][j]); + CHECK(expected_eq[i][j] == (j_values[i] == j_values[j])); } } From ca407117ed6b346005a4787252cdbb6a94161b93 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Mon, 9 Oct 2023 18:30:11 +0200 Subject: [PATCH 05/14] Try amalgamate again. There seems to be some issues or inconsistencies with the astyle version 3.2.1 from the AUR versus 3.2.1-build from apt: * --squeeze-lines is not defined in the one from Arch, so I had to comment that one out in order to make the amalgamate step run. * A bunch of files are affected by the amalgamate, which does not seem right. --- include/nlohmann/detail/exceptions.hpp | 2 +- .../detail/iterators/iterator_traits.hpp | 2 +- include/nlohmann/detail/meta/is_sax.hpp | 8 +- include/nlohmann/detail/meta/type_traits.hpp | 62 +- include/nlohmann/json.hpp | 16 +- include/nlohmann/ordered_map.hpp | 454 +++++++------- single_include/nlohmann/json.hpp | 582 ++++++++++-------- single_include/nlohmann/json_fwd.hpp | 1 + tests/src/unit-regression2.cpp | 2 +- tests/src/unit-testsuites.cpp | 4 +- tests/src/unit-to_chars.cpp | 10 +- 11 files changed, 593 insertions(+), 550 deletions(-) diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index c8c0a1373e..6edc81ca1c 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp @@ -115,7 +115,7 @@ class exception : public std::exception } auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, - [](const std::string & a, const std::string & b) + [](const std::string& a, const std::string& b) { return concat(a, '/', detail::escape(b)); }); diff --git a/include/nlohmann/detail/iterators/iterator_traits.hpp b/include/nlohmann/detail/iterators/iterator_traits.hpp index 34a20eee85..ce5fe27a12 100644 --- a/include/nlohmann/detail/iterators/iterator_traits.hpp +++ b/include/nlohmann/detail/iterators/iterator_traits.hpp @@ -43,7 +43,7 @@ struct iterator_traits template struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> - : iterator_types + : iterator_types { }; diff --git a/include/nlohmann/detail/meta/is_sax.hpp b/include/nlohmann/detail/meta/is_sax.hpp index 2150089632..2a7f437446 100644 --- a/include/nlohmann/detail/meta/is_sax.hpp +++ b/include/nlohmann/detail/meta/is_sax.hpp @@ -73,7 +73,7 @@ using parse_error_function_t = decltype(std::declval().parse_error( template struct is_sax { - private: + private: static_assert(is_basic_json::value, "BasicJsonType must be of type basic_json<...>"); @@ -84,7 +84,7 @@ struct is_sax using binary_t = typename BasicJsonType::binary_t; using exception_t = typename BasicJsonType::exception; - public: + public: static constexpr bool value = is_detected_exact::value && is_detected_exact::value && @@ -104,7 +104,7 @@ struct is_sax template struct is_sax_static_asserts { - private: + private: static_assert(is_basic_json::value, "BasicJsonType must be of type basic_json<...>"); @@ -115,7 +115,7 @@ struct is_sax_static_asserts using binary_t = typename BasicJsonType::binary_t; using exception_t = typename BasicJsonType::exception; - public: + public: static_assert(is_detected_exact::value, "Missing/invalid function: bool null()"); static_assert(is_detected_exact::value, diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 9851de430e..aa6054c8e3 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -190,7 +190,7 @@ template struct conjunction : std::true_type { }; template struct conjunction : B { }; template struct conjunction -: std::conditional(B::value), conjunction, B>::type {}; + : std::conditional(B::value), conjunction, B>::type {}; // https://en.cppreference.com/w/cpp/types/negation template struct negation : std::integral_constant < bool, !B::value > { }; @@ -203,19 +203,19 @@ struct is_default_constructible : std::is_default_constructible {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_constructible : std::is_constructible {}; @@ -238,10 +238,10 @@ struct is_iterator_traits : std::false_type {}; template struct is_iterator_traits> { - private: + private: using traits = iterator_traits; - public: + public: static constexpr auto value = is_detected::value && is_detected::value && @@ -253,7 +253,7 @@ struct is_iterator_traits> template struct is_range { - private: + private: using t_ref = typename std::add_lvalue_reference::type; using iterator = detected_t; @@ -265,7 +265,7 @@ struct is_range static constexpr auto is_iterator_begin = is_iterator_traits>::value; - public: + public: static constexpr bool value = !std::is_same::value && !std::is_same::value && is_iterator_begin; }; @@ -307,7 +307,7 @@ struct is_compatible_object_type_impl < template struct is_compatible_object_type - : is_compatible_object_type_impl {}; + : is_compatible_object_type_impl {}; template @@ -339,8 +339,8 @@ struct is_constructible_object_type_impl < template struct is_constructible_object_type - : is_constructible_object_type_impl {}; + : is_constructible_object_type_impl {}; template struct is_compatible_string_type @@ -386,7 +386,7 @@ struct is_compatible_array_type_impl < template struct is_compatible_array_type - : is_compatible_array_type_impl {}; + : is_compatible_array_type_impl {}; template struct is_constructible_array_type_impl : std::false_type {}; @@ -396,7 +396,7 @@ struct is_constructible_array_type_impl < BasicJsonType, ConstructibleArrayType, enable_if_t::value >> - : std::true_type {}; + : std::true_type {}; template struct is_constructible_array_type_impl < @@ -415,22 +415,22 @@ is_detected::value&& !std::is_same>::value&& is_complete_type < detected_t>::value >> -{ - using value_type = range_value_t; - - static constexpr bool value = - std::is_same::value || - has_from_json::value || - has_non_default_from_json < - BasicJsonType, - value_type >::value; -}; + { + using value_type = range_value_t; + + static constexpr bool value = + std::is_same::value || + has_from_json::value || + has_non_default_from_json < + BasicJsonType, + value_type >::value; + }; template struct is_constructible_array_type - : is_constructible_array_type_impl {}; + : is_constructible_array_type_impl {}; template @@ -456,8 +456,8 @@ struct is_compatible_integer_type_impl < template struct is_compatible_integer_type - : is_compatible_integer_type_impl {}; + : is_compatible_integer_type_impl {}; template struct is_compatible_type_impl: std::false_type {}; @@ -473,7 +473,7 @@ struct is_compatible_type_impl < template struct is_compatible_type - : is_compatible_type_impl {}; + : is_compatible_type_impl {}; template struct is_constructible_tuple : std::false_type {}; @@ -509,7 +509,7 @@ template struct is_comparable()(std::declval(), std::declval())), decltype(std::declval()(std::declval(), std::declval())) ->> : std::true_type {}; + >> : std::true_type {}; template using detect_is_transparent = typename T::is_transparent; diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 84d41ab98e..f2ab7e0038 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -4701,7 +4701,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // the valid JSON Patch operations enum class patch_operations {add, remove, replace, move, copy, test, invalid}; - const auto get_op = [](const std::string & op) + const auto get_op = [](const std::string& op) { if (op == "add") { @@ -4838,8 +4838,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec for (const auto& val : json_patch) { // wrapper to get a value for an operation - const auto get_value = [&val](const std::string & op, - const std::string & member, + const auto get_value = [&val](const std::string& op, + const std::string& member, bool string_type) -> basic_json & { // find value @@ -5216,14 +5216,14 @@ struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', */ bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept - { +{ #if JSON_HAS_THREE_WAY_COMPARISON - return std::is_lt(lhs <=> rhs); // *NOPAD* + return std::is_lt(lhs <=> rhs); // *NOPAD* #else - return ::nlohmann::detail::operator<(lhs, rhs); + return ::nlohmann::detail::operator<(lhs, rhs); #endif - } -}; +} + }; // C++20 prohibit function specialization in the std namespace. #ifndef JSON_HAS_CPP_20 diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 5d28cdf20b..1ba7b73116 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -27,333 +27,333 @@ NLOHMANN_JSON_NAMESPACE_BEGIN template , class Allocator = std::allocator>> struct ordered_map : std::vector, Allocator> -{ - using key_type = Key; - using mapped_type = T; - using Container = std::vector, Allocator>; - using iterator = typename Container::iterator; - using const_iterator = typename Container::const_iterator; - using size_type = typename Container::size_type; - using value_type = typename Container::value_type; + { + using key_type = Key; + using mapped_type = T; + using Container = std::vector, Allocator>; + using iterator = typename Container::iterator; + using const_iterator = typename Container::const_iterator; + using size_type = typename Container::size_type; + using value_type = typename Container::value_type; #ifdef JSON_HAS_CPP_14 - using key_compare = std::equal_to<>; + using key_compare = std::equal_to<>; #else - using key_compare = std::equal_to; + using key_compare = std::equal_to; #endif - // Explicit constructors instead of `using Container::Container` - // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) - ordered_map() noexcept(noexcept(Container())) : Container{} {} - explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} - template - ordered_map(It first, It last, const Allocator& alloc = Allocator()) - : Container{first, last, alloc} {} - ordered_map(std::initializer_list init, const Allocator& alloc = Allocator() ) - : Container{init, alloc} {} - - std::pair emplace(const key_type& key, T&& t) + // Explicit constructors instead of `using Container::Container` + // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) +ordered_map() noexcept(noexcept(Container())) : Container{} {} +explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} +template +ordered_map(It first, It last, const Allocator& alloc = Allocator()) +: Container{first, last, alloc} {} +ordered_map(std::initializer_list init, const Allocator& alloc = Allocator() ) +: Container{init, alloc} {} + +std::pair emplace(const key_type& key, T&& t) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return {it, false}; - } + return {it, false}; } - Container::emplace_back(key, std::forward(t)); - return {std::prev(this->end()), true}; } + Container::emplace_back(key, std::forward(t)); + return {std::prev(this->end()), true}; +} - template::value, int> = 0> - std::pair emplace(KeyType && key, T && t) +template::value, int> = 0> +std::pair emplace(KeyType && key, T && t) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return {it, false}; - } + return {it, false}; } - Container::emplace_back(std::forward(key), std::forward(t)); - return {std::prev(this->end()), true}; } + Container::emplace_back(std::forward(key), std::forward(t)); + return {std::prev(this->end()), true}; +} - T& operator[](const key_type& key) - { - return emplace(key, T{}).first->second; - } +T& operator[](const key_type& key) +{ + return emplace(key, T{}).first->second; +} - template::value, int> = 0> - T & operator[](KeyType && key) - { - return emplace(std::forward(key), T{}).first->second; - } +template::value, int> = 0> +T & operator[](KeyType && key) +{ + return emplace(std::forward(key), T{}).first->second; +} - const T& operator[](const key_type& key) const - { - return at(key); - } +const T& operator[](const key_type& key) const +{ + return at(key); +} - template::value, int> = 0> - const T & operator[](KeyType && key) const - { - return at(std::forward(key)); - } +template::value, int> = 0> +const T & operator[](KeyType && key) const +{ + return at(std::forward(key)); +} - T& at(const key_type& key) +T& at(const key_type& key) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it->second; - } + return it->second; } - - JSON_THROW(std::out_of_range("key not found")); } - template::value, int> = 0> - T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) + JSON_THROW(std::out_of_range("key not found")); +} + +template::value, int> = 0> +T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it->second; - } + return it->second; } - - JSON_THROW(std::out_of_range("key not found")); } - const T& at(const key_type& key) const + JSON_THROW(std::out_of_range("key not found")); +} + +const T& at(const key_type& key) const +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it->second; - } + return it->second; } - - JSON_THROW(std::out_of_range("key not found")); } - template::value, int> = 0> - const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) + JSON_THROW(std::out_of_range("key not found")); +} + +template::value, int> = 0> +const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it->second; - } + return it->second; } - - JSON_THROW(std::out_of_range("key not found")); } - size_type erase(const key_type& key) + JSON_THROW(std::out_of_range("key not found")); +} + +size_type erase(const key_type& key) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) { - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) - { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; - } - Container::pop_back(); - return 1; + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; } + Container::pop_back(); + return 1; } - return 0; } + return 0; +} - template::value, int> = 0> - size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +template::value, int> = 0> +size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) { - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) - { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; - } - Container::pop_back(); - return 1; + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; } + Container::pop_back(); + return 1; } - return 0; } + return 0; +} - iterator erase(iterator pos) - { - return erase(pos, std::next(pos)); - } +iterator erase(iterator pos) +{ + return erase(pos, std::next(pos)); +} - iterator erase(iterator first, iterator last) +iterator erase(iterator first, iterator last) +{ + if (first == last) { - if (first == last) - { - return first; - } + return first; + } - const auto elements_affected = std::distance(first, last); - const auto offset = std::distance(Container::begin(), first); + const auto elements_affected = std::distance(first, last); + const auto offset = std::distance(Container::begin(), first); - // This is the start situation. We need to delete elements_affected - // elements (3 in this example: e, f, g), and need to return an - // iterator past the last deleted element (h in this example). - // Note that offset is the distance from the start of the vector - // to first. We will need this later. + // This is the start situation. We need to delete elements_affected + // elements (3 in this example: e, f, g), and need to return an + // iterator past the last deleted element (h in this example). + // Note that offset is the distance from the start of the vector + // to first. We will need this later. - // [ a, b, c, d, e, f, g, h, i, j ] - // ^ ^ - // first last + // [ a, b, c, d, e, f, g, h, i, j ] + // ^ ^ + // first last - // Since we cannot move const Keys, we re-construct them in place. - // We start at first and re-construct (viz. copy) the elements from - // the back of the vector. Example for first iteration: + // Since we cannot move const Keys, we re-construct them in place. + // We start at first and re-construct (viz. copy) the elements from + // the back of the vector. Example for first iteration: - // ,--------. - // v | destroy e and re-construct with h - // [ a, b, c, d, e, f, g, h, i, j ] - // ^ ^ - // it it + elements_affected + // ,--------. + // v | destroy e and re-construct with h + // [ a, b, c, d, e, f, g, h, i, j ] + // ^ ^ + // it it + elements_affected - for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) - { - it->~value_type(); // destroy but keep allocation - new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it - } + for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) + { + it->~value_type(); // destroy but keep allocation + new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it + } - // [ a, b, c, d, h, i, j, h, i, j ] - // ^ ^ - // first last + // [ a, b, c, d, h, i, j, h, i, j ] + // ^ ^ + // first last - // remove the unneeded elements at the end of the vector - Container::resize(this->size() - static_cast(elements_affected)); + // remove the unneeded elements at the end of the vector + Container::resize(this->size() - static_cast(elements_affected)); - // [ a, b, c, d, h, i, j ] - // ^ ^ - // first last + // [ a, b, c, d, h, i, j ] + // ^ ^ + // first last - // first is now pointing past the last deleted element, but we cannot - // use this iterator, because it may have been invalidated by the - // resize call. Instead, we can return begin() + offset. - return Container::begin() + offset; - } + // first is now pointing past the last deleted element, but we cannot + // use this iterator, because it may have been invalidated by the + // resize call. Instead, we can return begin() + offset. + return Container::begin() + offset; +} - size_type count(const key_type& key) const +size_type count(const key_type& key) const +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return 1; - } + return 1; } - return 0; } + return 0; +} - template::value, int> = 0> - size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) +template::value, int> = 0> +size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return 1; - } + return 1; } - return 0; } + return 0; +} - iterator find(const key_type& key) +iterator find(const key_type& key) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it; - } + return it; } - return Container::end(); } + return Container::end(); +} - template::value, int> = 0> - iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +template::value, int> = 0> +iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it; - } + return it; } - return Container::end(); } + return Container::end(); +} - const_iterator find(const key_type& key) const +const_iterator find(const key_type& key) const +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it; - } + return it; } - return Container::end(); } + return Container::end(); +} - std::pair insert( value_type&& value ) - { - return emplace(value.first, std::move(value.second)); - } +std::pair insert( value_type&& value ) +{ + return emplace(value.first, std::move(value.second)); +} - std::pair insert( const value_type& value ) +std::pair insert( const value_type& value ) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, value.first)) { - if (m_compare(it->first, value.first)) - { - return {it, false}; - } + return {it, false}; } - Container::push_back(value); - return {--this->end(), true}; } + Container::push_back(value); + return {--this->end(), true}; +} - template - using require_input_iter = typename std::enable_if::iterator_category, - std::input_iterator_tag>::value>::type; +template +using require_input_iter = typename std::enable_if::iterator_category, + std::input_iterator_tag>::value>::type; - template> - void insert(InputIt first, InputIt last) +template> +void insert(InputIt first, InputIt last) +{ + for (auto it = first; it != last; ++it) { - for (auto it = first; it != last; ++it) - { - insert(*it); - } + insert(*it); } +} private: - JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); -}; +JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); + }; NLOHMANN_JSON_NAMESPACE_END diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 55c0cdfb87..a3191d5028 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -41,6 +41,7 @@ // SPDX-License-Identifier: MIT + #include // #include @@ -53,6 +54,7 @@ // SPDX-License-Identifier: MIT + // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK @@ -154,6 +156,7 @@ // SPDX-License-Identifier: MIT + #include // transform #include // array #include // forward_list @@ -176,6 +179,7 @@ // SPDX-License-Identifier: MIT + #include // nullptr_t #include // exception #if JSON_DIAGNOSTICS @@ -195,6 +199,7 @@ // SPDX-License-Identifier: MIT + #include // array #include // size_t #include // uint8_t @@ -210,6 +215,7 @@ // SPDX-License-Identifier: MIT + #include // declval, pair // #include // __ _____ _____ _____ @@ -221,6 +227,7 @@ // SPDX-License-Identifier: MIT + #include // #include @@ -233,6 +240,7 @@ // SPDX-License-Identifier: MIT + // #include @@ -2932,6 +2940,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include @@ -3006,6 +3015,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // size_t // #include @@ -3048,6 +3058,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // array #include // size_t #include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type @@ -3220,6 +3231,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // numeric_limits #include // false_type, is_constructible, is_integral, is_same, true_type #include // declval @@ -3235,6 +3247,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // random_access_iterator_tag // #include @@ -3273,7 +3286,7 @@ struct iterator_traits template struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> - : iterator_types + : iterator_types { }; @@ -3302,6 +3315,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include @@ -3321,6 +3335,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include @@ -3582,7 +3597,7 @@ template struct conjunction : std::true_type { }; template struct conjunction : B { }; template struct conjunction -: std::conditional(B::value), conjunction, B>::type {}; + : std::conditional(B::value), conjunction, B>::type {}; // https://en.cppreference.com/w/cpp/types/negation template struct negation : std::integral_constant < bool, !B::value > { }; @@ -3595,19 +3610,19 @@ struct is_default_constructible : std::is_default_constructible {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_constructible : std::is_constructible {}; @@ -3630,10 +3645,10 @@ struct is_iterator_traits : std::false_type {}; template struct is_iterator_traits> { - private: + private: using traits = iterator_traits; - public: + public: static constexpr auto value = is_detected::value && is_detected::value && @@ -3645,7 +3660,7 @@ struct is_iterator_traits> template struct is_range { - private: + private: using t_ref = typename std::add_lvalue_reference::type; using iterator = detected_t; @@ -3657,7 +3672,7 @@ struct is_range static constexpr auto is_iterator_begin = is_iterator_traits>::value; - public: + public: static constexpr bool value = !std::is_same::value && !std::is_same::value && is_iterator_begin; }; @@ -3699,7 +3714,7 @@ struct is_compatible_object_type_impl < template struct is_compatible_object_type - : is_compatible_object_type_impl {}; + : is_compatible_object_type_impl {}; template @@ -3731,8 +3746,8 @@ struct is_constructible_object_type_impl < template struct is_constructible_object_type - : is_constructible_object_type_impl {}; + : is_constructible_object_type_impl {}; template struct is_compatible_string_type @@ -3778,7 +3793,7 @@ struct is_compatible_array_type_impl < template struct is_compatible_array_type - : is_compatible_array_type_impl {}; + : is_compatible_array_type_impl {}; template struct is_constructible_array_type_impl : std::false_type {}; @@ -3788,7 +3803,7 @@ struct is_constructible_array_type_impl < BasicJsonType, ConstructibleArrayType, enable_if_t::value >> - : std::true_type {}; + : std::true_type {}; template struct is_constructible_array_type_impl < @@ -3807,22 +3822,22 @@ is_detected::value&& !std::is_same>::value&& is_complete_type < detected_t>::value >> -{ - using value_type = range_value_t; + { + using value_type = range_value_t; - static constexpr bool value = - std::is_same::value || - has_from_json::value || - has_non_default_from_json < - BasicJsonType, - value_type >::value; -}; + static constexpr bool value = + std::is_same::value || + has_from_json::value || + has_non_default_from_json < + BasicJsonType, + value_type >::value; + }; template struct is_constructible_array_type - : is_constructible_array_type_impl {}; + : is_constructible_array_type_impl {}; template @@ -3848,8 +3863,8 @@ struct is_compatible_integer_type_impl < template struct is_compatible_integer_type - : is_compatible_integer_type_impl {}; + : is_compatible_integer_type_impl {}; template struct is_compatible_type_impl: std::false_type {}; @@ -3865,7 +3880,7 @@ struct is_compatible_type_impl < template struct is_compatible_type - : is_compatible_type_impl {}; + : is_compatible_type_impl {}; template struct is_constructible_tuple : std::false_type {}; @@ -3901,7 +3916,7 @@ template struct is_comparable()(std::declval(), std::declval())), decltype(std::declval()(std::declval(), std::declval())) ->> : std::true_type {}; + >> : std::true_type {}; template using detect_is_transparent = typename T::is_transparent; @@ -4143,6 +4158,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // strlen #include // string #include // forward @@ -4373,7 +4389,7 @@ class exception : public std::exception } auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, - [](const std::string & a, const std::string & b) + [](const std::string& a, const std::string& b) { return concat(a, '/', detail::escape(b)); }); @@ -4528,6 +4544,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include @@ -4551,6 +4568,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include @@ -5056,6 +5074,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // copy #include // begin, end #include // string @@ -5075,6 +5094,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // size_t #include // input_iterator_tag #include // string, to_string @@ -5795,6 +5815,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // uint8_t, uint64_t #include // tie #include // move @@ -5906,6 +5927,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // uint8_t #include // size_t #include // hash @@ -6038,6 +6060,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // generate_n #include // array #include // ldexp @@ -6063,6 +6086,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // array #include // size_t #include // strlen @@ -6557,6 +6581,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include #include // string #include // move @@ -7288,6 +7313,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // array #include // localeconv #include // size_t @@ -8926,6 +8952,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // size_t #include // declval #include // string @@ -8994,7 +9021,7 @@ using parse_error_function_t = decltype(std::declval().parse_error( template struct is_sax { - private: + private: static_assert(is_basic_json::value, "BasicJsonType must be of type basic_json<...>"); @@ -9005,7 +9032,7 @@ struct is_sax using binary_t = typename BasicJsonType::binary_t; using exception_t = typename BasicJsonType::exception; - public: + public: static constexpr bool value = is_detected_exact::value && is_detected_exact::value && @@ -9025,7 +9052,7 @@ struct is_sax template struct is_sax_static_asserts { - private: + private: static_assert(is_basic_json::value, "BasicJsonType must be of type basic_json<...>"); @@ -9036,7 +9063,7 @@ struct is_sax_static_asserts using binary_t = typename BasicJsonType::binary_t; using exception_t = typename BasicJsonType::exception; - public: + public: static_assert(is_detected_exact::value, "Missing/invalid function: bool null()"); static_assert(is_detected_exact::value, @@ -12077,6 +12104,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // isfinite #include // uint8_t #include // function @@ -12593,6 +12621,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include // #include @@ -12605,6 +12634,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // ptrdiff_t #include // numeric_limits @@ -12763,6 +12793,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next #include // conditional, is_const, remove_const @@ -13524,6 +13555,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // ptrdiff_t #include // reverse_iterator #include // declval @@ -13692,6 +13724,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // all_of #include // isdigit #include // errno, ERANGE @@ -14686,6 +14719,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include #include @@ -14777,6 +14811,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // reverse #include // array #include // map @@ -14802,6 +14837,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // copy #include // size_t #include // back_inserter @@ -16770,6 +16806,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // reverse, remove, fill, find, none_of #include // array #include // localeconv, lconv @@ -16794,6 +16831,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // array #include // signbit, isfinite #include // intN_t, uintN_t @@ -18888,6 +18926,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // equal_to, less #include // initializer_list #include // input_iterator_tag, iterator_traits @@ -18909,334 +18948,334 @@ NLOHMANN_JSON_NAMESPACE_BEGIN template , class Allocator = std::allocator>> struct ordered_map : std::vector, Allocator> -{ - using key_type = Key; - using mapped_type = T; - using Container = std::vector, Allocator>; - using iterator = typename Container::iterator; - using const_iterator = typename Container::const_iterator; - using size_type = typename Container::size_type; - using value_type = typename Container::value_type; + { + using key_type = Key; + using mapped_type = T; + using Container = std::vector, Allocator>; + using iterator = typename Container::iterator; + using const_iterator = typename Container::const_iterator; + using size_type = typename Container::size_type; + using value_type = typename Container::value_type; #ifdef JSON_HAS_CPP_14 - using key_compare = std::equal_to<>; + using key_compare = std::equal_to<>; #else - using key_compare = std::equal_to; + using key_compare = std::equal_to; #endif - // Explicit constructors instead of `using Container::Container` - // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) - ordered_map() noexcept(noexcept(Container())) : Container{} {} - explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} - template - ordered_map(It first, It last, const Allocator& alloc = Allocator()) - : Container{first, last, alloc} {} - ordered_map(std::initializer_list init, const Allocator& alloc = Allocator() ) - : Container{init, alloc} {} + // Explicit constructors instead of `using Container::Container` + // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) +ordered_map() noexcept(noexcept(Container())) : Container{} {} +explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} +template +ordered_map(It first, It last, const Allocator& alloc = Allocator()) +: Container{first, last, alloc} {} +ordered_map(std::initializer_list init, const Allocator& alloc = Allocator() ) +: Container{init, alloc} {} - std::pair emplace(const key_type& key, T&& t) +std::pair emplace(const key_type& key, T&& t) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return {it, false}; - } + return {it, false}; } - Container::emplace_back(key, std::forward(t)); - return {std::prev(this->end()), true}; } + Container::emplace_back(key, std::forward(t)); + return {std::prev(this->end()), true}; +} - template::value, int> = 0> - std::pair emplace(KeyType && key, T && t) +template::value, int> = 0> +std::pair emplace(KeyType && key, T && t) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return {it, false}; - } + return {it, false}; } - Container::emplace_back(std::forward(key), std::forward(t)); - return {std::prev(this->end()), true}; } + Container::emplace_back(std::forward(key), std::forward(t)); + return {std::prev(this->end()), true}; +} - T& operator[](const key_type& key) - { - return emplace(key, T{}).first->second; - } +T& operator[](const key_type& key) +{ + return emplace(key, T{}).first->second; +} - template::value, int> = 0> - T & operator[](KeyType && key) - { - return emplace(std::forward(key), T{}).first->second; - } +template::value, int> = 0> +T & operator[](KeyType && key) +{ + return emplace(std::forward(key), T{}).first->second; +} - const T& operator[](const key_type& key) const - { - return at(key); - } +const T& operator[](const key_type& key) const +{ + return at(key); +} - template::value, int> = 0> - const T & operator[](KeyType && key) const - { - return at(std::forward(key)); - } +template::value, int> = 0> +const T & operator[](KeyType && key) const +{ + return at(std::forward(key)); +} - T& at(const key_type& key) +T& at(const key_type& key) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it->second; - } + return it->second; } - - JSON_THROW(std::out_of_range("key not found")); } - template::value, int> = 0> - T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) + JSON_THROW(std::out_of_range("key not found")); +} + +template::value, int> = 0> +T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it->second; - } + return it->second; } - - JSON_THROW(std::out_of_range("key not found")); } - const T& at(const key_type& key) const + JSON_THROW(std::out_of_range("key not found")); +} + +const T& at(const key_type& key) const +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it->second; - } + return it->second; } - - JSON_THROW(std::out_of_range("key not found")); } - template::value, int> = 0> - const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) + JSON_THROW(std::out_of_range("key not found")); +} + +template::value, int> = 0> +const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it->second; - } + return it->second; } - - JSON_THROW(std::out_of_range("key not found")); } - size_type erase(const key_type& key) + JSON_THROW(std::out_of_range("key not found")); +} + +size_type erase(const key_type& key) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) { - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) - { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; - } - Container::pop_back(); - return 1; + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; } + Container::pop_back(); + return 1; } - return 0; } + return 0; +} - template::value, int> = 0> - size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +template::value, int> = 0> +size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) { - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) - { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; - } - Container::pop_back(); - return 1; + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; } + Container::pop_back(); + return 1; } - return 0; } + return 0; +} - iterator erase(iterator pos) - { - return erase(pos, std::next(pos)); - } +iterator erase(iterator pos) +{ + return erase(pos, std::next(pos)); +} - iterator erase(iterator first, iterator last) +iterator erase(iterator first, iterator last) +{ + if (first == last) { - if (first == last) - { - return first; - } + return first; + } - const auto elements_affected = std::distance(first, last); - const auto offset = std::distance(Container::begin(), first); + const auto elements_affected = std::distance(first, last); + const auto offset = std::distance(Container::begin(), first); - // This is the start situation. We need to delete elements_affected - // elements (3 in this example: e, f, g), and need to return an - // iterator past the last deleted element (h in this example). - // Note that offset is the distance from the start of the vector - // to first. We will need this later. + // This is the start situation. We need to delete elements_affected + // elements (3 in this example: e, f, g), and need to return an + // iterator past the last deleted element (h in this example). + // Note that offset is the distance from the start of the vector + // to first. We will need this later. - // [ a, b, c, d, e, f, g, h, i, j ] - // ^ ^ - // first last + // [ a, b, c, d, e, f, g, h, i, j ] + // ^ ^ + // first last - // Since we cannot move const Keys, we re-construct them in place. - // We start at first and re-construct (viz. copy) the elements from - // the back of the vector. Example for first iteration: + // Since we cannot move const Keys, we re-construct them in place. + // We start at first and re-construct (viz. copy) the elements from + // the back of the vector. Example for first iteration: - // ,--------. - // v | destroy e and re-construct with h - // [ a, b, c, d, e, f, g, h, i, j ] - // ^ ^ - // it it + elements_affected + // ,--------. + // v | destroy e and re-construct with h + // [ a, b, c, d, e, f, g, h, i, j ] + // ^ ^ + // it it + elements_affected - for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) - { - it->~value_type(); // destroy but keep allocation - new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it - } + for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) + { + it->~value_type(); // destroy but keep allocation + new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it + } - // [ a, b, c, d, h, i, j, h, i, j ] - // ^ ^ - // first last + // [ a, b, c, d, h, i, j, h, i, j ] + // ^ ^ + // first last - // remove the unneeded elements at the end of the vector - Container::resize(this->size() - static_cast(elements_affected)); + // remove the unneeded elements at the end of the vector + Container::resize(this->size() - static_cast(elements_affected)); - // [ a, b, c, d, h, i, j ] - // ^ ^ - // first last + // [ a, b, c, d, h, i, j ] + // ^ ^ + // first last - // first is now pointing past the last deleted element, but we cannot - // use this iterator, because it may have been invalidated by the - // resize call. Instead, we can return begin() + offset. - return Container::begin() + offset; - } + // first is now pointing past the last deleted element, but we cannot + // use this iterator, because it may have been invalidated by the + // resize call. Instead, we can return begin() + offset. + return Container::begin() + offset; +} - size_type count(const key_type& key) const +size_type count(const key_type& key) const +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return 1; - } + return 1; } - return 0; } + return 0; +} - template::value, int> = 0> - size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) +template::value, int> = 0> +size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return 1; - } + return 1; } - return 0; } + return 0; +} - iterator find(const key_type& key) +iterator find(const key_type& key) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it; - } + return it; } - return Container::end(); } + return Container::end(); +} - template::value, int> = 0> - iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +template::value, int> = 0> +iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it; - } + return it; } - return Container::end(); } + return Container::end(); +} - const_iterator find(const key_type& key) const +const_iterator find(const key_type& key) const +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, key)) { - if (m_compare(it->first, key)) - { - return it; - } + return it; } - return Container::end(); } + return Container::end(); +} - std::pair insert( value_type&& value ) - { - return emplace(value.first, std::move(value.second)); - } +std::pair insert( value_type&& value ) +{ + return emplace(value.first, std::move(value.second)); +} - std::pair insert( const value_type& value ) +std::pair insert( const value_type& value ) +{ + for (auto it = this->begin(); it != this->end(); ++it) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, value.first)) { - if (m_compare(it->first, value.first)) - { - return {it, false}; - } + return {it, false}; } - Container::push_back(value); - return {--this->end(), true}; } + Container::push_back(value); + return {--this->end(), true}; +} - template - using require_input_iter = typename std::enable_if::iterator_category, - std::input_iterator_tag>::value>::type; +template +using require_input_iter = typename std::enable_if::iterator_category, + std::input_iterator_tag>::value>::type; - template> - void insert(InputIt first, InputIt last) +template> +void insert(InputIt first, InputIt last) +{ + for (auto it = first; it != last; ++it) { - for (auto it = first; it != last; ++it) - { - insert(*it); - } + insert(*it); } +} private: - JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); -}; +JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); + }; NLOHMANN_JSON_NAMESPACE_END @@ -23881,7 +23920,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // the valid JSON Patch operations enum class patch_operations {add, remove, replace, move, copy, test, invalid}; - const auto get_op = [](const std::string & op) + const auto get_op = [](const std::string& op) { if (op == "add") { @@ -24018,8 +24057,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec for (const auto& val : json_patch) { // wrapper to get a value for an operation - const auto get_value = [&val](const std::string & op, - const std::string & member, + const auto get_value = [&val](const std::string& op, + const std::string& member, bool string_type) -> basic_json & { // find value @@ -24396,14 +24435,14 @@ struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', */ bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept - { +{ #if JSON_HAS_THREE_WAY_COMPARISON - return std::is_lt(lhs <=> rhs); // *NOPAD* + return std::is_lt(lhs <=> rhs); // *NOPAD* #else - return ::nlohmann::detail::operator<(lhs, rhs); + return ::nlohmann::detail::operator<(lhs, rhs); #endif - } -}; +} + }; // C++20 prohibit function specialization in the std namespace. #ifndef JSON_HAS_CPP_20 @@ -24442,6 +24481,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC // SPDX-License-Identifier: MIT + // restore clang diagnostic settings #if defined(__clang__) #pragma clang diagnostic pop @@ -24486,6 +24526,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC // SPDX-License-Identifier: MIT + #undef JSON_HEDLEY_ALWAYS_INLINE #undef JSON_HEDLEY_ARM_VERSION #undef JSON_HEDLEY_ARM_VERSION_CHECK @@ -24636,4 +24677,5 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC #undef JSON_HEDLEY_FALL_THROUGH + #endif // INCLUDE_NLOHMANN_JSON_HPP_ diff --git a/single_include/nlohmann/json_fwd.hpp b/single_include/nlohmann/json_fwd.hpp index 7a0c8a82ad..98070dfc95 100644 --- a/single_include/nlohmann/json_fwd.hpp +++ b/single_include/nlohmann/json_fwd.hpp @@ -25,6 +25,7 @@ // SPDX-License-Identifier: MIT + // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index dbafb436ba..0fd9752527 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -88,7 +88,7 @@ struct Data Data() = default; Data(std::string a_, std::string b_) : a(std::move(a_)) - , b(std::move(b_)) + , b(std::move(b_)) {} std::string a{}; std::string b{}; diff --git a/tests/src/unit-testsuites.cpp b/tests/src/unit-testsuites.cpp index e0cc127b93..74413653c0 100644 --- a/tests/src/unit-testsuites.cpp +++ b/tests/src/unit-testsuites.cpp @@ -106,7 +106,7 @@ TEST_CASE("compliance tests from nativejson-benchmark") SECTION("doubles") { - auto TEST_DOUBLE = [](const std::string & json_string, const double expected) + auto TEST_DOUBLE = [](const std::string& json_string, const double expected) { CAPTURE(json_string) CAPTURE(expected) @@ -238,7 +238,7 @@ TEST_CASE("compliance tests from nativejson-benchmark") SECTION("strings") { - auto TEST_STRING = [](const std::string & json_string, const std::string & expected) + auto TEST_STRING = [](const std::string& json_string, const std::string& expected) { CAPTURE(json_string) CAPTURE(expected) diff --git a/tests/src/unit-to_chars.cpp b/tests/src/unit-to_chars.cpp index d9f75ea2ff..c68e58ddcc 100644 --- a/tests/src/unit-to_chars.cpp +++ b/tests/src/unit-to_chars.cpp @@ -126,7 +126,7 @@ TEST_CASE("digit gen") { SECTION("single precision") { - auto check_float = [](float number, const std::string & digits, int expected_exponent) + auto check_float = [](float number, const std::string& digits, int expected_exponent) { CAPTURE(number) CAPTURE(digits) @@ -190,7 +190,7 @@ TEST_CASE("digit gen") SECTION("double precision") { - auto check_double = [](double number, const std::string & digits, int expected_exponent) + auto check_double = [](double number, const std::string& digits, int expected_exponent) { CAPTURE(number) CAPTURE(digits) @@ -336,7 +336,7 @@ TEST_CASE("formatting") { SECTION("single precision") { - auto check_float = [](float number, const std::string & expected) + auto check_float = [](float number, const std::string& expected) { std::array buf{}; char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) @@ -396,7 +396,7 @@ TEST_CASE("formatting") SECTION("double precision") { - auto check_double = [](double number, const std::string & expected) + auto check_double = [](double number, const std::string& expected) { std::array buf{}; char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) @@ -456,7 +456,7 @@ TEST_CASE("formatting") SECTION("integer") { - auto check_integer = [](std::int64_t number, const std::string & expected) + auto check_integer = [](std::int64_t number, const std::string& expected) { const nlohmann::json j = number; CHECK(j.dump() == expected); From d4f959431555934c6e94f7c539dec84a70e8e4c3 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Mon, 9 Oct 2023 20:39:30 +0200 Subject: [PATCH 06/14] Revert "Try amalgamate again." This reverts commit ca407117ed6b346005a4787252cdbb6a94161b93. --- include/nlohmann/detail/exceptions.hpp | 2 +- .../detail/iterators/iterator_traits.hpp | 2 +- include/nlohmann/detail/meta/is_sax.hpp | 8 +- include/nlohmann/detail/meta/type_traits.hpp | 62 +- include/nlohmann/json.hpp | 16 +- include/nlohmann/ordered_map.hpp | 454 +++++++------- single_include/nlohmann/json.hpp | 582 ++++++++---------- single_include/nlohmann/json_fwd.hpp | 1 - tests/src/unit-regression2.cpp | 2 +- tests/src/unit-testsuites.cpp | 4 +- tests/src/unit-to_chars.cpp | 10 +- 11 files changed, 550 insertions(+), 593 deletions(-) diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index 6edc81ca1c..c8c0a1373e 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp @@ -115,7 +115,7 @@ class exception : public std::exception } auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, - [](const std::string& a, const std::string& b) + [](const std::string & a, const std::string & b) { return concat(a, '/', detail::escape(b)); }); diff --git a/include/nlohmann/detail/iterators/iterator_traits.hpp b/include/nlohmann/detail/iterators/iterator_traits.hpp index ce5fe27a12..34a20eee85 100644 --- a/include/nlohmann/detail/iterators/iterator_traits.hpp +++ b/include/nlohmann/detail/iterators/iterator_traits.hpp @@ -43,7 +43,7 @@ struct iterator_traits template struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> - : iterator_types + : iterator_types { }; diff --git a/include/nlohmann/detail/meta/is_sax.hpp b/include/nlohmann/detail/meta/is_sax.hpp index 2a7f437446..2150089632 100644 --- a/include/nlohmann/detail/meta/is_sax.hpp +++ b/include/nlohmann/detail/meta/is_sax.hpp @@ -73,7 +73,7 @@ using parse_error_function_t = decltype(std::declval().parse_error( template struct is_sax { - private: + private: static_assert(is_basic_json::value, "BasicJsonType must be of type basic_json<...>"); @@ -84,7 +84,7 @@ struct is_sax using binary_t = typename BasicJsonType::binary_t; using exception_t = typename BasicJsonType::exception; - public: + public: static constexpr bool value = is_detected_exact::value && is_detected_exact::value && @@ -104,7 +104,7 @@ struct is_sax template struct is_sax_static_asserts { - private: + private: static_assert(is_basic_json::value, "BasicJsonType must be of type basic_json<...>"); @@ -115,7 +115,7 @@ struct is_sax_static_asserts using binary_t = typename BasicJsonType::binary_t; using exception_t = typename BasicJsonType::exception; - public: + public: static_assert(is_detected_exact::value, "Missing/invalid function: bool null()"); static_assert(is_detected_exact::value, diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index aa6054c8e3..9851de430e 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -190,7 +190,7 @@ template struct conjunction : std::true_type { }; template struct conjunction : B { }; template struct conjunction - : std::conditional(B::value), conjunction, B>::type {}; +: std::conditional(B::value), conjunction, B>::type {}; // https://en.cppreference.com/w/cpp/types/negation template struct negation : std::integral_constant < bool, !B::value > { }; @@ -203,19 +203,19 @@ struct is_default_constructible : std::is_default_constructible {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_constructible : std::is_constructible {}; @@ -238,10 +238,10 @@ struct is_iterator_traits : std::false_type {}; template struct is_iterator_traits> { - private: + private: using traits = iterator_traits; - public: + public: static constexpr auto value = is_detected::value && is_detected::value && @@ -253,7 +253,7 @@ struct is_iterator_traits> template struct is_range { - private: + private: using t_ref = typename std::add_lvalue_reference::type; using iterator = detected_t; @@ -265,7 +265,7 @@ struct is_range static constexpr auto is_iterator_begin = is_iterator_traits>::value; - public: + public: static constexpr bool value = !std::is_same::value && !std::is_same::value && is_iterator_begin; }; @@ -307,7 +307,7 @@ struct is_compatible_object_type_impl < template struct is_compatible_object_type - : is_compatible_object_type_impl {}; + : is_compatible_object_type_impl {}; template @@ -339,8 +339,8 @@ struct is_constructible_object_type_impl < template struct is_constructible_object_type - : is_constructible_object_type_impl {}; + : is_constructible_object_type_impl {}; template struct is_compatible_string_type @@ -386,7 +386,7 @@ struct is_compatible_array_type_impl < template struct is_compatible_array_type - : is_compatible_array_type_impl {}; + : is_compatible_array_type_impl {}; template struct is_constructible_array_type_impl : std::false_type {}; @@ -396,7 +396,7 @@ struct is_constructible_array_type_impl < BasicJsonType, ConstructibleArrayType, enable_if_t::value >> - : std::true_type {}; + : std::true_type {}; template struct is_constructible_array_type_impl < @@ -415,22 +415,22 @@ is_detected::value&& !std::is_same>::value&& is_complete_type < detected_t>::value >> - { - using value_type = range_value_t; - - static constexpr bool value = - std::is_same::value || - has_from_json::value || - has_non_default_from_json < - BasicJsonType, - value_type >::value; - }; +{ + using value_type = range_value_t; + + static constexpr bool value = + std::is_same::value || + has_from_json::value || + has_non_default_from_json < + BasicJsonType, + value_type >::value; +}; template struct is_constructible_array_type - : is_constructible_array_type_impl {}; + : is_constructible_array_type_impl {}; template @@ -456,8 +456,8 @@ struct is_compatible_integer_type_impl < template struct is_compatible_integer_type - : is_compatible_integer_type_impl {}; + : is_compatible_integer_type_impl {}; template struct is_compatible_type_impl: std::false_type {}; @@ -473,7 +473,7 @@ struct is_compatible_type_impl < template struct is_compatible_type - : is_compatible_type_impl {}; + : is_compatible_type_impl {}; template struct is_constructible_tuple : std::false_type {}; @@ -509,7 +509,7 @@ template struct is_comparable()(std::declval(), std::declval())), decltype(std::declval()(std::declval(), std::declval())) - >> : std::true_type {}; +>> : std::true_type {}; template using detect_is_transparent = typename T::is_transparent; diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index f2ab7e0038..84d41ab98e 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -4701,7 +4701,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // the valid JSON Patch operations enum class patch_operations {add, remove, replace, move, copy, test, invalid}; - const auto get_op = [](const std::string& op) + const auto get_op = [](const std::string & op) { if (op == "add") { @@ -4838,8 +4838,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec for (const auto& val : json_patch) { // wrapper to get a value for an operation - const auto get_value = [&val](const std::string& op, - const std::string& member, + const auto get_value = [&val](const std::string & op, + const std::string & member, bool string_type) -> basic_json & { // find value @@ -5216,14 +5216,14 @@ struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', */ bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept -{ + { #if JSON_HAS_THREE_WAY_COMPARISON - return std::is_lt(lhs <=> rhs); // *NOPAD* + return std::is_lt(lhs <=> rhs); // *NOPAD* #else - return ::nlohmann::detail::operator<(lhs, rhs); + return ::nlohmann::detail::operator<(lhs, rhs); #endif -} - }; + } +}; // C++20 prohibit function specialization in the std namespace. #ifndef JSON_HAS_CPP_20 diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 1ba7b73116..5d28cdf20b 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -27,333 +27,333 @@ NLOHMANN_JSON_NAMESPACE_BEGIN template , class Allocator = std::allocator>> struct ordered_map : std::vector, Allocator> - { - using key_type = Key; - using mapped_type = T; - using Container = std::vector, Allocator>; - using iterator = typename Container::iterator; - using const_iterator = typename Container::const_iterator; - using size_type = typename Container::size_type; - using value_type = typename Container::value_type; +{ + using key_type = Key; + using mapped_type = T; + using Container = std::vector, Allocator>; + using iterator = typename Container::iterator; + using const_iterator = typename Container::const_iterator; + using size_type = typename Container::size_type; + using value_type = typename Container::value_type; #ifdef JSON_HAS_CPP_14 - using key_compare = std::equal_to<>; + using key_compare = std::equal_to<>; #else - using key_compare = std::equal_to; + using key_compare = std::equal_to; #endif - // Explicit constructors instead of `using Container::Container` - // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) -ordered_map() noexcept(noexcept(Container())) : Container{} {} -explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} -template -ordered_map(It first, It last, const Allocator& alloc = Allocator()) -: Container{first, last, alloc} {} -ordered_map(std::initializer_list init, const Allocator& alloc = Allocator() ) -: Container{init, alloc} {} - -std::pair emplace(const key_type& key, T&& t) -{ - for (auto it = this->begin(); it != this->end(); ++it) + // Explicit constructors instead of `using Container::Container` + // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) + ordered_map() noexcept(noexcept(Container())) : Container{} {} + explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} + template + ordered_map(It first, It last, const Allocator& alloc = Allocator()) + : Container{first, last, alloc} {} + ordered_map(std::initializer_list init, const Allocator& alloc = Allocator() ) + : Container{init, alloc} {} + + std::pair emplace(const key_type& key, T&& t) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return {it, false}; + if (m_compare(it->first, key)) + { + return {it, false}; + } } + Container::emplace_back(key, std::forward(t)); + return {std::prev(this->end()), true}; } - Container::emplace_back(key, std::forward(t)); - return {std::prev(this->end()), true}; -} -template::value, int> = 0> -std::pair emplace(KeyType && key, T && t) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + std::pair emplace(KeyType && key, T && t) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return {it, false}; + if (m_compare(it->first, key)) + { + return {it, false}; + } } + Container::emplace_back(std::forward(key), std::forward(t)); + return {std::prev(this->end()), true}; } - Container::emplace_back(std::forward(key), std::forward(t)); - return {std::prev(this->end()), true}; -} -T& operator[](const key_type& key) -{ - return emplace(key, T{}).first->second; -} + T& operator[](const key_type& key) + { + return emplace(key, T{}).first->second; + } -template::value, int> = 0> -T & operator[](KeyType && key) -{ - return emplace(std::forward(key), T{}).first->second; -} + template::value, int> = 0> + T & operator[](KeyType && key) + { + return emplace(std::forward(key), T{}).first->second; + } -const T& operator[](const key_type& key) const -{ - return at(key); -} + const T& operator[](const key_type& key) const + { + return at(key); + } -template::value, int> = 0> -const T & operator[](KeyType && key) const -{ - return at(std::forward(key)); -} + template::value, int> = 0> + const T & operator[](KeyType && key) const + { + return at(std::forward(key)); + } -T& at(const key_type& key) -{ - for (auto it = this->begin(); it != this->end(); ++it) + T& at(const key_type& key) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it->second; + if (m_compare(it->first, key)) + { + return it->second; + } } - } - JSON_THROW(std::out_of_range("key not found")); -} + JSON_THROW(std::out_of_range("key not found")); + } -template::value, int> = 0> -T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it->second; + if (m_compare(it->first, key)) + { + return it->second; + } } - } - JSON_THROW(std::out_of_range("key not found")); -} + JSON_THROW(std::out_of_range("key not found")); + } -const T& at(const key_type& key) const -{ - for (auto it = this->begin(); it != this->end(); ++it) + const T& at(const key_type& key) const { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it->second; + if (m_compare(it->first, key)) + { + return it->second; + } } - } - JSON_THROW(std::out_of_range("key not found")); -} + JSON_THROW(std::out_of_range("key not found")); + } -template::value, int> = 0> -const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it->second; + if (m_compare(it->first, key)) + { + return it->second; + } } - } - JSON_THROW(std::out_of_range("key not found")); -} + JSON_THROW(std::out_of_range("key not found")); + } -size_type erase(const key_type& key) -{ - for (auto it = this->begin(); it != this->end(); ++it) + size_type erase(const key_type& key) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) + if (m_compare(it->first, key)) { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) + { + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; + } + Container::pop_back(); + return 1; } - Container::pop_back(); - return 1; } + return 0; } - return 0; -} -template::value, int> = 0> -size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) + if (m_compare(it->first, key)) { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) + { + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; + } + Container::pop_back(); + return 1; } - Container::pop_back(); - return 1; } + return 0; } - return 0; -} -iterator erase(iterator pos) -{ - return erase(pos, std::next(pos)); -} - -iterator erase(iterator first, iterator last) -{ - if (first == last) + iterator erase(iterator pos) { - return first; + return erase(pos, std::next(pos)); } - const auto elements_affected = std::distance(first, last); - const auto offset = std::distance(Container::begin(), first); + iterator erase(iterator first, iterator last) + { + if (first == last) + { + return first; + } - // This is the start situation. We need to delete elements_affected - // elements (3 in this example: e, f, g), and need to return an - // iterator past the last deleted element (h in this example). - // Note that offset is the distance from the start of the vector - // to first. We will need this later. + const auto elements_affected = std::distance(first, last); + const auto offset = std::distance(Container::begin(), first); - // [ a, b, c, d, e, f, g, h, i, j ] - // ^ ^ - // first last + // This is the start situation. We need to delete elements_affected + // elements (3 in this example: e, f, g), and need to return an + // iterator past the last deleted element (h in this example). + // Note that offset is the distance from the start of the vector + // to first. We will need this later. - // Since we cannot move const Keys, we re-construct them in place. - // We start at first and re-construct (viz. copy) the elements from - // the back of the vector. Example for first iteration: + // [ a, b, c, d, e, f, g, h, i, j ] + // ^ ^ + // first last - // ,--------. - // v | destroy e and re-construct with h - // [ a, b, c, d, e, f, g, h, i, j ] - // ^ ^ - // it it + elements_affected + // Since we cannot move const Keys, we re-construct them in place. + // We start at first and re-construct (viz. copy) the elements from + // the back of the vector. Example for first iteration: - for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) - { - it->~value_type(); // destroy but keep allocation - new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it - } + // ,--------. + // v | destroy e and re-construct with h + // [ a, b, c, d, e, f, g, h, i, j ] + // ^ ^ + // it it + elements_affected - // [ a, b, c, d, h, i, j, h, i, j ] - // ^ ^ - // first last + for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) + { + it->~value_type(); // destroy but keep allocation + new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it + } - // remove the unneeded elements at the end of the vector - Container::resize(this->size() - static_cast(elements_affected)); + // [ a, b, c, d, h, i, j, h, i, j ] + // ^ ^ + // first last - // [ a, b, c, d, h, i, j ] - // ^ ^ - // first last + // remove the unneeded elements at the end of the vector + Container::resize(this->size() - static_cast(elements_affected)); - // first is now pointing past the last deleted element, but we cannot - // use this iterator, because it may have been invalidated by the - // resize call. Instead, we can return begin() + offset. - return Container::begin() + offset; -} + // [ a, b, c, d, h, i, j ] + // ^ ^ + // first last -size_type count(const key_type& key) const -{ - for (auto it = this->begin(); it != this->end(); ++it) + // first is now pointing past the last deleted element, but we cannot + // use this iterator, because it may have been invalidated by the + // resize call. Instead, we can return begin() + offset. + return Container::begin() + offset; + } + + size_type count(const key_type& key) const { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return 1; + if (m_compare(it->first, key)) + { + return 1; + } } + return 0; } - return 0; -} -template::value, int> = 0> -size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return 1; + if (m_compare(it->first, key)) + { + return 1; + } } + return 0; } - return 0; -} -iterator find(const key_type& key) -{ - for (auto it = this->begin(); it != this->end(); ++it) + iterator find(const key_type& key) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it; + if (m_compare(it->first, key)) + { + return it; + } } + return Container::end(); } - return Container::end(); -} -template::value, int> = 0> -iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it; + if (m_compare(it->first, key)) + { + return it; + } } + return Container::end(); } - return Container::end(); -} -const_iterator find(const key_type& key) const -{ - for (auto it = this->begin(); it != this->end(); ++it) + const_iterator find(const key_type& key) const { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it; + if (m_compare(it->first, key)) + { + return it; + } } + return Container::end(); } - return Container::end(); -} -std::pair insert( value_type&& value ) -{ - return emplace(value.first, std::move(value.second)); -} + std::pair insert( value_type&& value ) + { + return emplace(value.first, std::move(value.second)); + } -std::pair insert( const value_type& value ) -{ - for (auto it = this->begin(); it != this->end(); ++it) + std::pair insert( const value_type& value ) { - if (m_compare(it->first, value.first)) + for (auto it = this->begin(); it != this->end(); ++it) { - return {it, false}; + if (m_compare(it->first, value.first)) + { + return {it, false}; + } } + Container::push_back(value); + return {--this->end(), true}; } - Container::push_back(value); - return {--this->end(), true}; -} -template -using require_input_iter = typename std::enable_if::iterator_category, - std::input_iterator_tag>::value>::type; + template + using require_input_iter = typename std::enable_if::iterator_category, + std::input_iterator_tag>::value>::type; -template> -void insert(InputIt first, InputIt last) -{ - for (auto it = first; it != last; ++it) + template> + void insert(InputIt first, InputIt last) { - insert(*it); + for (auto it = first; it != last; ++it) + { + insert(*it); + } } -} private: -JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); - }; + JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); +}; NLOHMANN_JSON_NAMESPACE_END diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a3191d5028..55c0cdfb87 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -41,7 +41,6 @@ // SPDX-License-Identifier: MIT - #include // #include @@ -54,7 +53,6 @@ // SPDX-License-Identifier: MIT - // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK @@ -156,7 +154,6 @@ // SPDX-License-Identifier: MIT - #include // transform #include // array #include // forward_list @@ -179,7 +176,6 @@ // SPDX-License-Identifier: MIT - #include // nullptr_t #include // exception #if JSON_DIAGNOSTICS @@ -199,7 +195,6 @@ // SPDX-License-Identifier: MIT - #include // array #include // size_t #include // uint8_t @@ -215,7 +210,6 @@ // SPDX-License-Identifier: MIT - #include // declval, pair // #include // __ _____ _____ _____ @@ -227,7 +221,6 @@ // SPDX-License-Identifier: MIT - #include // #include @@ -240,7 +233,6 @@ // SPDX-License-Identifier: MIT - // #include @@ -2940,7 +2932,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include @@ -3015,7 +3006,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // size_t // #include @@ -3058,7 +3048,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // array #include // size_t #include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type @@ -3231,7 +3220,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // numeric_limits #include // false_type, is_constructible, is_integral, is_same, true_type #include // declval @@ -3247,7 +3235,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // random_access_iterator_tag // #include @@ -3286,7 +3273,7 @@ struct iterator_traits template struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> - : iterator_types + : iterator_types { }; @@ -3315,7 +3302,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include @@ -3335,7 +3321,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include @@ -3597,7 +3582,7 @@ template struct conjunction : std::true_type { }; template struct conjunction : B { }; template struct conjunction - : std::conditional(B::value), conjunction, B>::type {}; +: std::conditional(B::value), conjunction, B>::type {}; // https://en.cppreference.com/w/cpp/types/negation template struct negation : std::integral_constant < bool, !B::value > { }; @@ -3610,19 +3595,19 @@ struct is_default_constructible : std::is_default_constructible {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction, is_default_constructible> {}; + : conjunction, is_default_constructible> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_default_constructible> - : conjunction...> {}; + : conjunction...> {}; template struct is_constructible : std::is_constructible {}; @@ -3645,10 +3630,10 @@ struct is_iterator_traits : std::false_type {}; template struct is_iterator_traits> { - private: + private: using traits = iterator_traits; - public: + public: static constexpr auto value = is_detected::value && is_detected::value && @@ -3660,7 +3645,7 @@ struct is_iterator_traits> template struct is_range { - private: + private: using t_ref = typename std::add_lvalue_reference::type; using iterator = detected_t; @@ -3672,7 +3657,7 @@ struct is_range static constexpr auto is_iterator_begin = is_iterator_traits>::value; - public: + public: static constexpr bool value = !std::is_same::value && !std::is_same::value && is_iterator_begin; }; @@ -3714,7 +3699,7 @@ struct is_compatible_object_type_impl < template struct is_compatible_object_type - : is_compatible_object_type_impl {}; + : is_compatible_object_type_impl {}; template @@ -3746,8 +3731,8 @@ struct is_constructible_object_type_impl < template struct is_constructible_object_type - : is_constructible_object_type_impl {}; + : is_constructible_object_type_impl {}; template struct is_compatible_string_type @@ -3793,7 +3778,7 @@ struct is_compatible_array_type_impl < template struct is_compatible_array_type - : is_compatible_array_type_impl {}; + : is_compatible_array_type_impl {}; template struct is_constructible_array_type_impl : std::false_type {}; @@ -3803,7 +3788,7 @@ struct is_constructible_array_type_impl < BasicJsonType, ConstructibleArrayType, enable_if_t::value >> - : std::true_type {}; + : std::true_type {}; template struct is_constructible_array_type_impl < @@ -3822,22 +3807,22 @@ is_detected::value&& !std::is_same>::value&& is_complete_type < detected_t>::value >> - { - using value_type = range_value_t; +{ + using value_type = range_value_t; - static constexpr bool value = - std::is_same::value || - has_from_json::value || - has_non_default_from_json < - BasicJsonType, - value_type >::value; - }; + static constexpr bool value = + std::is_same::value || + has_from_json::value || + has_non_default_from_json < + BasicJsonType, + value_type >::value; +}; template struct is_constructible_array_type - : is_constructible_array_type_impl {}; + : is_constructible_array_type_impl {}; template @@ -3863,8 +3848,8 @@ struct is_compatible_integer_type_impl < template struct is_compatible_integer_type - : is_compatible_integer_type_impl {}; + : is_compatible_integer_type_impl {}; template struct is_compatible_type_impl: std::false_type {}; @@ -3880,7 +3865,7 @@ struct is_compatible_type_impl < template struct is_compatible_type - : is_compatible_type_impl {}; + : is_compatible_type_impl {}; template struct is_constructible_tuple : std::false_type {}; @@ -3916,7 +3901,7 @@ template struct is_comparable()(std::declval(), std::declval())), decltype(std::declval()(std::declval(), std::declval())) - >> : std::true_type {}; +>> : std::true_type {}; template using detect_is_transparent = typename T::is_transparent; @@ -4158,7 +4143,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // strlen #include // string #include // forward @@ -4389,7 +4373,7 @@ class exception : public std::exception } auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, - [](const std::string& a, const std::string& b) + [](const std::string & a, const std::string & b) { return concat(a, '/', detail::escape(b)); }); @@ -4544,7 +4528,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include @@ -4568,7 +4551,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include @@ -5074,7 +5056,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // copy #include // begin, end #include // string @@ -5094,7 +5075,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // size_t #include // input_iterator_tag #include // string, to_string @@ -5815,7 +5795,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // uint8_t, uint64_t #include // tie #include // move @@ -5927,7 +5906,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // uint8_t #include // size_t #include // hash @@ -6060,7 +6038,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // generate_n #include // array #include // ldexp @@ -6086,7 +6063,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // array #include // size_t #include // strlen @@ -6581,7 +6557,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include #include // string #include // move @@ -7313,7 +7288,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // array #include // localeconv #include // size_t @@ -8952,7 +8926,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // size_t #include // declval #include // string @@ -9021,7 +8994,7 @@ using parse_error_function_t = decltype(std::declval().parse_error( template struct is_sax { - private: + private: static_assert(is_basic_json::value, "BasicJsonType must be of type basic_json<...>"); @@ -9032,7 +9005,7 @@ struct is_sax using binary_t = typename BasicJsonType::binary_t; using exception_t = typename BasicJsonType::exception; - public: + public: static constexpr bool value = is_detected_exact::value && is_detected_exact::value && @@ -9052,7 +9025,7 @@ struct is_sax template struct is_sax_static_asserts { - private: + private: static_assert(is_basic_json::value, "BasicJsonType must be of type basic_json<...>"); @@ -9063,7 +9036,7 @@ struct is_sax_static_asserts using binary_t = typename BasicJsonType::binary_t; using exception_t = typename BasicJsonType::exception; - public: + public: static_assert(is_detected_exact::value, "Missing/invalid function: bool null()"); static_assert(is_detected_exact::value, @@ -12104,7 +12077,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // isfinite #include // uint8_t #include // function @@ -12621,7 +12593,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - // #include // #include @@ -12634,7 +12605,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // ptrdiff_t #include // numeric_limits @@ -12793,7 +12763,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next #include // conditional, is_const, remove_const @@ -13555,7 +13524,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // ptrdiff_t #include // reverse_iterator #include // declval @@ -13724,7 +13692,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // all_of #include // isdigit #include // errno, ERANGE @@ -14719,7 +14686,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include #include @@ -14811,7 +14777,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // reverse #include // array #include // map @@ -14837,7 +14802,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // copy #include // size_t #include // back_inserter @@ -16806,7 +16770,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // reverse, remove, fill, find, none_of #include // array #include // localeconv, lconv @@ -16831,7 +16794,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // array #include // signbit, isfinite #include // intN_t, uintN_t @@ -18926,7 +18888,6 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT - #include // equal_to, less #include // initializer_list #include // input_iterator_tag, iterator_traits @@ -18948,334 +18909,334 @@ NLOHMANN_JSON_NAMESPACE_BEGIN template , class Allocator = std::allocator>> struct ordered_map : std::vector, Allocator> - { - using key_type = Key; - using mapped_type = T; - using Container = std::vector, Allocator>; - using iterator = typename Container::iterator; - using const_iterator = typename Container::const_iterator; - using size_type = typename Container::size_type; - using value_type = typename Container::value_type; +{ + using key_type = Key; + using mapped_type = T; + using Container = std::vector, Allocator>; + using iterator = typename Container::iterator; + using const_iterator = typename Container::const_iterator; + using size_type = typename Container::size_type; + using value_type = typename Container::value_type; #ifdef JSON_HAS_CPP_14 - using key_compare = std::equal_to<>; + using key_compare = std::equal_to<>; #else - using key_compare = std::equal_to; + using key_compare = std::equal_to; #endif - // Explicit constructors instead of `using Container::Container` - // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) -ordered_map() noexcept(noexcept(Container())) : Container{} {} -explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} -template -ordered_map(It first, It last, const Allocator& alloc = Allocator()) -: Container{first, last, alloc} {} -ordered_map(std::initializer_list init, const Allocator& alloc = Allocator() ) -: Container{init, alloc} {} + // Explicit constructors instead of `using Container::Container` + // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) + ordered_map() noexcept(noexcept(Container())) : Container{} {} + explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} + template + ordered_map(It first, It last, const Allocator& alloc = Allocator()) + : Container{first, last, alloc} {} + ordered_map(std::initializer_list init, const Allocator& alloc = Allocator() ) + : Container{init, alloc} {} -std::pair emplace(const key_type& key, T&& t) -{ - for (auto it = this->begin(); it != this->end(); ++it) + std::pair emplace(const key_type& key, T&& t) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return {it, false}; + if (m_compare(it->first, key)) + { + return {it, false}; + } } + Container::emplace_back(key, std::forward(t)); + return {std::prev(this->end()), true}; } - Container::emplace_back(key, std::forward(t)); - return {std::prev(this->end()), true}; -} -template::value, int> = 0> -std::pair emplace(KeyType && key, T && t) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + std::pair emplace(KeyType && key, T && t) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return {it, false}; + if (m_compare(it->first, key)) + { + return {it, false}; + } } + Container::emplace_back(std::forward(key), std::forward(t)); + return {std::prev(this->end()), true}; } - Container::emplace_back(std::forward(key), std::forward(t)); - return {std::prev(this->end()), true}; -} -T& operator[](const key_type& key) -{ - return emplace(key, T{}).first->second; -} + T& operator[](const key_type& key) + { + return emplace(key, T{}).first->second; + } -template::value, int> = 0> -T & operator[](KeyType && key) -{ - return emplace(std::forward(key), T{}).first->second; -} + template::value, int> = 0> + T & operator[](KeyType && key) + { + return emplace(std::forward(key), T{}).first->second; + } -const T& operator[](const key_type& key) const -{ - return at(key); -} + const T& operator[](const key_type& key) const + { + return at(key); + } -template::value, int> = 0> -const T & operator[](KeyType && key) const -{ - return at(std::forward(key)); -} + template::value, int> = 0> + const T & operator[](KeyType && key) const + { + return at(std::forward(key)); + } -T& at(const key_type& key) -{ - for (auto it = this->begin(); it != this->end(); ++it) + T& at(const key_type& key) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it->second; + if (m_compare(it->first, key)) + { + return it->second; + } } - } - JSON_THROW(std::out_of_range("key not found")); -} + JSON_THROW(std::out_of_range("key not found")); + } -template::value, int> = 0> -T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it->second; + if (m_compare(it->first, key)) + { + return it->second; + } } - } - JSON_THROW(std::out_of_range("key not found")); -} + JSON_THROW(std::out_of_range("key not found")); + } -const T& at(const key_type& key) const -{ - for (auto it = this->begin(); it != this->end(); ++it) + const T& at(const key_type& key) const { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it->second; + if (m_compare(it->first, key)) + { + return it->second; + } } - } - JSON_THROW(std::out_of_range("key not found")); -} + JSON_THROW(std::out_of_range("key not found")); + } -template::value, int> = 0> -const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it->second; + if (m_compare(it->first, key)) + { + return it->second; + } } - } - JSON_THROW(std::out_of_range("key not found")); -} + JSON_THROW(std::out_of_range("key not found")); + } -size_type erase(const key_type& key) -{ - for (auto it = this->begin(); it != this->end(); ++it) + size_type erase(const key_type& key) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) + if (m_compare(it->first, key)) { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) + { + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; + } + Container::pop_back(); + return 1; } - Container::pop_back(); - return 1; } + return 0; } - return 0; -} -template::value, int> = 0> -size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) + if (m_compare(it->first, key)) { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) + { + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; + } + Container::pop_back(); + return 1; } - Container::pop_back(); - return 1; } + return 0; } - return 0; -} -iterator erase(iterator pos) -{ - return erase(pos, std::next(pos)); -} - -iterator erase(iterator first, iterator last) -{ - if (first == last) + iterator erase(iterator pos) { - return first; + return erase(pos, std::next(pos)); } - const auto elements_affected = std::distance(first, last); - const auto offset = std::distance(Container::begin(), first); + iterator erase(iterator first, iterator last) + { + if (first == last) + { + return first; + } - // This is the start situation. We need to delete elements_affected - // elements (3 in this example: e, f, g), and need to return an - // iterator past the last deleted element (h in this example). - // Note that offset is the distance from the start of the vector - // to first. We will need this later. + const auto elements_affected = std::distance(first, last); + const auto offset = std::distance(Container::begin(), first); - // [ a, b, c, d, e, f, g, h, i, j ] - // ^ ^ - // first last + // This is the start situation. We need to delete elements_affected + // elements (3 in this example: e, f, g), and need to return an + // iterator past the last deleted element (h in this example). + // Note that offset is the distance from the start of the vector + // to first. We will need this later. - // Since we cannot move const Keys, we re-construct them in place. - // We start at first and re-construct (viz. copy) the elements from - // the back of the vector. Example for first iteration: + // [ a, b, c, d, e, f, g, h, i, j ] + // ^ ^ + // first last - // ,--------. - // v | destroy e and re-construct with h - // [ a, b, c, d, e, f, g, h, i, j ] - // ^ ^ - // it it + elements_affected + // Since we cannot move const Keys, we re-construct them in place. + // We start at first and re-construct (viz. copy) the elements from + // the back of the vector. Example for first iteration: - for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) - { - it->~value_type(); // destroy but keep allocation - new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it - } + // ,--------. + // v | destroy e and re-construct with h + // [ a, b, c, d, e, f, g, h, i, j ] + // ^ ^ + // it it + elements_affected - // [ a, b, c, d, h, i, j, h, i, j ] - // ^ ^ - // first last + for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) + { + it->~value_type(); // destroy but keep allocation + new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it + } - // remove the unneeded elements at the end of the vector - Container::resize(this->size() - static_cast(elements_affected)); + // [ a, b, c, d, h, i, j, h, i, j ] + // ^ ^ + // first last - // [ a, b, c, d, h, i, j ] - // ^ ^ - // first last + // remove the unneeded elements at the end of the vector + Container::resize(this->size() - static_cast(elements_affected)); - // first is now pointing past the last deleted element, but we cannot - // use this iterator, because it may have been invalidated by the - // resize call. Instead, we can return begin() + offset. - return Container::begin() + offset; -} + // [ a, b, c, d, h, i, j ] + // ^ ^ + // first last -size_type count(const key_type& key) const -{ - for (auto it = this->begin(); it != this->end(); ++it) + // first is now pointing past the last deleted element, but we cannot + // use this iterator, because it may have been invalidated by the + // resize call. Instead, we can return begin() + offset. + return Container::begin() + offset; + } + + size_type count(const key_type& key) const { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return 1; + if (m_compare(it->first, key)) + { + return 1; + } } + return 0; } - return 0; -} -template::value, int> = 0> -size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return 1; + if (m_compare(it->first, key)) + { + return 1; + } } + return 0; } - return 0; -} -iterator find(const key_type& key) -{ - for (auto it = this->begin(); it != this->end(); ++it) + iterator find(const key_type& key) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it; + if (m_compare(it->first, key)) + { + return it; + } } + return Container::end(); } - return Container::end(); -} -template::value, int> = 0> -iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) -{ - for (auto it = this->begin(); it != this->end(); ++it) + template::value, int> = 0> + iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it; + if (m_compare(it->first, key)) + { + return it; + } } + return Container::end(); } - return Container::end(); -} -const_iterator find(const key_type& key) const -{ - for (auto it = this->begin(); it != this->end(); ++it) + const_iterator find(const key_type& key) const { - if (m_compare(it->first, key)) + for (auto it = this->begin(); it != this->end(); ++it) { - return it; + if (m_compare(it->first, key)) + { + return it; + } } + return Container::end(); } - return Container::end(); -} -std::pair insert( value_type&& value ) -{ - return emplace(value.first, std::move(value.second)); -} + std::pair insert( value_type&& value ) + { + return emplace(value.first, std::move(value.second)); + } -std::pair insert( const value_type& value ) -{ - for (auto it = this->begin(); it != this->end(); ++it) + std::pair insert( const value_type& value ) { - if (m_compare(it->first, value.first)) + for (auto it = this->begin(); it != this->end(); ++it) { - return {it, false}; + if (m_compare(it->first, value.first)) + { + return {it, false}; + } } + Container::push_back(value); + return {--this->end(), true}; } - Container::push_back(value); - return {--this->end(), true}; -} -template -using require_input_iter = typename std::enable_if::iterator_category, - std::input_iterator_tag>::value>::type; + template + using require_input_iter = typename std::enable_if::iterator_category, + std::input_iterator_tag>::value>::type; -template> -void insert(InputIt first, InputIt last) -{ - for (auto it = first; it != last; ++it) + template> + void insert(InputIt first, InputIt last) { - insert(*it); + for (auto it = first; it != last; ++it) + { + insert(*it); + } } -} private: -JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); - }; + JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); +}; NLOHMANN_JSON_NAMESPACE_END @@ -23920,7 +23881,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // the valid JSON Patch operations enum class patch_operations {add, remove, replace, move, copy, test, invalid}; - const auto get_op = [](const std::string& op) + const auto get_op = [](const std::string & op) { if (op == "add") { @@ -24057,8 +24018,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec for (const auto& val : json_patch) { // wrapper to get a value for an operation - const auto get_value = [&val](const std::string& op, - const std::string& member, + const auto get_value = [&val](const std::string & op, + const std::string & member, bool string_type) -> basic_json & { // find value @@ -24435,14 +24396,14 @@ struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', */ bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept -{ + { #if JSON_HAS_THREE_WAY_COMPARISON - return std::is_lt(lhs <=> rhs); // *NOPAD* + return std::is_lt(lhs <=> rhs); // *NOPAD* #else - return ::nlohmann::detail::operator<(lhs, rhs); + return ::nlohmann::detail::operator<(lhs, rhs); #endif -} - }; + } +}; // C++20 prohibit function specialization in the std namespace. #ifndef JSON_HAS_CPP_20 @@ -24481,7 +24442,6 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC // SPDX-License-Identifier: MIT - // restore clang diagnostic settings #if defined(__clang__) #pragma clang diagnostic pop @@ -24526,7 +24486,6 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC // SPDX-License-Identifier: MIT - #undef JSON_HEDLEY_ALWAYS_INLINE #undef JSON_HEDLEY_ARM_VERSION #undef JSON_HEDLEY_ARM_VERSION_CHECK @@ -24677,5 +24636,4 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC #undef JSON_HEDLEY_FALL_THROUGH - #endif // INCLUDE_NLOHMANN_JSON_HPP_ diff --git a/single_include/nlohmann/json_fwd.hpp b/single_include/nlohmann/json_fwd.hpp index 98070dfc95..7a0c8a82ad 100644 --- a/single_include/nlohmann/json_fwd.hpp +++ b/single_include/nlohmann/json_fwd.hpp @@ -25,7 +25,6 @@ // SPDX-License-Identifier: MIT - // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 0fd9752527..dbafb436ba 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -88,7 +88,7 @@ struct Data Data() = default; Data(std::string a_, std::string b_) : a(std::move(a_)) - , b(std::move(b_)) + , b(std::move(b_)) {} std::string a{}; std::string b{}; diff --git a/tests/src/unit-testsuites.cpp b/tests/src/unit-testsuites.cpp index 74413653c0..e0cc127b93 100644 --- a/tests/src/unit-testsuites.cpp +++ b/tests/src/unit-testsuites.cpp @@ -106,7 +106,7 @@ TEST_CASE("compliance tests from nativejson-benchmark") SECTION("doubles") { - auto TEST_DOUBLE = [](const std::string& json_string, const double expected) + auto TEST_DOUBLE = [](const std::string & json_string, const double expected) { CAPTURE(json_string) CAPTURE(expected) @@ -238,7 +238,7 @@ TEST_CASE("compliance tests from nativejson-benchmark") SECTION("strings") { - auto TEST_STRING = [](const std::string& json_string, const std::string& expected) + auto TEST_STRING = [](const std::string & json_string, const std::string & expected) { CAPTURE(json_string) CAPTURE(expected) diff --git a/tests/src/unit-to_chars.cpp b/tests/src/unit-to_chars.cpp index c68e58ddcc..d9f75ea2ff 100644 --- a/tests/src/unit-to_chars.cpp +++ b/tests/src/unit-to_chars.cpp @@ -126,7 +126,7 @@ TEST_CASE("digit gen") { SECTION("single precision") { - auto check_float = [](float number, const std::string& digits, int expected_exponent) + auto check_float = [](float number, const std::string & digits, int expected_exponent) { CAPTURE(number) CAPTURE(digits) @@ -190,7 +190,7 @@ TEST_CASE("digit gen") SECTION("double precision") { - auto check_double = [](double number, const std::string& digits, int expected_exponent) + auto check_double = [](double number, const std::string & digits, int expected_exponent) { CAPTURE(number) CAPTURE(digits) @@ -336,7 +336,7 @@ TEST_CASE("formatting") { SECTION("single precision") { - auto check_float = [](float number, const std::string& expected) + auto check_float = [](float number, const std::string & expected) { std::array buf{}; char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) @@ -396,7 +396,7 @@ TEST_CASE("formatting") SECTION("double precision") { - auto check_double = [](double number, const std::string& expected) + auto check_double = [](double number, const std::string & expected) { std::array buf{}; char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) @@ -456,7 +456,7 @@ TEST_CASE("formatting") SECTION("integer") { - auto check_integer = [](std::int64_t number, const std::string& expected) + auto check_integer = [](std::int64_t number, const std::string & expected) { const nlohmann::json j = number; CHECK(j.dump() == expected); From ee57287af77fd64a2cbf6b01941bcc9d6d7aaf35 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Mon, 9 Oct 2023 21:43:45 +0200 Subject: [PATCH 07/14] amalgamate with astyle==3.1.2 --- single_include/nlohmann/json.hpp | 42 ++++++++++++++++++++++++++++ single_include/nlohmann/json_fwd.hpp | 1 + tests/src/unit-bjdata.cpp | 14 +++++----- tests/src/unit-cbor.cpp | 14 +++++----- tests/src/unit-msgpack.cpp | 10 +++---- 5 files changed, 62 insertions(+), 19 deletions(-) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 55c0cdfb87..71218c6c16 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -41,6 +41,7 @@ // SPDX-License-Identifier: MIT + #include // #include @@ -53,6 +54,7 @@ // SPDX-License-Identifier: MIT + // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK @@ -154,6 +156,7 @@ // SPDX-License-Identifier: MIT + #include // transform #include // array #include // forward_list @@ -176,6 +179,7 @@ // SPDX-License-Identifier: MIT + #include // nullptr_t #include // exception #if JSON_DIAGNOSTICS @@ -195,6 +199,7 @@ // SPDX-License-Identifier: MIT + #include // array #include // size_t #include // uint8_t @@ -210,6 +215,7 @@ // SPDX-License-Identifier: MIT + #include // declval, pair // #include // __ _____ _____ _____ @@ -221,6 +227,7 @@ // SPDX-License-Identifier: MIT + #include // #include @@ -233,6 +240,7 @@ // SPDX-License-Identifier: MIT + // #include @@ -2932,6 +2940,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include @@ -3006,6 +3015,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // size_t // #include @@ -3048,6 +3058,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // array #include // size_t #include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type @@ -3220,6 +3231,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // numeric_limits #include // false_type, is_constructible, is_integral, is_same, true_type #include // declval @@ -3235,6 +3247,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // random_access_iterator_tag // #include @@ -3302,6 +3315,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include @@ -3321,6 +3335,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include @@ -4143,6 +4158,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // strlen #include // string #include // forward @@ -4528,6 +4544,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include @@ -4551,6 +4568,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include @@ -5056,6 +5074,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // copy #include // begin, end #include // string @@ -5075,6 +5094,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // size_t #include // input_iterator_tag #include // string, to_string @@ -5795,6 +5815,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // uint8_t, uint64_t #include // tie #include // move @@ -5906,6 +5927,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // uint8_t #include // size_t #include // hash @@ -6038,6 +6060,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // generate_n #include // array #include // ldexp @@ -6063,6 +6086,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // array #include // size_t #include // strlen @@ -6557,6 +6581,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include #include // string #include // move @@ -7288,6 +7313,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // array #include // localeconv #include // size_t @@ -8926,6 +8952,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // size_t #include // declval #include // string @@ -12077,6 +12104,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // isfinite #include // uint8_t #include // function @@ -12593,6 +12621,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + // #include // #include @@ -12605,6 +12634,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // ptrdiff_t #include // numeric_limits @@ -12763,6 +12793,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next #include // conditional, is_const, remove_const @@ -13524,6 +13555,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // ptrdiff_t #include // reverse_iterator #include // declval @@ -13692,6 +13724,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // all_of #include // isdigit #include // errno, ERANGE @@ -14686,6 +14719,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include #include @@ -14777,6 +14811,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // reverse #include // array #include // map @@ -14802,6 +14837,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // copy #include // size_t #include // back_inserter @@ -16770,6 +16806,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // reverse, remove, fill, find, none_of #include // array #include // localeconv, lconv @@ -16794,6 +16831,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // array #include // signbit, isfinite #include // intN_t, uintN_t @@ -18888,6 +18926,7 @@ NLOHMANN_JSON_NAMESPACE_END // SPDX-License-Identifier: MIT + #include // equal_to, less #include // initializer_list #include // input_iterator_tag, iterator_traits @@ -24442,6 +24481,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC // SPDX-License-Identifier: MIT + // restore clang diagnostic settings #if defined(__clang__) #pragma clang diagnostic pop @@ -24486,6 +24526,7 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC // SPDX-License-Identifier: MIT + #undef JSON_HEDLEY_ALWAYS_INLINE #undef JSON_HEDLEY_ARM_VERSION #undef JSON_HEDLEY_ARM_VERSION_CHECK @@ -24636,4 +24677,5 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC #undef JSON_HEDLEY_FALL_THROUGH + #endif // INCLUDE_NLOHMANN_JSON_HPP_ diff --git a/single_include/nlohmann/json_fwd.hpp b/single_include/nlohmann/json_fwd.hpp index 7a0c8a82ad..98070dfc95 100644 --- a/single_include/nlohmann/json_fwd.hpp +++ b/single_include/nlohmann/json_fwd.hpp @@ -25,6 +25,7 @@ // SPDX-License-Identifier: MIT + // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 1aa3c22b0e..919ddf84fa 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -339,13 +339,13 @@ TEST_CASE("BJData") std::vector const numbers { -32769, - -100000, - -1000000, - -10000000, - -100000000, - -1000000000, - -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 - }; + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 + }; for (const auto i : numbers) { CAPTURE(i) diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index 9e9f999aef..0bf33e13d0 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -241,13 +241,13 @@ TEST_CASE("CBOR") const std::vector numbers { -65537, - -100000, - -1000000, - -10000000, - -100000000, - -1000000000, - -4294967296, - }; + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -4294967296, + }; for (const auto i : numbers) { CAPTURE(i) diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index 1686cc4a54..ff4a25f4fb 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -479,11 +479,11 @@ TEST_CASE("MessagePack") std::vector const numbers { -32769, - -65536, - -77777, - -1048576, - -2147483648LL, - }; + -65536, + -77777, + -1048576, + -2147483648LL, + }; for (auto i : numbers) { CAPTURE(i) From f68d2b1475e4012ec7ab8a8c549cc40ca8274d51 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Wed, 11 Oct 2023 23:33:42 +0200 Subject: [PATCH 08/14] Don't use concept. Causes compilation error on GCC 10 Opting out of using concept and rather defining a structure while still being able to not use SFINAE and instead `requires` expression. Compiling with C++23 on GCC 13.2.1 fails on overload resolution on calling operator== for `std::nullptr_t`. The solution for this was to simply add another overload for nullptr, on par with the equivalent `nullptr_t` constructor. --- include/nlohmann/detail/meta/type_traits.hpp | 9 ++++---- include/nlohmann/json.hpp | 15 ++++++++---- single_include/nlohmann/json.hpp | 24 +++++++++++++------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 9851de430e..8747a85e35 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -684,10 +684,11 @@ inline constexpr bool value_in_range_of(T val) template using bool_constant = std::integral_constant; -#ifdef JSON_HAS_CPP_20 - template - concept CompatibleType = !is_basic_json>::value && is_compatible_type>::value; -#endif +template > +struct json_compatible_type +{ + static constexpr auto value = !is_basic_json::value && is_compatible_type::value; +}; /////////////////////////////////////////////////////////////////////////////// // is_c_string diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 84d41ab98e..2e116f104b 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3694,12 +3694,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template T> + template + requires detail::json_compatible_type::value bool operator==(T rhs) const noexcept { return *this == basic_json(rhs); } + /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ + bool operator==(std::nullptr_t rhs) const noexcept + { + return *this == basic_json(rhs); + } + /// @brief comparison: not equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ bool operator!=(const_reference rhs) const noexcept @@ -3726,9 +3733,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief comparison: 3-way /// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/ - template - requires std::is_scalar_v - std::partial_ordering operator<=>(ScalarType rhs) const noexcept // *NOPAD* + template + requires detail::json_compatible_type::value + std::partial_ordering operator<=>(T rhs) const noexcept // *NOPAD* { return *this <=> basic_json(rhs); // *NOPAD* } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 71218c6c16..8ef520dc0c 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4091,10 +4091,11 @@ inline constexpr bool value_in_range_of(T val) template using bool_constant = std::integral_constant; -#ifdef JSON_HAS_CPP_20 - template - concept CompatibleType = !is_basic_json>::value && is_compatible_type>::value; -#endif +template > +struct json_compatible_type +{ + static constexpr auto value = !is_basic_json::value && is_compatible_type::value; +}; /////////////////////////////////////////////////////////////////////////////// // is_c_string @@ -22913,12 +22914,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template T> + template + requires detail::json_compatible_type::value bool operator==(T rhs) const noexcept { return *this == basic_json(rhs); } + /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ + bool operator==(std::nullptr_t rhs) const noexcept + { + return *this == basic_json(rhs); + } + /// @brief comparison: not equal /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ bool operator!=(const_reference rhs) const noexcept @@ -22945,9 +22953,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief comparison: 3-way /// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/ - template - requires std::is_scalar_v - std::partial_ordering operator<=>(ScalarType rhs) const noexcept // *NOPAD* + template + requires detail::json_compatible_type::value + std::partial_ordering operator<=>(T rhs) const noexcept // *NOPAD* { return *this <=> basic_json(rhs); // *NOPAD* } From 0c9adb13f535ae15eaa2e5cfd34324d835eff610 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Thu, 29 Feb 2024 21:24:01 +0100 Subject: [PATCH 09/14] Use SFINAE instead of 'requires' clause because of cppcheck. --- include/nlohmann/json.hpp | 6 ++++-- single_include/nlohmann/json.hpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 2e116f104b..ae5c0a5522 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3692,10 +3692,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #endif } + // template::value, int>::type = 0> /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template - requires detail::json_compatible_type::value + template ::value, int>::type = 0> bool operator==(T rhs) const noexcept { return *this == basic_json(rhs); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8ef520dc0c..44c7f5f3ff 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -22912,10 +22912,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #endif } + // template::value, int>::type = 0> /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template - requires detail::json_compatible_type::value + template ::value, int>::type = 0> bool operator==(T rhs) const noexcept { return *this == basic_json(rhs); From b20332ddb98227e2c4dc2fe7b22350cc9fc8f84d Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Thu, 29 Feb 2024 22:52:18 +0100 Subject: [PATCH 10/14] Use bool instead of auto --- include/nlohmann/detail/meta/type_traits.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 8747a85e35..f017febf1b 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -684,10 +684,11 @@ inline constexpr bool value_in_range_of(T val) template using bool_constant = std::integral_constant; + template > struct json_compatible_type { - static constexpr auto value = !is_basic_json::value && is_compatible_type::value; + static constexpr bool value = !is_basic_json::value && is_compatible_type::value; }; /////////////////////////////////////////////////////////////////////////////// From 7fe8daded837793c3842b9d7e820fc040b7fab89 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Wed, 6 Mar 2024 14:57:47 +0100 Subject: [PATCH 11/14] Amalgamate --- single_include/nlohmann/json.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 44c7f5f3ff..39aebedadb 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4091,10 +4091,11 @@ inline constexpr bool value_in_range_of(T val) template using bool_constant = std::integral_constant; + template > struct json_compatible_type { - static constexpr auto value = !is_basic_json::value && is_compatible_type::value; + static constexpr bool value = !is_basic_json::value && is_compatible_type::value; }; /////////////////////////////////////////////////////////////////////////////// From 65b9b38ff33829b43d15488d84413233a34d63fb Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Thu, 7 Mar 2024 20:53:52 +0100 Subject: [PATCH 12/14] Fix compile errors on other versions of clang --- include/nlohmann/json.hpp | 4 ++-- single_include/nlohmann/json.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index ae5c0a5522..77dd000edb 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3696,8 +3696,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // std::is_scalar::value, int>::type = 0> /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template ::value, int>::type = 0> + template + requires detail::json_compatible_type::value bool operator==(T rhs) const noexcept { return *this == basic_json(rhs); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 39aebedadb..bb2cbb8f37 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -22917,8 +22917,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // std::is_scalar::value, int>::type = 0> /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ - template ::value, int>::type = 0> + template + requires detail::json_compatible_type::value bool operator==(T rhs) const noexcept { return *this == basic_json(rhs); From fc191903cc5b4f645b3cb33c808cc5d36a74ecad Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Tue, 19 Mar 2024 20:57:58 +0100 Subject: [PATCH 13/14] Operator for non equality --- include/nlohmann/json.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 77dd000edb..482a99133b 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3692,8 +3692,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #endif } - // template::value, int>::type = 0> /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ template @@ -3703,6 +3701,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return *this == basic_json(rhs); } + /// @brief comparison: not equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ + template + requires detail::json_compatible_type::value + bool operator!=(T rhs) const noexcept + { + return *this != basic_json(rhs); + } + /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ bool operator==(std::nullptr_t rhs) const noexcept { From 8d896613a7913f265c532aa5d951dcc4c0b413f1 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Tue, 19 Mar 2024 20:59:18 +0100 Subject: [PATCH 14/14] amalgamate --- single_include/nlohmann/json.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index bb2cbb8f37..937a5fc00a 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -22913,8 +22913,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #endif } - // template::value, int>::type = 0> /// @brief comparison: equal /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ template @@ -22924,6 +22922,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return *this == basic_json(rhs); } + /// @brief comparison: not equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ + template + requires detail::json_compatible_type::value + bool operator!=(T rhs) const noexcept + { + return *this != basic_json(rhs); + } + /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ bool operator==(std::nullptr_t rhs) const noexcept {