From eb0f8d734c6638fd1eca76458bda53e10f612330 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 3 May 2021 20:42:28 +0200 Subject: [PATCH] :ok_hand: apply review comments --- doc/mkdocs/docs/api/basic_json/contains.md | 2 +- doc/mkdocs/docs/api/basic_json/count.md | 2 +- doc/mkdocs/docs/api/basic_json/find.md | 4 ++-- doc/mkdocs/docs/api/basic_json/value.md | 6 ++--- include/nlohmann/json.hpp | 26 +++++++++++----------- single_include/nlohmann/json.hpp | 26 +++++++++++----------- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/doc/mkdocs/docs/api/basic_json/contains.md b/doc/mkdocs/docs/api/basic_json/contains.md index e6f8caffa..1dc1e0619 100644 --- a/doc/mkdocs/docs/api/basic_json/contains.md +++ b/doc/mkdocs/docs/api/basic_json/contains.md @@ -2,7 +2,7 @@ ```cpp template -bool contains(KeyT && key) const; +bool contains(const KeyT& key) const; ``` Check whether an element exists in a JSON object with key equivalent to `key`. If the element is not found or the JSON diff --git a/doc/mkdocs/docs/api/basic_json/count.md b/doc/mkdocs/docs/api/basic_json/count.md index 35973c2a3..141d467b5 100644 --- a/doc/mkdocs/docs/api/basic_json/count.md +++ b/doc/mkdocs/docs/api/basic_json/count.md @@ -2,7 +2,7 @@ ```cpp template -size_type count(KeyT && key) const; +size_type count(const KeyT& key) const; ``` Returns the number of elements with key `key`. If `ObjectType` is the default `std::map` type, the return value will diff --git a/doc/mkdocs/docs/api/basic_json/find.md b/doc/mkdocs/docs/api/basic_json/find.md index 1359a62f0..12691640a 100644 --- a/doc/mkdocs/docs/api/basic_json/find.md +++ b/doc/mkdocs/docs/api/basic_json/find.md @@ -2,10 +2,10 @@ ```cpp template -iterator find(KeyT && key); +iterator find(const KeyT& key); template -const_iterator find(KeyT && key) const +const_iterator find(const KeyT& key) const ``` Finds an element in a JSON object with key equivalent to `key`. If the element is not found or the JSON value is not an diff --git a/doc/mkdocs/docs/api/basic_json/value.md b/doc/mkdocs/docs/api/basic_json/value.md index 8a23506e4..eee02e23e 100644 --- a/doc/mkdocs/docs/api/basic_json/value.md +++ b/doc/mkdocs/docs/api/basic_json/value.md @@ -3,13 +3,13 @@ ```cpp // (1) template -ValueType value(KeyType && key, - const ValueType& default_value) const; +ValueType value(const KeyType& key, + ValueType && default_value) const; // (2) template ValueType value(const json_pointer& ptr, - const ValueType& default_value) const; + ValueType && default_value) const; ``` 1. Returns either a copy of an object's element at the specified key `key` or a given default value if no element with diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 60f3fa550..8735fb2b1 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3834,13 +3834,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec template < class KeyType, class ValueType, typename detail::enable_if_t < detail::is_getable::value && !std::is_same::value&& detail::is_key_type::value > ... > - ValueType value(KeyType&& key, const ValueType& default_value) const + ValueType value(const KeyType& key, ValueType&& default_value) const { // at only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { // if key is found, return value and given default value otherwise - const auto it = find(std::forward(key)); + const auto it = find(key); if (it != end()) { return it->template get(); @@ -3908,7 +3908,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ template::value, int>::type = 0> - ValueType value(const json_pointer& ptr, const ValueType& default_value) const + ValueType value(const json_pointer& ptr, ValueType && default_value) const { // at only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -4380,13 +4380,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ template < class KeyT, typename detail::enable_if_t < detail::is_key_type::value > ... > - iterator find(KeyT&& key) + iterator find(const KeyT& key) { auto result = end(); if (is_object()) { - result.m_it.object_iterator = m_value.object->find(std::forward(key)); + result.m_it.object_iterator = m_value.object->find(key); } return result; @@ -4394,17 +4394,17 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /*! @brief find an element in a JSON object - @copydoc find(KeyT&&) + @copydoc find(const KeyT&) */ template < class KeyT, typename detail::enable_if_t < detail::is_key_type::value > ... > - const_iterator find(KeyT&& key) const + const_iterator find(const KeyT& key) const { auto result = cend(); if (is_object()) { - result.m_it.object_iterator = m_value.object->find(std::forward(key)); + result.m_it.object_iterator = m_value.object->find(key); } return result; @@ -4433,10 +4433,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ template < class KeyT, typename detail::enable_if_t < detail::is_key_type::value > ... > - size_type count(KeyT&& key) const + size_type count(const KeyT& key) const { // return 0 for all nonobject types - return is_object() ? m_value.object->count(std::forward(key)) : 0; + return is_object() ? m_value.object->count(key) : 0; } /*! @@ -4459,16 +4459,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec @liveexample{The following code shows an example for `contains()`.,contains} - @sa see @ref find(KeyT&&) -- returns an iterator to an object element + @sa see @ref find(const KeyT&) -- returns an iterator to an object element @sa see @ref contains(const json_pointer&) const -- checks the existence for a JSON pointer @since version 3.6.0 */ template < class KeyT, typename detail::enable_if_t < !std::is_same::type, json_pointer>::value&& detail::is_key_type::value > ... > - bool contains(KeyT&& key) const + bool contains(const KeyT& key) const { - return is_object() && m_value.object->find(std::forward(key)) != m_value.object->end(); + return is_object() && m_value.object->find(key) != m_value.object->end(); } /*! diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index cc057a41c..13179c82e 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20867,13 +20867,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec template < class KeyType, class ValueType, typename detail::enable_if_t < detail::is_getable::value && !std::is_same::value&& detail::is_key_type::value > ... > - ValueType value(KeyType&& key, const ValueType& default_value) const + ValueType value(const KeyType& key, ValueType&& default_value) const { // at only works for objects if (JSON_HEDLEY_LIKELY(is_object())) { // if key is found, return value and given default value otherwise - const auto it = find(std::forward(key)); + const auto it = find(key); if (it != end()) { return it->template get(); @@ -20941,7 +20941,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ template::value, int>::type = 0> - ValueType value(const json_pointer& ptr, const ValueType& default_value) const + ValueType value(const json_pointer& ptr, ValueType && default_value) const { // at only works for objects if (JSON_HEDLEY_LIKELY(is_object())) @@ -21413,13 +21413,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ template < class KeyT, typename detail::enable_if_t < detail::is_key_type::value > ... > - iterator find(KeyT&& key) + iterator find(const KeyT& key) { auto result = end(); if (is_object()) { - result.m_it.object_iterator = m_value.object->find(std::forward(key)); + result.m_it.object_iterator = m_value.object->find(key); } return result; @@ -21427,17 +21427,17 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /*! @brief find an element in a JSON object - @copydoc find(KeyT&&) + @copydoc find(const KeyT&) */ template < class KeyT, typename detail::enable_if_t < detail::is_key_type::value > ... > - const_iterator find(KeyT&& key) const + const_iterator find(const KeyT& key) const { auto result = cend(); if (is_object()) { - result.m_it.object_iterator = m_value.object->find(std::forward(key)); + result.m_it.object_iterator = m_value.object->find(key); } return result; @@ -21466,10 +21466,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec */ template < class KeyT, typename detail::enable_if_t < detail::is_key_type::value > ... > - size_type count(KeyT&& key) const + size_type count(const KeyT& key) const { // return 0 for all nonobject types - return is_object() ? m_value.object->count(std::forward(key)) : 0; + return is_object() ? m_value.object->count(key) : 0; } /*! @@ -21492,16 +21492,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec @liveexample{The following code shows an example for `contains()`.,contains} - @sa see @ref find(KeyT&&) -- returns an iterator to an object element + @sa see @ref find(const KeyT&) -- returns an iterator to an object element @sa see @ref contains(const json_pointer&) const -- checks the existence for a JSON pointer @since version 3.6.0 */ template < class KeyT, typename detail::enable_if_t < !std::is_same::type, json_pointer>::value&& detail::is_key_type::value > ... > - bool contains(KeyT&& key) const + bool contains(const KeyT& key) const { - return is_object() && m_value.object->find(std::forward(key)) != m_value.object->end(); + return is_object() && m_value.object->find(key) != m_value.object->end(); } /*!