Skip to content

Commit

Permalink
👌 address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Nov 23, 2021
1 parent 5379b5d commit 15e4598
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions doc/mkdocs/docs/api/basic_json/operator[].md
Expand Up @@ -7,9 +7,9 @@ const_reference operator[](size_type idx) const;

// (2)
template<typename KeyT>
reference operator[](KeyT && key);
reference operator[](const KeyT& key);
template<typename KeyT>
const_reference operator[](KeyT && key) const;
const_reference operator[](const KeyT& key) const;

// (3)
reference operator[](const json_pointer& ptr);
Expand Down
8 changes: 4 additions & 4 deletions include/nlohmann/json.hpp
Expand Up @@ -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<basic_json_t, KeyT>::value&& !std::is_same<typename std::decay<KeyT>::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())
Expand All @@ -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<KeyT>(key), nullptr);
auto result = m_value.object->emplace(key, nullptr);
return set_parent(result.first->second);
}

Expand Down Expand Up @@ -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<basic_json_t, KeyT>::value&& !std::is_same<typename std::decay<KeyT>::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<KeyT>(key));
auto it = m_value.object->find(key);
JSON_ASSERT(it != m_value.object->end());
return it->second;
}
Expand Down
8 changes: 4 additions & 4 deletions single_include/nlohmann/json.hpp
Expand Up @@ -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<basic_json_t, KeyT>::value&& !std::is_same<typename std::decay<KeyT>::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())
Expand All @@ -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<KeyT>(key), nullptr);
auto result = m_value.object->emplace(key, nullptr);
return set_parent(result.first->second);
}

Expand Down Expand Up @@ -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<basic_json_t, KeyT>::value&& !std::is_same<typename std::decay<KeyT>::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<KeyT>(key));
auto it = m_value.object->find(key);
JSON_ASSERT(it != m_value.object->end());
return it->second;
}
Expand Down

0 comments on commit 15e4598

Please sign in to comment.