From ca407117ed6b346005a4787252cdbb6a94161b93 Mon Sep 17 00:00:00 2001 From: Fredrik Sandhei Date: Mon, 9 Oct 2023 18:30:11 +0200 Subject: [PATCH] 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 | 60 +- include/nlohmann/json.hpp | 16 +- include/nlohmann/ordered_map.hpp | 544 +++++++------- single_include/nlohmann/json.hpp | 674 ++++++++++-------- 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, 683 insertions(+), 640 deletions(-) diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index c8c0a1373..6edc81ca1 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 34a20eee8..ce5fe27a1 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 215008963..2a7f43744 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 9851de430..aa6054c8e 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; + { + 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 @@ -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 84d41ab98..f2ab7e003 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 5d28cdf20..1ba7b7311 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} {} + // 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}; + } + } + 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) + { + if (m_compare(it->first, key)) + { + return {it, false}; + } + } + 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; +} + +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); +} + +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) + { + if (m_compare(it->first, key)) + { + 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) +{ + for (auto it = this->begin(); it != this->end(); ++it) + { + if (m_compare(it->first, key)) + { + return it->second; + } + } + + 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) + { + if (m_compare(it->first, key)) + { + 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) +{ + for (auto it = this->begin(); it != this->end(); ++it) + { + if (m_compare(it->first, key)) + { + return it->second; + } + } + + 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) + { + 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) { - return {it, false}; + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; } + Container::pop_back(); + return 1; } - Container::emplace_back(key, std::forward(t)); - return {std::prev(this->end()), true}; } + return 0; +} - template::value, int> = 0> - std::pair emplace(KeyType && key, T && t) +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) { - return {it, false}; + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; } + Container::pop_back(); + return 1; } - Container::emplace_back(std::forward(key), std::forward(t)); - return {std::prev(this->end()), true}; + } + return 0; +} + +iterator erase(iterator pos) +{ + return erase(pos, std::next(pos)); +} + +iterator erase(iterator first, iterator last) +{ + if (first == last) + { + return first; } - T& operator[](const key_type& key) + 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. + + // [ 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: + + // ,--------. + // 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) { - return emplace(key, T{}).first->second; + it->~value_type(); // destroy but keep allocation + new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it } - template::value, int> = 0> - T & operator[](KeyType && key) - { - return emplace(std::forward(key), T{}).first->second; - } + // [ a, b, c, d, h, i, j, h, i, j ] + // ^ ^ + // first last - const T& operator[](const key_type& key) const - { - return at(key); - } + // remove the unneeded elements at the end of the vector + Container::resize(this->size() - static_cast(elements_affected)); - template::value, int> = 0> - const T & operator[](KeyType && key) const - { - return at(std::forward(key)); - } + // [ a, b, c, d, h, i, j ] + // ^ ^ + // first last - T& at(const key_type& key) + // 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 +{ + 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 1; } - - JSON_THROW(std::out_of_range("key not found")); } + return 0; +} - template::value, int> = 0> - T & at(KeyType && key) // 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 it->second; - } + return 1; } - - JSON_THROW(std::out_of_range("key not found")); } + return 0; +} - const T& at(const key_type& key) const +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->second; - } + return it; } - - JSON_THROW(std::out_of_range("key not found")); } + return Container::end(); +} - template::value, int> = 0> - const T & at(KeyType && key) const // 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->second; - } + return it; } - - JSON_THROW(std::out_of_range("key not found")); } + return Container::end(); +} - size_type erase(const key_type& key) +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)) - { - // 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; - } + return it; } - return 0; } + return Container::end(); +} - template::value, int> = 0> - size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +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) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, value.first)) { - 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) - { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; - } - Container::pop_back(); - return 1; - } - } - return 0; - } - - iterator erase(iterator pos) - { - return erase(pos, std::next(pos)); - } - - iterator erase(iterator first, iterator last) - { - if (first == last) - { - return 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. - - // [ 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: - - // ,--------. - // 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 - } - - // [ 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)); - - // [ 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; - } - - size_type count(const key_type& key) const - { - for (auto it = this->begin(); it != this->end(); ++it) - { - if (m_compare(it->first, key)) - { - return 1; - } - } - 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) - { - if (m_compare(it->first, key)) - { - return 1; - } - } - return 0; - } - - iterator find(const key_type& key) - { - for (auto it = this->begin(); it != this->end(); ++it) - { - if (m_compare(it->first, key)) - { - return it; - } - } - 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) - { - if (m_compare(it->first, key)) - { - return it; - } - } - return Container::end(); - } - - const_iterator find(const key_type& key) const - { - for (auto it = this->begin(); it != this->end(); ++it) - { - if (m_compare(it->first, key)) - { - return it; - } - } - return Container::end(); - } - - 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) - { - if (m_compare(it->first, value.first)) - { - return {it, false}; - } - } - 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> - void insert(InputIt first, InputIt last) - { - for (auto it = first; it != last; ++it) - { - insert(*it); + return {it, false}; } } + 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> +void insert(InputIt first, InputIt last) +{ + 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 55c0cdfb8..a3191d502 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}; + } + } + 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) + { + if (m_compare(it->first, key)) + { + return {it, false}; + } + } + 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; +} + +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); +} + +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) + { + if (m_compare(it->first, key)) + { + 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) +{ + for (auto it = this->begin(); it != this->end(); ++it) + { + if (m_compare(it->first, key)) + { + return it->second; + } + } + + 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) + { + if (m_compare(it->first, key)) + { + 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) +{ + for (auto it = this->begin(); it != this->end(); ++it) + { + if (m_compare(it->first, key)) + { + return it->second; + } + } + + 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) + { + 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) { - return {it, false}; + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; } + Container::pop_back(); + return 1; } - Container::emplace_back(key, std::forward(t)); - return {std::prev(this->end()), true}; } + return 0; +} - template::value, int> = 0> - std::pair emplace(KeyType && key, T && t) +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) { - return {it, false}; + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; } + Container::pop_back(); + return 1; } - Container::emplace_back(std::forward(key), std::forward(t)); - return {std::prev(this->end()), true}; + } + return 0; +} + +iterator erase(iterator pos) +{ + return erase(pos, std::next(pos)); +} + +iterator erase(iterator first, iterator last) +{ + if (first == last) + { + return first; } - T& operator[](const key_type& key) + 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. + + // [ 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: + + // ,--------. + // 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) { - return emplace(key, T{}).first->second; + it->~value_type(); // destroy but keep allocation + new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it } - template::value, int> = 0> - T & operator[](KeyType && key) - { - return emplace(std::forward(key), T{}).first->second; - } + // [ a, b, c, d, h, i, j, h, i, j ] + // ^ ^ + // first last - const T& operator[](const key_type& key) const - { - return at(key); - } + // remove the unneeded elements at the end of the vector + Container::resize(this->size() - static_cast(elements_affected)); - template::value, int> = 0> - const T & operator[](KeyType && key) const - { - return at(std::forward(key)); - } + // [ a, b, c, d, h, i, j ] + // ^ ^ + // first last - T& at(const key_type& key) + // 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 +{ + 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 1; } - - JSON_THROW(std::out_of_range("key not found")); } + return 0; +} - template::value, int> = 0> - T & at(KeyType && key) // 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 it->second; - } + return 1; } - - JSON_THROW(std::out_of_range("key not found")); } + return 0; +} - const T& at(const key_type& key) const +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->second; - } + return it; } - - JSON_THROW(std::out_of_range("key not found")); } + return Container::end(); +} - template::value, int> = 0> - const T & at(KeyType && key) const // 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->second; - } + return it; } - - JSON_THROW(std::out_of_range("key not found")); } + return Container::end(); +} - size_type erase(const key_type& key) +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)) - { - // 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; - } + return it; } - return 0; } + return Container::end(); +} - template::value, int> = 0> - size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) +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) { - for (auto it = this->begin(); it != this->end(); ++it) + if (m_compare(it->first, value.first)) { - 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) - { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; - } - Container::pop_back(); - return 1; - } - } - return 0; - } - - iterator erase(iterator pos) - { - return erase(pos, std::next(pos)); - } - - iterator erase(iterator first, iterator last) - { - if (first == last) - { - return 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. - - // [ 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: - - // ,--------. - // 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 - } - - // [ 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)); - - // [ 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; - } - - size_type count(const key_type& key) const - { - for (auto it = this->begin(); it != this->end(); ++it) - { - if (m_compare(it->first, key)) - { - return 1; - } - } - 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) - { - if (m_compare(it->first, key)) - { - return 1; - } - } - return 0; - } - - iterator find(const key_type& key) - { - for (auto it = this->begin(); it != this->end(); ++it) - { - if (m_compare(it->first, key)) - { - return it; - } - } - 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) - { - if (m_compare(it->first, key)) - { - return it; - } - } - return Container::end(); - } - - const_iterator find(const key_type& key) const - { - for (auto it = this->begin(); it != this->end(); ++it) - { - if (m_compare(it->first, key)) - { - return it; - } - } - return Container::end(); - } - - 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) - { - if (m_compare(it->first, value.first)) - { - return {it, false}; - } - } - 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> - void insert(InputIt first, InputIt last) - { - for (auto it = first; it != last; ++it) - { - insert(*it); + return {it, false}; } } + 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> +void insert(InputIt first, InputIt last) +{ + 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 @@ -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 7a0c8a82a..98070dfc9 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 dbafb436b..0fd975252 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 e0cc127b9..74413653c 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 d9f75ea2f..c68e58ddc 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);