From 15e45981ead5ca64a963d79c5dd5b6d18b2c7a3f Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 23 Nov 2021 20:41:30 +0100 Subject: [PATCH] :ok_hand: address review comments --- doc/mkdocs/docs/api/basic_json/operator[].md | 4 ++-- include/nlohmann/json.hpp | 8 ++++---- single_include/nlohmann/json.hpp | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/mkdocs/docs/api/basic_json/operator[].md b/doc/mkdocs/docs/api/basic_json/operator[].md index 419f86978..06140558f 100644 --- a/doc/mkdocs/docs/api/basic_json/operator[].md +++ b/doc/mkdocs/docs/api/basic_json/operator[].md @@ -7,9 +7,9 @@ const_reference operator[](size_type idx) const; // (2) template -reference operator[](KeyT && key); +reference operator[](const KeyT& key); template -const_reference operator[](KeyT && key) const; +const_reference operator[](const KeyT& key) const; // (3) reference operator[](const json_pointer& ptr); diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index e92affe80..bf5765f70 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3750,7 +3750,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ 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[](KeyT && key) + reference operator[](const KeyT& key) { // implicitly convert null value to an empty object if (is_null()) @@ -3763,7 +3763,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(std::forward(key), nullptr); + auto result = m_value.object->emplace(key, nullptr); return set_parent(result.first->second); } @@ -3803,12 +3803,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ 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[](KeyT && key) const + const_reference operator[](const KeyT& key) const { // operator[] only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - auto it = m_value.object->find(std::forward(key)); + auto it = m_value.object->find(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 0ccdcd70c..fc25e659d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -21317,7 +21317,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ 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[](KeyT && key) + reference operator[](const KeyT& key) { // implicitly convert null value to an empty object if (is_null()) @@ -21330,7 +21330,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(std::forward(key), nullptr); + auto result = m_value.object->emplace(key, nullptr); return set_parent(result.first->second); } @@ -21370,12 +21370,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ 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[](KeyT && key) const + const_reference operator[](const KeyT& key) const { // operator[] only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { - auto it = m_value.object->find(std::forward(key)); + auto it = m_value.object->find(key); JSON_ASSERT(it != m_value.object->end()); return it->second; }