Remove need for object_t to be fully instanced, allowing unordered_map
the unordered_map template cannot be instanced with an incomplete type so this patch replaces all places where this is made necessary with alternative though equivilent types.
This commit is contained in:
parent
90ab92ade1
commit
16e8d99967
34
src/json.hpp
34
src/json.hpp
@ -1003,7 +1003,7 @@ class basic_json
|
||||
*/
|
||||
template <class CompatibleObjectType, typename
|
||||
std::enable_if<
|
||||
std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
|
||||
std::is_constructible<StringType, typename CompatibleObjectType::key_type>::value and
|
||||
std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type
|
||||
= 0>
|
||||
basic_json(const CompatibleObjectType& val)
|
||||
@ -2203,7 +2203,7 @@ class basic_json
|
||||
/// get an object (explicit)
|
||||
template <class T, typename
|
||||
std::enable_if<
|
||||
std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
|
||||
std::is_convertible<StringType, typename T::key_type>::value and
|
||||
std::is_convertible<basic_json_t, typename T::mapped_type>::value
|
||||
, int>::type = 0>
|
||||
T get_impl(T*) const
|
||||
@ -2751,7 +2751,7 @@ class basic_json
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
reference at(const typename object_t::key_type& key)
|
||||
reference at(const StringType& key)
|
||||
{
|
||||
// at only works for objects
|
||||
if (is_object())
|
||||
@ -2798,7 +2798,7 @@ class basic_json
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
const_reference at(const typename object_t::key_type& key) const
|
||||
const_reference at(const StringType& key) const
|
||||
{
|
||||
// at only works for objects
|
||||
if (is_object())
|
||||
@ -2928,7 +2928,7 @@ class basic_json
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
reference operator[](const typename object_t::key_type& key)
|
||||
reference operator[](const StringType& key)
|
||||
{
|
||||
// implicitly convert null to object
|
||||
if (is_null())
|
||||
@ -2975,7 +2975,7 @@ class basic_json
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
const_reference operator[](const typename object_t::key_type& key) const
|
||||
const_reference operator[](const StringType& key) const
|
||||
{
|
||||
// [] only works for objects
|
||||
if (is_object())
|
||||
@ -3133,7 +3133,7 @@ class basic_json
|
||||
std::enable_if<
|
||||
std::is_convertible<basic_json_t, ValueType>::value
|
||||
, int>::type = 0>
|
||||
ValueType value(const typename object_t::key_type& key, ValueType default_value) const
|
||||
ValueType value(const StringType& key, ValueType default_value) const
|
||||
{
|
||||
// at only works for objects
|
||||
if (is_object())
|
||||
@ -3159,7 +3159,7 @@ class basic_json
|
||||
@brief overload for a default value of type const char*
|
||||
@copydoc basic_json::value()
|
||||
*/
|
||||
string_t value(const typename object_t::key_type& key, const char* default_value) const
|
||||
string_t value(const StringType& key, const char* default_value) const
|
||||
{
|
||||
return value(key, string_t(default_value));
|
||||
}
|
||||
@ -3469,7 +3469,7 @@ class basic_json
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
size_type erase(const typename object_t::key_type& key)
|
||||
size_type erase(const StringType& key)
|
||||
{
|
||||
// this erase only works for objects
|
||||
if (is_object())
|
||||
@ -3541,7 +3541,7 @@ class basic_json
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
iterator find(typename object_t::key_type key)
|
||||
iterator find(StringType key)
|
||||
{
|
||||
auto result = end();
|
||||
|
||||
@ -3557,7 +3557,7 @@ class basic_json
|
||||
@brief find an element in a JSON object
|
||||
@copydoc find(typename object_t::key_type)
|
||||
*/
|
||||
const_iterator find(typename object_t::key_type key) const
|
||||
const_iterator find(StringType key) const
|
||||
{
|
||||
auto result = cend();
|
||||
|
||||
@ -3587,7 +3587,7 @@ class basic_json
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
size_type count(typename object_t::key_type key) const
|
||||
size_type count(StringType key) const
|
||||
{
|
||||
// return 0 for all nonobject types
|
||||
return is_object() ? m_value.object->count(key) : 0;
|
||||
@ -4220,7 +4220,7 @@ class basic_json
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
void push_back(const typename object_t::value_type& val)
|
||||
void push_back(const std::pair<StringType, basic_json>& val)
|
||||
{
|
||||
// push_back only works for null objects or objects
|
||||
if (not(is_null() or is_object()))
|
||||
@ -4241,9 +4241,9 @@ class basic_json
|
||||
|
||||
/*!
|
||||
@brief add an object to an object
|
||||
@copydoc push_back(const typename object_t::value_type&)
|
||||
@copydoc push_back(const std::pair<StringType, basic_json>&)
|
||||
*/
|
||||
reference operator+=(const typename object_t::value_type& val)
|
||||
reference operator+=(const std::pair<StringType, basic_json>& val)
|
||||
{
|
||||
push_back(val);
|
||||
return operator[](val.first);
|
||||
@ -6083,7 +6083,7 @@ class basic_json
|
||||
}
|
||||
|
||||
/// return the key of an object iterator
|
||||
typename object_t::key_type key() const
|
||||
StringType key() const
|
||||
{
|
||||
if (m_object->is_object())
|
||||
{
|
||||
@ -6340,7 +6340,7 @@ class basic_json
|
||||
}
|
||||
|
||||
/// return the key of an object iterator
|
||||
typename object_t::key_type key() const
|
||||
StringType key() const
|
||||
{
|
||||
auto it = --this->base();
|
||||
return it.key();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user