Added object_t::key_type and object_t::mapped_type aliases.

This commit is contained in:
Francois Chabot 2019-01-16 10:27:29 -05:00
parent dffae1082f
commit c549d648cf
2 changed files with 50 additions and 44 deletions

View File

@ -479,6 +479,9 @@ class basic_json
AllocatorType<std::pair<const StringType, AllocatorType<std::pair<const StringType,
basic_json>>>; basic_json>>>;
using key_type = typename object_t::key_type;
using mapped_type = typename object_t::mapped_type;
/*! /*!
@brief a type for an array @brief a type for an array
@ -2993,7 +2996,7 @@ class basic_json
@complexity Logarithmic in the size of the container. @complexity Logarithmic in the size of the container.
@sa @ref operator[](const typename object_t::key_type&) for unchecked @sa @ref operator[](const key_type&) for unchecked
access by reference access by reference
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@ -3003,7 +3006,7 @@ class basic_json
written using `at()`. It also demonstrates the different exceptions that written using `at()`. It also demonstrates the different exceptions that
can be thrown.,at__object_t_key_type} can be thrown.,at__object_t_key_type}
*/ */
reference at(const typename object_t::key_type& key) reference at(const key_type& key)
{ {
// at only works for objects // at only works for objects
if (JSON_LIKELY(is_object())) if (JSON_LIKELY(is_object()))
@ -3044,7 +3047,7 @@ class basic_json
@complexity Logarithmic in the size of the container. @complexity Logarithmic in the size of the container.
@sa @ref operator[](const typename object_t::key_type&) for unchecked @sa @ref operator[](const key_type&) for unchecked
access by reference access by reference
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@ -3054,7 +3057,7 @@ class basic_json
`at()`. It also demonstrates the different exceptions that can be thrown., `at()`. It also demonstrates the different exceptions that can be thrown.,
at__object_t_key_type_const} at__object_t_key_type_const}
*/ */
const_reference at(const typename object_t::key_type& key) const const_reference at(const key_type& key) const
{ {
// at only works for objects // at only works for objects
if (JSON_LIKELY(is_object())) if (JSON_LIKELY(is_object()))
@ -3178,13 +3181,13 @@ class basic_json
@liveexample{The example below shows how object elements can be read and @liveexample{The example below shows how object elements can be read and
written using the `[]` operator.,operatorarray__key_type} written using the `[]` operator.,operatorarray__key_type}
@sa @ref at(const typename object_t::key_type&) for access by reference @sa @ref at(const key_type&) for access by reference
with range checking with range checking
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@since version 1.0.0 @since version 1.0.0
*/ */
reference operator[](const typename object_t::key_type& key) reference operator[](const key_type& key)
{ {
// implicitly convert null value to an empty object // implicitly convert null value to an empty object
if (is_null()) if (is_null())
@ -3227,13 +3230,13 @@ class basic_json
@liveexample{The example below shows how object elements can be read using @liveexample{The example below shows how object elements can be read using
the `[]` operator.,operatorarray__key_type_const} the `[]` operator.,operatorarray__key_type_const}
@sa @ref at(const typename object_t::key_type&) for access by reference @sa @ref at(const key_type&) for access by reference
with range checking with range checking
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@since version 1.0.0 @since version 1.0.0
*/ */
const_reference operator[](const typename object_t::key_type& key) const const_reference operator[](const key_type& key) const
{ {
// const operator[] only works for objects // const operator[] only works for objects
if (JSON_LIKELY(is_object())) if (JSON_LIKELY(is_object()))
@ -3266,7 +3269,7 @@ class basic_json
@liveexample{The example below shows how object elements can be read and @liveexample{The example below shows how object elements can be read and
written using the `[]` operator.,operatorarray__key_type} written using the `[]` operator.,operatorarray__key_type}
@sa @ref at(const typename object_t::key_type&) for access by reference @sa @ref at(const key_type&) for access by reference
with range checking with range checking
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@ -3316,7 +3319,7 @@ class basic_json
@liveexample{The example below shows how object elements can be read using @liveexample{The example below shows how object elements can be read using
the `[]` operator.,operatorarray__key_type_const} the `[]` operator.,operatorarray__key_type_const}
@sa @ref at(const typename object_t::key_type&) for access by reference @sa @ref at(const key_type&) for access by reference
with range checking with range checking
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@ -3350,10 +3353,10 @@ class basic_json
} }
@endcode @endcode
@note Unlike @ref at(const typename object_t::key_type&), this function @note Unlike @ref at(const key_type&), this function
does not throw if the given key @a key was not found. does not throw if the given key @a key was not found.
@note Unlike @ref operator[](const typename object_t::key_type& key), this @note Unlike @ref operator[](const key_type& key), this
function does not implicitly add an element to the position defined by @a function does not implicitly add an element to the position defined by @a
key. This function is furthermore also applicable to const objects. key. This function is furthermore also applicable to const objects.
@ -3376,16 +3379,16 @@ class basic_json
@liveexample{The example below shows how object elements can be queried @liveexample{The example below shows how object elements can be queried
with a default value.,basic_json__value} with a default value.,basic_json__value}
@sa @ref at(const typename object_t::key_type&) for access by reference @sa @ref at(const key_type&) for access by reference
with range checking with range checking
@sa @ref operator[](const typename object_t::key_type&) for unchecked @sa @ref operator[](const key_type&) for unchecked
access by reference access by reference
@since version 1.0.0 @since version 1.0.0
*/ */
template<class ValueType, typename std::enable_if< template<class ValueType, typename std::enable_if<
std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0> std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0>
ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const ValueType value(const key_type& key, const ValueType& default_value) const
{ {
// at only works for objects // at only works for objects
if (JSON_LIKELY(is_object())) if (JSON_LIKELY(is_object()))
@ -3405,9 +3408,9 @@ class basic_json
/*! /*!
@brief overload for a default value of type const char* @brief overload for a default value of type const char*
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const @copydoc basic_json::value(const key_type&, const ValueType&) const
*/ */
string_t value(const typename object_t::key_type& key, const char* default_value) const string_t value(const key_type& key, const char* default_value) const
{ {
return value(key, string_t(default_value)); return value(key, string_t(default_value));
} }
@ -3608,7 +3611,7 @@ class basic_json
@sa @ref erase(IteratorType, IteratorType) -- removes the elements in @sa @ref erase(IteratorType, IteratorType) -- removes the elements in
the given range the given range
@sa @ref erase(const typename object_t::key_type&) -- removes the element @sa @ref erase(const key_type&) -- removes the element
from an object at the given key from an object at the given key
@sa @ref erase(const size_type) -- removes the element from an array at @sa @ref erase(const size_type) -- removes the element from an array at
the given index the given index
@ -3713,7 +3716,7 @@ class basic_json
types.,erase__IteratorType_IteratorType} types.,erase__IteratorType_IteratorType}
@sa @ref erase(IteratorType) -- removes the element at a given position @sa @ref erase(IteratorType) -- removes the element at a given position
@sa @ref erase(const typename object_t::key_type&) -- removes the element @sa @ref erase(const key_type&) -- removes the element
from an object at the given key from an object at the given key
@sa @ref erase(const size_type) -- removes the element from an array at @sa @ref erase(const size_type) -- removes the element from an array at
the given index the given index
@ -3811,7 +3814,7 @@ class basic_json
@since version 1.0.0 @since version 1.0.0
*/ */
size_type erase(const typename object_t::key_type& key) size_type erase(const key_type& key)
{ {
// this erase only works for objects // this erase only works for objects
if (JSON_LIKELY(is_object())) if (JSON_LIKELY(is_object()))
@ -3841,7 +3844,7 @@ class basic_json
@sa @ref erase(IteratorType) -- removes the element at a given position @sa @ref erase(IteratorType) -- removes the element at a given position
@sa @ref erase(IteratorType, IteratorType) -- removes the elements in @sa @ref erase(IteratorType, IteratorType) -- removes the elements in
the given range the given range
@sa @ref erase(const typename object_t::key_type&) -- removes the element @sa @ref erase(const key_type&) -- removes the element
from an object at the given key from an object at the given key
@since version 1.0.0 @since version 1.0.0
@ -7145,7 +7148,7 @@ class basic_json
Uses a JSON pointer to retrieve a reference to the respective JSON value. Uses a JSON pointer to retrieve a reference to the respective JSON value.
No bound checking is performed. Similar to @ref operator[](const typename No bound checking is performed. Similar to @ref operator[](const typename
object_t::key_type&), `null` values are created in arrays and objects if key_type&), `null` values are created in arrays and objects if
necessary. necessary.
In particular: In particular:

View File

@ -12946,6 +12946,9 @@ class basic_json
AllocatorType<std::pair<const StringType, AllocatorType<std::pair<const StringType,
basic_json>>>; basic_json>>>;
using key_type = typename object_t::key_type;
using mapped_type = typename object_t::mapped_type;
/*! /*!
@brief a type for an array @brief a type for an array
@ -15460,7 +15463,7 @@ class basic_json
@complexity Logarithmic in the size of the container. @complexity Logarithmic in the size of the container.
@sa @ref operator[](const typename object_t::key_type&) for unchecked @sa @ref operator[](const key_type&) for unchecked
access by reference access by reference
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@ -15470,7 +15473,7 @@ class basic_json
written using `at()`. It also demonstrates the different exceptions that written using `at()`. It also demonstrates the different exceptions that
can be thrown.,at__object_t_key_type} can be thrown.,at__object_t_key_type}
*/ */
reference at(const typename object_t::key_type& key) reference at(const key_type& key)
{ {
// at only works for objects // at only works for objects
if (JSON_LIKELY(is_object())) if (JSON_LIKELY(is_object()))
@ -15511,7 +15514,7 @@ class basic_json
@complexity Logarithmic in the size of the container. @complexity Logarithmic in the size of the container.
@sa @ref operator[](const typename object_t::key_type&) for unchecked @sa @ref operator[](const key_type&) for unchecked
access by reference access by reference
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@ -15521,7 +15524,7 @@ class basic_json
`at()`. It also demonstrates the different exceptions that can be thrown., `at()`. It also demonstrates the different exceptions that can be thrown.,
at__object_t_key_type_const} at__object_t_key_type_const}
*/ */
const_reference at(const typename object_t::key_type& key) const const_reference at(const key_type& key) const
{ {
// at only works for objects // at only works for objects
if (JSON_LIKELY(is_object())) if (JSON_LIKELY(is_object()))
@ -15645,13 +15648,13 @@ class basic_json
@liveexample{The example below shows how object elements can be read and @liveexample{The example below shows how object elements can be read and
written using the `[]` operator.,operatorarray__key_type} written using the `[]` operator.,operatorarray__key_type}
@sa @ref at(const typename object_t::key_type&) for access by reference @sa @ref at(const key_type&) for access by reference
with range checking with range checking
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@since version 1.0.0 @since version 1.0.0
*/ */
reference operator[](const typename object_t::key_type& key) reference operator[](const key_type& key)
{ {
// implicitly convert null value to an empty object // implicitly convert null value to an empty object
if (is_null()) if (is_null())
@ -15694,13 +15697,13 @@ class basic_json
@liveexample{The example below shows how object elements can be read using @liveexample{The example below shows how object elements can be read using
the `[]` operator.,operatorarray__key_type_const} the `[]` operator.,operatorarray__key_type_const}
@sa @ref at(const typename object_t::key_type&) for access by reference @sa @ref at(const key_type&) for access by reference
with range checking with range checking
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@since version 1.0.0 @since version 1.0.0
*/ */
const_reference operator[](const typename object_t::key_type& key) const const_reference operator[](const key_type& key) const
{ {
// const operator[] only works for objects // const operator[] only works for objects
if (JSON_LIKELY(is_object())) if (JSON_LIKELY(is_object()))
@ -15733,7 +15736,7 @@ class basic_json
@liveexample{The example below shows how object elements can be read and @liveexample{The example below shows how object elements can be read and
written using the `[]` operator.,operatorarray__key_type} written using the `[]` operator.,operatorarray__key_type}
@sa @ref at(const typename object_t::key_type&) for access by reference @sa @ref at(const key_type&) for access by reference
with range checking with range checking
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@ -15783,7 +15786,7 @@ class basic_json
@liveexample{The example below shows how object elements can be read using @liveexample{The example below shows how object elements can be read using
the `[]` operator.,operatorarray__key_type_const} the `[]` operator.,operatorarray__key_type_const}
@sa @ref at(const typename object_t::key_type&) for access by reference @sa @ref at(const key_type&) for access by reference
with range checking with range checking
@sa @ref value() for access by value with a default value @sa @ref value() for access by value with a default value
@ -15817,10 +15820,10 @@ class basic_json
} }
@endcode @endcode
@note Unlike @ref at(const typename object_t::key_type&), this function @note Unlike @ref at(const key_type&), this function
does not throw if the given key @a key was not found. does not throw if the given key @a key was not found.
@note Unlike @ref operator[](const typename object_t::key_type& key), this @note Unlike @ref operator[](const key_type& key), this
function does not implicitly add an element to the position defined by @a function does not implicitly add an element to the position defined by @a
key. This function is furthermore also applicable to const objects. key. This function is furthermore also applicable to const objects.
@ -15843,16 +15846,16 @@ class basic_json
@liveexample{The example below shows how object elements can be queried @liveexample{The example below shows how object elements can be queried
with a default value.,basic_json__value} with a default value.,basic_json__value}
@sa @ref at(const typename object_t::key_type&) for access by reference @sa @ref at(const key_type&) for access by reference
with range checking with range checking
@sa @ref operator[](const typename object_t::key_type&) for unchecked @sa @ref operator[](const key_type&) for unchecked
access by reference access by reference
@since version 1.0.0 @since version 1.0.0
*/ */
template<class ValueType, typename std::enable_if< template<class ValueType, typename std::enable_if<
std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0> std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0>
ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const ValueType value(const key_type& key, const ValueType& default_value) const
{ {
// at only works for objects // at only works for objects
if (JSON_LIKELY(is_object())) if (JSON_LIKELY(is_object()))
@ -15872,9 +15875,9 @@ class basic_json
/*! /*!
@brief overload for a default value of type const char* @brief overload for a default value of type const char*
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const @copydoc basic_json::value(const key_type&, const ValueType&) const
*/ */
string_t value(const typename object_t::key_type& key, const char* default_value) const string_t value(const key_type& key, const char* default_value) const
{ {
return value(key, string_t(default_value)); return value(key, string_t(default_value));
} }
@ -16075,7 +16078,7 @@ class basic_json
@sa @ref erase(IteratorType, IteratorType) -- removes the elements in @sa @ref erase(IteratorType, IteratorType) -- removes the elements in
the given range the given range
@sa @ref erase(const typename object_t::key_type&) -- removes the element @sa @ref erase(const key_type&) -- removes the element
from an object at the given key from an object at the given key
@sa @ref erase(const size_type) -- removes the element from an array at @sa @ref erase(const size_type) -- removes the element from an array at
the given index the given index
@ -16180,7 +16183,7 @@ class basic_json
types.,erase__IteratorType_IteratorType} types.,erase__IteratorType_IteratorType}
@sa @ref erase(IteratorType) -- removes the element at a given position @sa @ref erase(IteratorType) -- removes the element at a given position
@sa @ref erase(const typename object_t::key_type&) -- removes the element @sa @ref erase(const key_type&) -- removes the element
from an object at the given key from an object at the given key
@sa @ref erase(const size_type) -- removes the element from an array at @sa @ref erase(const size_type) -- removes the element from an array at
the given index the given index
@ -16278,7 +16281,7 @@ class basic_json
@since version 1.0.0 @since version 1.0.0
*/ */
size_type erase(const typename object_t::key_type& key) size_type erase(const key_type& key)
{ {
// this erase only works for objects // this erase only works for objects
if (JSON_LIKELY(is_object())) if (JSON_LIKELY(is_object()))
@ -16308,7 +16311,7 @@ class basic_json
@sa @ref erase(IteratorType) -- removes the element at a given position @sa @ref erase(IteratorType) -- removes the element at a given position
@sa @ref erase(IteratorType, IteratorType) -- removes the elements in @sa @ref erase(IteratorType, IteratorType) -- removes the elements in
the given range the given range
@sa @ref erase(const typename object_t::key_type&) -- removes the element @sa @ref erase(const key_type&) -- removes the element
from an object at the given key from an object at the given key
@since version 1.0.0 @since version 1.0.0
@ -19612,7 +19615,7 @@ class basic_json
Uses a JSON pointer to retrieve a reference to the respective JSON value. Uses a JSON pointer to retrieve a reference to the respective JSON value.
No bound checking is performed. Similar to @ref operator[](const typename No bound checking is performed. Similar to @ref operator[](const typename
object_t::key_type&), `null` values are created in arrays and objects if key_type&), `null` values are created in arrays and objects if
necessary. necessary.
In particular: In particular: