reverted breaking changes

This commit is contained in:
Niels 2016-07-27 21:40:15 +02:00
parent a7f8c47f68
commit 6297631e22
2 changed files with 350 additions and 118 deletions

View file

@ -621,8 +621,8 @@ class basic_json
> that implementations will agree exactly on their numeric values. > that implementations will agree exactly on their numeric values.
As this range is a subrange (when considered in conjunction with the As this range is a subrange (when considered in conjunction with the
number_integer_t type) of the exactly supported range [0, UINT64_MAX], number_integer_t type) of the exactly supported range [0, UINT64_MAX], this
this class's integer type is interoperable. class's integer type is interoperable.
#### Storage #### Storage
@ -760,7 +760,6 @@ class basic_json
}; };
std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter); std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
alloc.construct(object.get(), std::forward<Args>(args)...); alloc.construct(object.get(), std::forward<Args>(args)...);
assert(object.get() != nullptr);
return object.release(); return object.release();
} }
@ -1416,8 +1415,8 @@ class basic_json
Create an unsigned integer number JSON value with a given content. Create an unsigned integer number JSON value with a given content.
@tparam T helper type to compare number_unsigned_t and unsigned int (not @tparam T helper type to compare number_unsigned_t and unsigned int
visible in) the interface. (not visible in) the interface.
@param[in] val an integer to create a JSON number from @param[in] val an integer to create a JSON number from
@ -1522,8 +1521,8 @@ class basic_json
disallows NaN values: disallows NaN values:
> Numeric values that cannot be represented in the grammar below (such as > Numeric values that cannot be represented in the grammar below (such as
> Infinity and NaN) are not permitted. > Infinity and NaN) are not permitted.
In case the parameter @a val is not a number, a JSON null value is created In case the parameter @a val is not a number, a JSON null value is
instead. created instead.
@complexity Constant. @complexity Constant.
@ -1648,6 +1647,8 @@ class basic_json
m_type = value_t::object; m_type = value_t::object;
m_value = value_t::object; m_value = value_t::object;
assert(m_value.object != nullptr);
std::for_each(init.begin(), init.end(), [this](const basic_json & element) std::for_each(init.begin(), init.end(), [this](const basic_json & element)
{ {
m_value.object->emplace(*(element[0].m_value.string), element[1]); m_value.object->emplace(*(element[0].m_value.string), element[1]);
@ -1805,8 +1806,7 @@ class basic_json
std::is_same<InputIT, typename basic_json_t::const_iterator>::value std::is_same<InputIT, typename basic_json_t::const_iterator>::value
, int>::type , int>::type
= 0> = 0>
basic_json(InputIT first, InputIT last) basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
: m_type(first.m_object->m_type)
{ {
// make sure iterator fits the current value // make sure iterator fits the current value
if (first.m_object != last.m_object) if (first.m_object != last.m_object)
@ -1840,30 +1840,35 @@ class basic_json
{ {
case value_t::number_integer: case value_t::number_integer:
{ {
assert(first.m_object != nullptr);
m_value.number_integer = first.m_object->m_value.number_integer; m_value.number_integer = first.m_object->m_value.number_integer;
break; break;
} }
case value_t::number_unsigned: case value_t::number_unsigned:
{ {
assert(first.m_object != nullptr);
m_value.number_unsigned = first.m_object->m_value.number_unsigned; m_value.number_unsigned = first.m_object->m_value.number_unsigned;
break; break;
} }
case value_t::number_float: case value_t::number_float:
{ {
assert(first.m_object != nullptr);
m_value.number_float = first.m_object->m_value.number_float; m_value.number_float = first.m_object->m_value.number_float;
break; break;
} }
case value_t::boolean: case value_t::boolean:
{ {
assert(first.m_object != nullptr);
m_value.boolean = first.m_object->m_value.boolean; m_value.boolean = first.m_object->m_value.boolean;
break; break;
} }
case value_t::string: case value_t::string:
{ {
assert(first.m_object != nullptr);
m_value = *first.m_object->m_value.string; m_value = *first.m_object->m_value.string;
break; break;
} }
@ -1882,6 +1887,7 @@ class basic_json
default: default:
{ {
assert(first.m_object != nullptr);
throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name()); throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name());
} }
} }
@ -1945,18 +1951,21 @@ class basic_json
{ {
case value_t::object: case value_t::object:
{ {
assert(other.m_value.object != nullptr);
m_value = *other.m_value.object; m_value = *other.m_value.object;
break; break;
} }
case value_t::array: case value_t::array:
{ {
assert(other.m_value.array != nullptr);
m_value = *other.m_value.array; m_value = *other.m_value.array;
break; break;
} }
case value_t::string: case value_t::string:
{ {
assert(other.m_value.string != nullptr);
m_value = *other.m_value.string; m_value = *other.m_value.string;
break; break;
} }
@ -2011,7 +2020,8 @@ class basic_json
@since version 1.0.0 @since version 1.0.0
*/ */
basic_json(basic_json&& other) noexcept basic_json(basic_json&& other) noexcept
: m_type(std::move(other.m_type)), m_value(std::move(other.m_value)) : m_type(std::move(other.m_type)),
m_value(std::move(other.m_value))
{ {
// invalidate payload // invalidate payload
other.m_type = value_t::null; other.m_type = value_t::null;
@ -2533,17 +2543,29 @@ class basic_json
, int>::type = 0> , int>::type = 0>
T get_impl(T*) const T get_impl(T*) const
{ {
return is_object() if (is_object())
? T(m_value.object->begin(), m_value.object->end()) {
: throw std::domain_error("type must be object, but is " + type_name()); assert(m_value.object != nullptr);
return T(m_value.object->begin(), m_value.object->end());
}
else
{
throw std::domain_error("type must be object, but is " + type_name());
}
} }
/// get an object (explicit) /// get an object (explicit)
object_t get_impl(object_t*) const object_t get_impl(object_t*) const
{ {
return is_object() if (is_object())
? *(m_value.object) {
: throw std::domain_error("type must be object, but is " + type_name()); assert(m_value.object != nullptr);
return *(m_value.object);
}
else
{
throw std::domain_error("type must be object, but is " + type_name());
}
} }
/// get an array (explicit) /// get an array (explicit)
@ -2560,6 +2582,7 @@ class basic_json
if (is_array()) if (is_array())
{ {
T to_vector; T to_vector;
assert(m_value.array != nullptr);
std::transform(m_value.array->begin(), m_value.array->end(), std::transform(m_value.array->begin(), m_value.array->end(),
std::inserter(to_vector, to_vector.end()), [](basic_json i) std::inserter(to_vector, to_vector.end()), [](basic_json i)
{ {
@ -2584,6 +2607,7 @@ class basic_json
if (is_array()) if (is_array())
{ {
std::vector<T> to_vector; std::vector<T> to_vector;
assert(m_value.array != nullptr);
to_vector.reserve(m_value.array->size()); to_vector.reserve(m_value.array->size());
std::transform(m_value.array->begin(), m_value.array->end(), std::transform(m_value.array->begin(), m_value.array->end(),
std::inserter(to_vector, to_vector.end()), [](basic_json i) std::inserter(to_vector, to_vector.end()), [](basic_json i)
@ -2606,17 +2630,29 @@ class basic_json
, int>::type = 0> , int>::type = 0>
T get_impl(T*) const T get_impl(T*) const
{ {
return is_array() if (is_array())
? T(m_value.array->begin(), m_value.array->end()) {
: throw std::domain_error("type must be array, but is " + type_name()); assert(m_value.array != nullptr);
return T(m_value.array->begin(), m_value.array->end());
}
else
{
throw std::domain_error("type must be array, but is " + type_name());
}
} }
/// get an array (explicit) /// get an array (explicit)
array_t get_impl(array_t*) const array_t get_impl(array_t*) const
{ {
return is_array() if (is_array())
? *(m_value.array) {
: throw std::domain_error("type must be array, but is " + type_name()); assert(m_value.array != nullptr);
return *(m_value.array);
}
else
{
throw std::domain_error("type must be array, but is " + type_name());
}
} }
/// get a string (explicit) /// get a string (explicit)
@ -2626,9 +2662,15 @@ class basic_json
, int>::type = 0> , int>::type = 0>
T get_impl(T*) const T get_impl(T*) const
{ {
return is_string() if (is_string())
? *m_value.string {
: throw std::domain_error("type must be string, but is " + type_name()); assert(m_value.string != nullptr);
return *m_value.string;
}
else
{
throw std::domain_error("type must be string, but is " + type_name());
}
} }
/// get a number (explicit) /// get a number (explicit)
@ -3098,6 +3140,7 @@ class basic_json
{ {
try try
{ {
assert(m_value.array != nullptr);
return m_value.array->at(idx); return m_value.array->at(idx);
} }
catch (std::out_of_range&) catch (std::out_of_range&)
@ -3141,6 +3184,7 @@ class basic_json
{ {
try try
{ {
assert(m_value.array != nullptr);
return m_value.array->at(idx); return m_value.array->at(idx);
} }
catch (std::out_of_range&) catch (std::out_of_range&)
@ -3188,6 +3232,7 @@ class basic_json
{ {
try try
{ {
assert(m_value.object != nullptr);
return m_value.object->at(key); return m_value.object->at(key);
} }
catch (std::out_of_range&) catch (std::out_of_range&)
@ -3235,6 +3280,7 @@ class basic_json
{ {
try try
{ {
assert(m_value.object != nullptr);
return m_value.object->at(key); return m_value.object->at(key);
} }
catch (std::out_of_range&) catch (std::out_of_range&)
@ -3287,6 +3333,7 @@ class basic_json
if (is_array()) if (is_array())
{ {
// fill up array with null values if given idx is outside range // fill up array with null values if given idx is outside range
assert(m_value.array != nullptr);
if (idx >= m_value.array->size()) if (idx >= m_value.array->size())
{ {
m_value.array->insert(m_value.array->end(), m_value.array->insert(m_value.array->end(),
@ -3324,9 +3371,15 @@ class basic_json
const_reference operator[](size_type idx) const const_reference operator[](size_type idx) const
{ {
// const operator[] only works for arrays // const operator[] only works for arrays
return is_array() if (is_array())
? m_value.array->operator[](idx) {
: throw std::domain_error("cannot use operator[] with " + type_name()); assert(m_value.array != nullptr);
return m_value.array->operator[](idx);
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
} }
/*! /*!
@ -3366,9 +3419,15 @@ class basic_json
} }
// operator[] only works for objects // operator[] only works for objects
return is_object() if (is_object())
? m_value.object->operator[](key) {
: throw std::domain_error("cannot use operator[] with " + type_name()); assert(m_value.object != nullptr);
return m_value.object->operator[](key);
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
} }
/*! /*!
@ -3401,9 +3460,16 @@ class basic_json
const_reference operator[](const typename object_t::key_type& key) const const_reference operator[](const typename object_t::key_type& key) const
{ {
// const operator[] only works for objects // const operator[] only works for objects
return is_object() if (is_object())
? m_value.object->find(key)->second {
: throw std::domain_error("cannot use operator[] with " + type_name()); assert(m_value.object != nullptr);
assert(m_value.object->find(key) != m_value.object->end());
return m_value.object->find(key)->second;
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
} }
/*! /*!
@ -3512,9 +3578,15 @@ class basic_json
} }
// at only works for objects // at only works for objects
return is_object() if (is_object())
? m_value.object->operator[](key) {
: throw std::domain_error("cannot use operator[] with " + type_name()); assert(m_value.object != nullptr);
return m_value.object->operator[](key);
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
} }
/*! /*!
@ -3548,9 +3620,16 @@ class basic_json
const_reference operator[](T* key) const const_reference operator[](T* key) const
{ {
// at only works for objects // at only works for objects
return is_object() if (is_object())
? m_value.object->find(key)->second {
: throw std::domain_error("cannot use operator[] with " + type_name()); assert(m_value.object != nullptr);
assert(m_value.object->find(key) != m_value.object->end());
return m_value.object->find(key)->second;
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
} }
/*! /*!
@ -3880,12 +3959,14 @@ class basic_json
case value_t::object: case value_t::object:
{ {
assert(m_value.object != nullptr);
result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator); result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
break; break;
} }
case value_t::array: case value_t::array:
{ {
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator); result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
break; break;
} }
@ -3986,6 +4067,7 @@ class basic_json
case value_t::object: case value_t::object:
{ {
assert(m_value.object != nullptr);
result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator, result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
last.m_it.object_iterator); last.m_it.object_iterator);
break; break;
@ -3993,6 +4075,7 @@ class basic_json
case value_t::array: case value_t::array:
{ {
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator, result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
last.m_it.array_iterator); last.m_it.array_iterator);
break; break;
@ -4039,9 +4122,15 @@ class basic_json
size_type erase(const typename object_t::key_type& key) size_type erase(const typename object_t::key_type& key)
{ {
// this erase only works for objects // this erase only works for objects
return is_object() if (is_object())
? m_value.object->erase(key) {
: throw std::domain_error("cannot use erase() with " + type_name()); assert(m_value.object != nullptr);
return m_value.object->erase(key);
}
else
{
throw std::domain_error("cannot use erase() with " + type_name());
}
} }
/*! /*!
@ -4078,6 +4167,7 @@ class basic_json
throw std::out_of_range("array index " + std::to_string(idx) + " is out of range"); throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
} }
assert(m_value.array != nullptr);
m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx)); m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
} }
else else
@ -4120,6 +4210,7 @@ class basic_json
if (is_object()) if (is_object())
{ {
assert(m_value.object != nullptr);
result.m_it.object_iterator = m_value.object->find(key); result.m_it.object_iterator = m_value.object->find(key);
} }
@ -4136,6 +4227,7 @@ class basic_json
if (is_object()) if (is_object())
{ {
assert(m_value.object != nullptr);
result.m_it.object_iterator = m_value.object->find(key); result.m_it.object_iterator = m_value.object->find(key);
} }
@ -4163,6 +4255,7 @@ class basic_json
size_type count(typename object_t::key_type key) const size_type count(typename object_t::key_type key) const
{ {
// return 0 for all nonobject types // return 0 for all nonobject types
assert(not is_object() or m_value.object != nullptr);
return is_object() ? m_value.object->count(key) : 0; return is_object() ? m_value.object->count(key) : 0;
} }
@ -4504,10 +4597,6 @@ class basic_json
object | result of function `object_t::empty()` object | result of function `object_t::empty()`
array | result of function `array_t::empty()` array | result of function `array_t::empty()`
@note This function does not return whether a string stored as JSON value
is empty - it returns whether the JSON container itself is empty which is
false in the case of a string.
@complexity Constant, as long as @ref array_t and @ref object_t satisfy @complexity Constant, as long as @ref array_t and @ref object_t satisfy
the Container concept; that is, their `empty()` functions have constant the Container concept; that is, their `empty()` functions have constant
complexity. complexity.
@ -4537,13 +4626,13 @@ class basic_json
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::empty() assert(m_value.array != nullptr);
return m_value.array->empty(); return m_value.array->empty();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::empty() assert(m_value.object != nullptr);
return m_value.object->empty(); return m_value.object->empty();
} }
@ -4571,10 +4660,6 @@ class basic_json
object | result of function object_t::size() object | result of function object_t::size()
array | result of function array_t::size() array | result of function array_t::size()
@note This function does not return the length of a string stored as JSON
value - it returns the number of elements in the JSON value which is 1 in
the case of a string.
@complexity Constant, as long as @ref array_t and @ref object_t satisfy @complexity Constant, as long as @ref array_t and @ref object_t satisfy
the Container concept; that is, their size() functions have constant the Container concept; that is, their size() functions have constant
complexity. complexity.
@ -4605,13 +4690,13 @@ class basic_json
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::size() assert(m_value.array != nullptr);
return m_value.array->size(); return m_value.array->size();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::size() assert(m_value.object != nullptr);
return m_value.object->size(); return m_value.object->size();
} }
@ -4665,13 +4750,13 @@ class basic_json
{ {
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::max_size() assert(m_value.array != nullptr);
return m_value.array->max_size(); return m_value.array->max_size();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::max_size() assert(m_value.object != nullptr);
return m_value.object->max_size(); return m_value.object->max_size();
} }
@ -4748,18 +4833,21 @@ class basic_json
case value_t::string: case value_t::string:
{ {
assert(m_value.string != nullptr);
m_value.string->clear(); m_value.string->clear();
break; break;
} }
case value_t::array: case value_t::array:
{ {
assert(m_value.array != nullptr);
m_value.array->clear(); m_value.array->clear();
break; break;
} }
case value_t::object: case value_t::object:
{ {
assert(m_value.object != nullptr);
m_value.object->clear(); m_value.object->clear();
break; break;
} }
@ -4807,6 +4895,7 @@ class basic_json
} }
// add element to array (move semantics) // add element to array (move semantics)
assert(m_value.array != nullptr);
m_value.array->push_back(std::move(val)); m_value.array->push_back(std::move(val));
// invalidate object // invalidate object
val.m_type = value_t::null; val.m_type = value_t::null;
@ -4842,6 +4931,7 @@ class basic_json
} }
// add element to array // add element to array
assert(m_value.array != nullptr);
m_value.array->push_back(val); m_value.array->push_back(val);
} }
@ -4891,6 +4981,7 @@ class basic_json
} }
// add element to array // add element to array
assert(m_value.object != nullptr);
m_value.object->insert(val); m_value.object->insert(val);
} }
@ -4987,6 +5078,7 @@ class basic_json
// insert to array and return iterator // insert to array and return iterator
iterator result(this); iterator result(this);
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val); result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
return result; return result;
} }
@ -5042,6 +5134,7 @@ class basic_json
// insert to array and return iterator // insert to array and return iterator
iterator result(this); iterator result(this);
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val); result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
return result; return result;
} }
@ -5108,6 +5201,7 @@ class basic_json
// insert to array and return iterator // insert to array and return iterator
iterator result(this); iterator result(this);
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->insert( result.m_it.array_iterator = m_value.array->insert(
pos.m_it.array_iterator, pos.m_it.array_iterator,
first.m_it.array_iterator, first.m_it.array_iterator,
@ -5155,6 +5249,7 @@ class basic_json
// insert to array and return iterator // insert to array and return iterator
iterator result(this); iterator result(this);
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist); result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist);
return result; return result;
} }
@ -5212,6 +5307,7 @@ class basic_json
// swap only works for arrays // swap only works for arrays
if (is_array()) if (is_array())
{ {
assert(m_value.array != nullptr);
std::swap(*(m_value.array), other); std::swap(*(m_value.array), other);
} }
else else
@ -5245,6 +5341,7 @@ class basic_json
// swap only works for objects // swap only works for objects
if (is_object()) if (is_object())
{ {
assert(m_value.object != nullptr);
std::swap(*(m_value.object), other); std::swap(*(m_value.object), other);
} }
else else
@ -5278,6 +5375,7 @@ class basic_json
// swap only works for strings // swap only works for strings
if (is_string()) if (is_string())
{ {
assert(m_value.string != nullptr);
std::swap(*(m_value.string), other); std::swap(*(m_value.string), other);
} }
else else
@ -5364,10 +5462,14 @@ class basic_json
{ {
case value_t::array: case value_t::array:
{ {
assert(lhs.m_value.array != nullptr);
assert(rhs.m_value.array != nullptr);
return *lhs.m_value.array == *rhs.m_value.array; return *lhs.m_value.array == *rhs.m_value.array;
} }
case value_t::object: case value_t::object:
{ {
assert(lhs.m_value.object != nullptr);
assert(rhs.m_value.object != nullptr);
return *lhs.m_value.object == *rhs.m_value.object; return *lhs.m_value.object == *rhs.m_value.object;
} }
case value_t::null: case value_t::null:
@ -5376,6 +5478,8 @@ class basic_json
} }
case value_t::string: case value_t::string:
{ {
assert(lhs.m_value.string != nullptr);
assert(rhs.m_value.string != nullptr);
return *lhs.m_value.string == *rhs.m_value.string; return *lhs.m_value.string == *rhs.m_value.string;
} }
case value_t::boolean: case value_t::boolean:
@ -5548,10 +5652,14 @@ class basic_json
{ {
case value_t::array: case value_t::array:
{ {
assert(lhs.m_value.array != nullptr);
assert(rhs.m_value.array != nullptr);
return *lhs.m_value.array < *rhs.m_value.array; return *lhs.m_value.array < *rhs.m_value.array;
} }
case value_t::object: case value_t::object:
{ {
assert(lhs.m_value.object != nullptr);
assert(rhs.m_value.object != nullptr);
return *lhs.m_value.object < *rhs.m_value.object; return *lhs.m_value.object < *rhs.m_value.object;
} }
case value_t::null: case value_t::null:
@ -5560,6 +5668,8 @@ class basic_json
} }
case value_t::string: case value_t::string:
{ {
assert(lhs.m_value.string != nullptr);
assert(rhs.m_value.string != nullptr);
return *lhs.m_value.string < *rhs.m_value.string; return *lhs.m_value.string < *rhs.m_value.string;
} }
case value_t::boolean: case value_t::boolean:
@ -5734,14 +5844,14 @@ class basic_json
// string->float->string, string->double->string or string->long // string->float->string, string->double->string or string->long
// double->string; to be safe, we read this value from // double->string; to be safe, we read this value from
// std::numeric_limits<number_float_t>::digits10 // std::numeric_limits<number_float_t>::digits10
const auto old_precision = o.precision(std::numeric_limits<double>::digits10); const auto old_preicison = o.precision(std::numeric_limits<double>::digits10);
// do the actual serialization // do the actual serialization
j.dump(o, pretty_print, static_cast<unsigned int>(indentation)); j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
// reset locale and precision // reset locale and precision
o.imbue(old_locale); o.imbue(old_locale);
o.precision(old_precision); o.precision(old_preicison);
return o; return o;
} }
@ -6091,6 +6201,8 @@ class basic_json
{ {
case value_t::object: case value_t::object:
{ {
assert(m_value.object != nullptr);
if (m_value.object->empty()) if (m_value.object->empty())
{ {
o << "{}"; o << "{}";
@ -6131,6 +6243,8 @@ class basic_json
case value_t::array: case value_t::array:
{ {
assert(m_value.array != nullptr);
if (m_value.array->empty()) if (m_value.array->empty())
{ {
o << "[]"; o << "[]";
@ -6169,6 +6283,7 @@ class basic_json
case value_t::string: case value_t::string:
{ {
assert(m_value.string != nullptr);
o << string_t("\"") << escape_string(*m_value.string) << "\""; o << string_t("\"") << escape_string(*m_value.string) << "\"";
return; return;
} }
@ -9407,6 +9522,7 @@ basic_json_parser_63:
basic_json result; basic_json result;
// iterate the JSON object values // iterate the JSON object values
assert(value.m_value.object != nullptr);
for (const auto& element : *value.m_value.object) for (const auto& element : *value.m_value.object)
{ {
if (not element.second.is_primitive()) if (not element.second.is_primitive())

View file

@ -621,8 +621,8 @@ class basic_json
> that implementations will agree exactly on their numeric values. > that implementations will agree exactly on their numeric values.
As this range is a subrange (when considered in conjunction with the As this range is a subrange (when considered in conjunction with the
number_integer_t type) of the exactly supported range [0, UINT64_MAX], number_integer_t type) of the exactly supported range [0, UINT64_MAX], this
this class's integer type is interoperable. class's integer type is interoperable.
#### Storage #### Storage
@ -760,7 +760,6 @@ class basic_json
}; };
std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter); std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
alloc.construct(object.get(), std::forward<Args>(args)...); alloc.construct(object.get(), std::forward<Args>(args)...);
assert(object.get() != nullptr);
return object.release(); return object.release();
} }
@ -1416,8 +1415,8 @@ class basic_json
Create an unsigned integer number JSON value with a given content. Create an unsigned integer number JSON value with a given content.
@tparam T helper type to compare number_unsigned_t and unsigned int (not @tparam T helper type to compare number_unsigned_t and unsigned int
visible in) the interface. (not visible in) the interface.
@param[in] val an integer to create a JSON number from @param[in] val an integer to create a JSON number from
@ -1522,8 +1521,8 @@ class basic_json
disallows NaN values: disallows NaN values:
> Numeric values that cannot be represented in the grammar below (such as > Numeric values that cannot be represented in the grammar below (such as
> Infinity and NaN) are not permitted. > Infinity and NaN) are not permitted.
In case the parameter @a val is not a number, a JSON null value is created In case the parameter @a val is not a number, a JSON null value is
instead. created instead.
@complexity Constant. @complexity Constant.
@ -1648,6 +1647,8 @@ class basic_json
m_type = value_t::object; m_type = value_t::object;
m_value = value_t::object; m_value = value_t::object;
assert(m_value.object != nullptr);
std::for_each(init.begin(), init.end(), [this](const basic_json & element) std::for_each(init.begin(), init.end(), [this](const basic_json & element)
{ {
m_value.object->emplace(*(element[0].m_value.string), element[1]); m_value.object->emplace(*(element[0].m_value.string), element[1]);
@ -1805,8 +1806,7 @@ class basic_json
std::is_same<InputIT, typename basic_json_t::const_iterator>::value std::is_same<InputIT, typename basic_json_t::const_iterator>::value
, int>::type , int>::type
= 0> = 0>
basic_json(InputIT first, InputIT last) basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
: m_type(first.m_object->m_type)
{ {
// make sure iterator fits the current value // make sure iterator fits the current value
if (first.m_object != last.m_object) if (first.m_object != last.m_object)
@ -1840,30 +1840,35 @@ class basic_json
{ {
case value_t::number_integer: case value_t::number_integer:
{ {
assert(first.m_object != nullptr);
m_value.number_integer = first.m_object->m_value.number_integer; m_value.number_integer = first.m_object->m_value.number_integer;
break; break;
} }
case value_t::number_unsigned: case value_t::number_unsigned:
{ {
assert(first.m_object != nullptr);
m_value.number_unsigned = first.m_object->m_value.number_unsigned; m_value.number_unsigned = first.m_object->m_value.number_unsigned;
break; break;
} }
case value_t::number_float: case value_t::number_float:
{ {
assert(first.m_object != nullptr);
m_value.number_float = first.m_object->m_value.number_float; m_value.number_float = first.m_object->m_value.number_float;
break; break;
} }
case value_t::boolean: case value_t::boolean:
{ {
assert(first.m_object != nullptr);
m_value.boolean = first.m_object->m_value.boolean; m_value.boolean = first.m_object->m_value.boolean;
break; break;
} }
case value_t::string: case value_t::string:
{ {
assert(first.m_object != nullptr);
m_value = *first.m_object->m_value.string; m_value = *first.m_object->m_value.string;
break; break;
} }
@ -1882,6 +1887,7 @@ class basic_json
default: default:
{ {
assert(first.m_object != nullptr);
throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name()); throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name());
} }
} }
@ -1945,18 +1951,21 @@ class basic_json
{ {
case value_t::object: case value_t::object:
{ {
assert(other.m_value.object != nullptr);
m_value = *other.m_value.object; m_value = *other.m_value.object;
break; break;
} }
case value_t::array: case value_t::array:
{ {
assert(other.m_value.array != nullptr);
m_value = *other.m_value.array; m_value = *other.m_value.array;
break; break;
} }
case value_t::string: case value_t::string:
{ {
assert(other.m_value.string != nullptr);
m_value = *other.m_value.string; m_value = *other.m_value.string;
break; break;
} }
@ -2011,7 +2020,8 @@ class basic_json
@since version 1.0.0 @since version 1.0.0
*/ */
basic_json(basic_json&& other) noexcept basic_json(basic_json&& other) noexcept
: m_type(std::move(other.m_type)), m_value(std::move(other.m_value)) : m_type(std::move(other.m_type)),
m_value(std::move(other.m_value))
{ {
// invalidate payload // invalidate payload
other.m_type = value_t::null; other.m_type = value_t::null;
@ -2533,17 +2543,29 @@ class basic_json
, int>::type = 0> , int>::type = 0>
T get_impl(T*) const T get_impl(T*) const
{ {
return is_object() if (is_object())
? T(m_value.object->begin(), m_value.object->end()) {
: throw std::domain_error("type must be object, but is " + type_name()); assert(m_value.object != nullptr);
return T(m_value.object->begin(), m_value.object->end());
}
else
{
throw std::domain_error("type must be object, but is " + type_name());
}
} }
/// get an object (explicit) /// get an object (explicit)
object_t get_impl(object_t*) const object_t get_impl(object_t*) const
{ {
return is_object() if (is_object())
? *(m_value.object) {
: throw std::domain_error("type must be object, but is " + type_name()); assert(m_value.object != nullptr);
return *(m_value.object);
}
else
{
throw std::domain_error("type must be object, but is " + type_name());
}
} }
/// get an array (explicit) /// get an array (explicit)
@ -2560,6 +2582,7 @@ class basic_json
if (is_array()) if (is_array())
{ {
T to_vector; T to_vector;
assert(m_value.array != nullptr);
std::transform(m_value.array->begin(), m_value.array->end(), std::transform(m_value.array->begin(), m_value.array->end(),
std::inserter(to_vector, to_vector.end()), [](basic_json i) std::inserter(to_vector, to_vector.end()), [](basic_json i)
{ {
@ -2584,6 +2607,7 @@ class basic_json
if (is_array()) if (is_array())
{ {
std::vector<T> to_vector; std::vector<T> to_vector;
assert(m_value.array != nullptr);
to_vector.reserve(m_value.array->size()); to_vector.reserve(m_value.array->size());
std::transform(m_value.array->begin(), m_value.array->end(), std::transform(m_value.array->begin(), m_value.array->end(),
std::inserter(to_vector, to_vector.end()), [](basic_json i) std::inserter(to_vector, to_vector.end()), [](basic_json i)
@ -2606,17 +2630,29 @@ class basic_json
, int>::type = 0> , int>::type = 0>
T get_impl(T*) const T get_impl(T*) const
{ {
return is_array() if (is_array())
? T(m_value.array->begin(), m_value.array->end()) {
: throw std::domain_error("type must be array, but is " + type_name()); assert(m_value.array != nullptr);
return T(m_value.array->begin(), m_value.array->end());
}
else
{
throw std::domain_error("type must be array, but is " + type_name());
}
} }
/// get an array (explicit) /// get an array (explicit)
array_t get_impl(array_t*) const array_t get_impl(array_t*) const
{ {
return is_array() if (is_array())
? *(m_value.array) {
: throw std::domain_error("type must be array, but is " + type_name()); assert(m_value.array != nullptr);
return *(m_value.array);
}
else
{
throw std::domain_error("type must be array, but is " + type_name());
}
} }
/// get a string (explicit) /// get a string (explicit)
@ -2626,9 +2662,15 @@ class basic_json
, int>::type = 0> , int>::type = 0>
T get_impl(T*) const T get_impl(T*) const
{ {
return is_string() if (is_string())
? *m_value.string {
: throw std::domain_error("type must be string, but is " + type_name()); assert(m_value.string != nullptr);
return *m_value.string;
}
else
{
throw std::domain_error("type must be string, but is " + type_name());
}
} }
/// get a number (explicit) /// get a number (explicit)
@ -3098,6 +3140,7 @@ class basic_json
{ {
try try
{ {
assert(m_value.array != nullptr);
return m_value.array->at(idx); return m_value.array->at(idx);
} }
catch (std::out_of_range&) catch (std::out_of_range&)
@ -3141,6 +3184,7 @@ class basic_json
{ {
try try
{ {
assert(m_value.array != nullptr);
return m_value.array->at(idx); return m_value.array->at(idx);
} }
catch (std::out_of_range&) catch (std::out_of_range&)
@ -3188,6 +3232,7 @@ class basic_json
{ {
try try
{ {
assert(m_value.object != nullptr);
return m_value.object->at(key); return m_value.object->at(key);
} }
catch (std::out_of_range&) catch (std::out_of_range&)
@ -3235,6 +3280,7 @@ class basic_json
{ {
try try
{ {
assert(m_value.object != nullptr);
return m_value.object->at(key); return m_value.object->at(key);
} }
catch (std::out_of_range&) catch (std::out_of_range&)
@ -3287,6 +3333,7 @@ class basic_json
if (is_array()) if (is_array())
{ {
// fill up array with null values if given idx is outside range // fill up array with null values if given idx is outside range
assert(m_value.array != nullptr);
if (idx >= m_value.array->size()) if (idx >= m_value.array->size())
{ {
m_value.array->insert(m_value.array->end(), m_value.array->insert(m_value.array->end(),
@ -3324,9 +3371,15 @@ class basic_json
const_reference operator[](size_type idx) const const_reference operator[](size_type idx) const
{ {
// const operator[] only works for arrays // const operator[] only works for arrays
return is_array() if (is_array())
? m_value.array->operator[](idx) {
: throw std::domain_error("cannot use operator[] with " + type_name()); assert(m_value.array != nullptr);
return m_value.array->operator[](idx);
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
} }
/*! /*!
@ -3366,9 +3419,15 @@ class basic_json
} }
// operator[] only works for objects // operator[] only works for objects
return is_object() if (is_object())
? m_value.object->operator[](key) {
: throw std::domain_error("cannot use operator[] with " + type_name()); assert(m_value.object != nullptr);
return m_value.object->operator[](key);
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
} }
/*! /*!
@ -3401,9 +3460,16 @@ class basic_json
const_reference operator[](const typename object_t::key_type& key) const const_reference operator[](const typename object_t::key_type& key) const
{ {
// const operator[] only works for objects // const operator[] only works for objects
return is_object() if (is_object())
? m_value.object->find(key)->second {
: throw std::domain_error("cannot use operator[] with " + type_name()); assert(m_value.object != nullptr);
assert(m_value.object->find(key) != m_value.object->end());
return m_value.object->find(key)->second;
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
} }
/*! /*!
@ -3512,9 +3578,15 @@ class basic_json
} }
// at only works for objects // at only works for objects
return is_object() if (is_object())
? m_value.object->operator[](key) {
: throw std::domain_error("cannot use operator[] with " + type_name()); assert(m_value.object != nullptr);
return m_value.object->operator[](key);
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
} }
/*! /*!
@ -3548,9 +3620,16 @@ class basic_json
const_reference operator[](T* key) const const_reference operator[](T* key) const
{ {
// at only works for objects // at only works for objects
return is_object() if (is_object())
? m_value.object->find(key)->second {
: throw std::domain_error("cannot use operator[] with " + type_name()); assert(m_value.object != nullptr);
assert(m_value.object->find(key) != m_value.object->end());
return m_value.object->find(key)->second;
}
else
{
throw std::domain_error("cannot use operator[] with " + type_name());
}
} }
/*! /*!
@ -3880,12 +3959,14 @@ class basic_json
case value_t::object: case value_t::object:
{ {
assert(m_value.object != nullptr);
result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator); result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
break; break;
} }
case value_t::array: case value_t::array:
{ {
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator); result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
break; break;
} }
@ -3986,6 +4067,7 @@ class basic_json
case value_t::object: case value_t::object:
{ {
assert(m_value.object != nullptr);
result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator, result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
last.m_it.object_iterator); last.m_it.object_iterator);
break; break;
@ -3993,6 +4075,7 @@ class basic_json
case value_t::array: case value_t::array:
{ {
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator, result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
last.m_it.array_iterator); last.m_it.array_iterator);
break; break;
@ -4039,9 +4122,15 @@ class basic_json
size_type erase(const typename object_t::key_type& key) size_type erase(const typename object_t::key_type& key)
{ {
// this erase only works for objects // this erase only works for objects
return is_object() if (is_object())
? m_value.object->erase(key) {
: throw std::domain_error("cannot use erase() with " + type_name()); assert(m_value.object != nullptr);
return m_value.object->erase(key);
}
else
{
throw std::domain_error("cannot use erase() with " + type_name());
}
} }
/*! /*!
@ -4078,6 +4167,7 @@ class basic_json
throw std::out_of_range("array index " + std::to_string(idx) + " is out of range"); throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
} }
assert(m_value.array != nullptr);
m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx)); m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
} }
else else
@ -4120,6 +4210,7 @@ class basic_json
if (is_object()) if (is_object())
{ {
assert(m_value.object != nullptr);
result.m_it.object_iterator = m_value.object->find(key); result.m_it.object_iterator = m_value.object->find(key);
} }
@ -4136,6 +4227,7 @@ class basic_json
if (is_object()) if (is_object())
{ {
assert(m_value.object != nullptr);
result.m_it.object_iterator = m_value.object->find(key); result.m_it.object_iterator = m_value.object->find(key);
} }
@ -4163,6 +4255,7 @@ class basic_json
size_type count(typename object_t::key_type key) const size_type count(typename object_t::key_type key) const
{ {
// return 0 for all nonobject types // return 0 for all nonobject types
assert(not is_object() or m_value.object != nullptr);
return is_object() ? m_value.object->count(key) : 0; return is_object() ? m_value.object->count(key) : 0;
} }
@ -4504,10 +4597,6 @@ class basic_json
object | result of function `object_t::empty()` object | result of function `object_t::empty()`
array | result of function `array_t::empty()` array | result of function `array_t::empty()`
@note This function does not return whether a string stored as JSON value
is empty - it returns whether the JSON container itself is empty which is
false in the case of a string.
@complexity Constant, as long as @ref array_t and @ref object_t satisfy @complexity Constant, as long as @ref array_t and @ref object_t satisfy
the Container concept; that is, their `empty()` functions have constant the Container concept; that is, their `empty()` functions have constant
complexity. complexity.
@ -4537,13 +4626,13 @@ class basic_json
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::empty() assert(m_value.array != nullptr);
return m_value.array->empty(); return m_value.array->empty();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::empty() assert(m_value.object != nullptr);
return m_value.object->empty(); return m_value.object->empty();
} }
@ -4571,10 +4660,6 @@ class basic_json
object | result of function object_t::size() object | result of function object_t::size()
array | result of function array_t::size() array | result of function array_t::size()
@note This function does not return the length of a string stored as JSON
value - it returns the number of elements in the JSON value which is 1 in
the case of a string.
@complexity Constant, as long as @ref array_t and @ref object_t satisfy @complexity Constant, as long as @ref array_t and @ref object_t satisfy
the Container concept; that is, their size() functions have constant the Container concept; that is, their size() functions have constant
complexity. complexity.
@ -4605,13 +4690,13 @@ class basic_json
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::size() assert(m_value.array != nullptr);
return m_value.array->size(); return m_value.array->size();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::size() assert(m_value.object != nullptr);
return m_value.object->size(); return m_value.object->size();
} }
@ -4665,13 +4750,13 @@ class basic_json
{ {
case value_t::array: case value_t::array:
{ {
// delegate call to array_t::max_size() assert(m_value.array != nullptr);
return m_value.array->max_size(); return m_value.array->max_size();
} }
case value_t::object: case value_t::object:
{ {
// delegate call to object_t::max_size() assert(m_value.object != nullptr);
return m_value.object->max_size(); return m_value.object->max_size();
} }
@ -4748,18 +4833,21 @@ class basic_json
case value_t::string: case value_t::string:
{ {
assert(m_value.string != nullptr);
m_value.string->clear(); m_value.string->clear();
break; break;
} }
case value_t::array: case value_t::array:
{ {
assert(m_value.array != nullptr);
m_value.array->clear(); m_value.array->clear();
break; break;
} }
case value_t::object: case value_t::object:
{ {
assert(m_value.object != nullptr);
m_value.object->clear(); m_value.object->clear();
break; break;
} }
@ -4807,6 +4895,7 @@ class basic_json
} }
// add element to array (move semantics) // add element to array (move semantics)
assert(m_value.array != nullptr);
m_value.array->push_back(std::move(val)); m_value.array->push_back(std::move(val));
// invalidate object // invalidate object
val.m_type = value_t::null; val.m_type = value_t::null;
@ -4842,6 +4931,7 @@ class basic_json
} }
// add element to array // add element to array
assert(m_value.array != nullptr);
m_value.array->push_back(val); m_value.array->push_back(val);
} }
@ -4891,6 +4981,7 @@ class basic_json
} }
// add element to array // add element to array
assert(m_value.object != nullptr);
m_value.object->insert(val); m_value.object->insert(val);
} }
@ -4987,6 +5078,7 @@ class basic_json
// insert to array and return iterator // insert to array and return iterator
iterator result(this); iterator result(this);
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val); result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
return result; return result;
} }
@ -5042,6 +5134,7 @@ class basic_json
// insert to array and return iterator // insert to array and return iterator
iterator result(this); iterator result(this);
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val); result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
return result; return result;
} }
@ -5108,6 +5201,7 @@ class basic_json
// insert to array and return iterator // insert to array and return iterator
iterator result(this); iterator result(this);
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->insert( result.m_it.array_iterator = m_value.array->insert(
pos.m_it.array_iterator, pos.m_it.array_iterator,
first.m_it.array_iterator, first.m_it.array_iterator,
@ -5155,6 +5249,7 @@ class basic_json
// insert to array and return iterator // insert to array and return iterator
iterator result(this); iterator result(this);
assert(m_value.array != nullptr);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist); result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist);
return result; return result;
} }
@ -5212,6 +5307,7 @@ class basic_json
// swap only works for arrays // swap only works for arrays
if (is_array()) if (is_array())
{ {
assert(m_value.array != nullptr);
std::swap(*(m_value.array), other); std::swap(*(m_value.array), other);
} }
else else
@ -5245,6 +5341,7 @@ class basic_json
// swap only works for objects // swap only works for objects
if (is_object()) if (is_object())
{ {
assert(m_value.object != nullptr);
std::swap(*(m_value.object), other); std::swap(*(m_value.object), other);
} }
else else
@ -5278,6 +5375,7 @@ class basic_json
// swap only works for strings // swap only works for strings
if (is_string()) if (is_string())
{ {
assert(m_value.string != nullptr);
std::swap(*(m_value.string), other); std::swap(*(m_value.string), other);
} }
else else
@ -5364,10 +5462,14 @@ class basic_json
{ {
case value_t::array: case value_t::array:
{ {
assert(lhs.m_value.array != nullptr);
assert(rhs.m_value.array != nullptr);
return *lhs.m_value.array == *rhs.m_value.array; return *lhs.m_value.array == *rhs.m_value.array;
} }
case value_t::object: case value_t::object:
{ {
assert(lhs.m_value.object != nullptr);
assert(rhs.m_value.object != nullptr);
return *lhs.m_value.object == *rhs.m_value.object; return *lhs.m_value.object == *rhs.m_value.object;
} }
case value_t::null: case value_t::null:
@ -5376,6 +5478,8 @@ class basic_json
} }
case value_t::string: case value_t::string:
{ {
assert(lhs.m_value.string != nullptr);
assert(rhs.m_value.string != nullptr);
return *lhs.m_value.string == *rhs.m_value.string; return *lhs.m_value.string == *rhs.m_value.string;
} }
case value_t::boolean: case value_t::boolean:
@ -5548,10 +5652,14 @@ class basic_json
{ {
case value_t::array: case value_t::array:
{ {
assert(lhs.m_value.array != nullptr);
assert(rhs.m_value.array != nullptr);
return *lhs.m_value.array < *rhs.m_value.array; return *lhs.m_value.array < *rhs.m_value.array;
} }
case value_t::object: case value_t::object:
{ {
assert(lhs.m_value.object != nullptr);
assert(rhs.m_value.object != nullptr);
return *lhs.m_value.object < *rhs.m_value.object; return *lhs.m_value.object < *rhs.m_value.object;
} }
case value_t::null: case value_t::null:
@ -5560,6 +5668,8 @@ class basic_json
} }
case value_t::string: case value_t::string:
{ {
assert(lhs.m_value.string != nullptr);
assert(rhs.m_value.string != nullptr);
return *lhs.m_value.string < *rhs.m_value.string; return *lhs.m_value.string < *rhs.m_value.string;
} }
case value_t::boolean: case value_t::boolean:
@ -5734,14 +5844,14 @@ class basic_json
// string->float->string, string->double->string or string->long // string->float->string, string->double->string or string->long
// double->string; to be safe, we read this value from // double->string; to be safe, we read this value from
// std::numeric_limits<number_float_t>::digits10 // std::numeric_limits<number_float_t>::digits10
const auto old_precision = o.precision(std::numeric_limits<double>::digits10); const auto old_preicison = o.precision(std::numeric_limits<double>::digits10);
// do the actual serialization // do the actual serialization
j.dump(o, pretty_print, static_cast<unsigned int>(indentation)); j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
// reset locale and precision // reset locale and precision
o.imbue(old_locale); o.imbue(old_locale);
o.precision(old_precision); o.precision(old_preicison);
return o; return o;
} }
@ -6091,6 +6201,8 @@ class basic_json
{ {
case value_t::object: case value_t::object:
{ {
assert(m_value.object != nullptr);
if (m_value.object->empty()) if (m_value.object->empty())
{ {
o << "{}"; o << "{}";
@ -6131,6 +6243,8 @@ class basic_json
case value_t::array: case value_t::array:
{ {
assert(m_value.array != nullptr);
if (m_value.array->empty()) if (m_value.array->empty())
{ {
o << "[]"; o << "[]";
@ -6169,6 +6283,7 @@ class basic_json
case value_t::string: case value_t::string:
{ {
assert(m_value.string != nullptr);
o << string_t("\"") << escape_string(*m_value.string) << "\""; o << string_t("\"") << escape_string(*m_value.string) << "\"";
return; return;
} }
@ -8704,6 +8819,7 @@ class basic_json
basic_json result; basic_json result;
// iterate the JSON object values // iterate the JSON object values
assert(value.m_value.object != nullptr);
for (const auto& element : *value.m_value.object) for (const auto& element : *value.m_value.object)
{ {
if (not element.second.is_primitive()) if (not element.second.is_primitive())