👌 apply review comments

This commit is contained in:
Niels Lohmann 2021-05-03 20:42:28 +02:00
parent 12c0bc4c9e
commit eb0f8d734c
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
6 changed files with 33 additions and 33 deletions

View File

@ -2,7 +2,7 @@
```cpp
template<typename KeyT>
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

View File

@ -2,7 +2,7 @@
```cpp
template<typename KeyT>
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

View File

@ -2,10 +2,10 @@
```cpp
template<typename KeyT>
iterator find(KeyT && key);
iterator find(const KeyT& key);
template<typename KeyT>
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

View File

@ -3,13 +3,13 @@
```cpp
// (1)
template<class KeyType, class ValueType>
ValueType value(KeyType && key,
const ValueType& default_value) const;
ValueType value(const KeyType& key,
ValueType && default_value) const;
// (2)
template<class ValueType>
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

View File

@ -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<basic_json_t, ValueType>::value
&& !std::is_same<value_t, ValueType>::value&& detail::is_key_type<basic_json_t, KeyType>::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<KeyType>(key));
const auto it = find(key);
if (it != end())
{
return it->template get<ValueType>();
@ -3908,7 +3908,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
template<class ValueType, typename std::enable_if<
detail::is_getable<basic_json_t, ValueType>::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<basic_json_t, KeyT>::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<KeyT>(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<basic_json_t, KeyT>::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<KeyT>(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<basic_json_t, KeyT>::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<KeyT>(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<typename std::decay<KeyT>::type, json_pointer>::value&& detail::is_key_type<basic_json_t, KeyT>::value > ... >
bool contains(KeyT&& key) const
bool contains(const KeyT& key) const
{
return is_object() && m_value.object->find(std::forward<KeyT>(key)) != m_value.object->end();
return is_object() && m_value.object->find(key) != m_value.object->end();
}
/*!

View File

@ -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<basic_json_t, ValueType>::value
&& !std::is_same<value_t, ValueType>::value&& detail::is_key_type<basic_json_t, KeyType>::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<KeyType>(key));
const auto it = find(key);
if (it != end())
{
return it->template get<ValueType>();
@ -20941,7 +20941,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
template<class ValueType, typename std::enable_if<
detail::is_getable<basic_json_t, ValueType>::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<basic_json_t, KeyT>::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<KeyT>(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<basic_json_t, KeyT>::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<KeyT>(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<basic_json_t, KeyT>::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<KeyT>(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<typename std::decay<KeyT>::type, json_pointer>::value&& detail::is_key_type<basic_json_t, KeyT>::value > ... >
bool contains(KeyT&& key) const
bool contains(const KeyT& key) const
{
return is_object() && m_value.object->find(std::forward<KeyT>(key)) != m_value.object->end();
return is_object() && m_value.object->find(key) != m_value.object->end();
}
/*!