From 2cdf3dd4083081482e43b23e5e43a3a2efb4f1d0 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 2 Jan 2022 13:25:18 +0100 Subject: [PATCH] :rewind: undo commit 15e45981ead5ca64a963d79c5dd5b6d18b2c7a3f --- include/nlohmann/json.hpp | 8 ++++---- single_include/nlohmann/json.hpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 619048a35..4bf674453 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -2074,7 +2074,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ template < class KeyT, typename detail::enable_if_t < detail::is_usable_as_key_type::value&& !std::is_same::type, json_pointer>::value, int > = 0 > - reference operator[](const KeyT& key) + reference operator[](KeyT && key) { // implicitly convert null value to an empty object if (is_null()) @@ -2087,7 +2087,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // operator[] only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - auto result = m_value.object->emplace(key, nullptr); + auto result = m_value.object->emplace(std::forward(key), nullptr); return set_parent(result.first->second); } @@ -2098,12 +2098,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ template < class KeyT, typename detail::enable_if_t < detail::is_usable_as_key_type::value&& !std::is_same::type, json_pointer>::value, int > = 0 > - const_reference operator[](const KeyT& key) const + const_reference operator[](KeyT && key) const { // operator[] only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - auto it = m_value.object->find(key); + auto it = m_value.object->find(std::forward(key)); JSON_ASSERT(it != m_value.object->end()); return it->second; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 47494a492..0ce534a1e 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -19263,7 +19263,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ template < class KeyT, typename detail::enable_if_t < detail::is_usable_as_key_type::value&& !std::is_same::type, json_pointer>::value, int > = 0 > - reference operator[](const KeyT& key) + reference operator[](KeyT && key) { // implicitly convert null value to an empty object if (is_null()) @@ -19276,7 +19276,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // operator[] only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - auto result = m_value.object->emplace(key, nullptr); + auto result = m_value.object->emplace(std::forward(key), nullptr); return set_parent(result.first->second); } @@ -19287,12 +19287,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ template < class KeyT, typename detail::enable_if_t < detail::is_usable_as_key_type::value&& !std::is_same::type, json_pointer>::value, int > = 0 > - const_reference operator[](const KeyT& key) const + const_reference operator[](KeyT && key) const { // operator[] only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - auto it = m_value.object->find(key); + auto it = m_value.object->find(std::forward(key)); JSON_ASSERT(it != m_value.object->end()); return it->second; }