1
0
mirror of https://github.com/nlohmann/json.git synced 2025-08-07 18:02:57 +03:00

Merge branch 'feature/hedley' into develop

This commit is contained in:
Niels Lohmann
2019-07-14 20:58:08 +02:00
35 changed files with 5861 additions and 959 deletions

View File

@@ -319,7 +319,7 @@ class basic_json
@since 2.1.0
*/
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json meta()
{
basic_json result;
@@ -824,6 +824,7 @@ class basic_json
/// helper for exception-safe object creation
template<typename T, typename... Args>
JSON_HEDLEY_RETURNS_NON_NULL
static T* create(Args&& ... args)
{
AllocatorType<T> alloc;
@@ -950,7 +951,7 @@ class basic_json
default:
{
object = nullptr; // silence warning, see #821
if (JSON_UNLIKELY(t == value_t::null))
if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
{
JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.6.1")); // LCOV_EXCL_LINE
}
@@ -1427,7 +1428,7 @@ class basic_json
}
// if object is wanted but impossible, throw an exception
if (JSON_UNLIKELY(manual_type == value_t::object and not is_an_object))
if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object and not is_an_object))
{
JSON_THROW(type_error::create(301, "cannot create object from initializer list"));
}
@@ -1494,7 +1495,7 @@ class basic_json
@since version 1.0.0
*/
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json array(initializer_list_t init = {})
{
return basic_json(init, false, value_t::array);
@@ -1538,7 +1539,7 @@ class basic_json
@since version 1.0.0
*/
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json object(initializer_list_t init = {})
{
return basic_json(init, false, value_t::object);
@@ -1637,7 +1638,7 @@ class basic_json
assert(last.m_object != nullptr);
// make sure iterator fits the current value
if (JSON_UNLIKELY(first.m_object != last.m_object))
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
{
JSON_THROW(invalid_iterator::create(201, "iterators are not compatible"));
}
@@ -1654,8 +1655,8 @@ class basic_json
case value_t::number_unsigned:
case value_t::string:
{
if (JSON_UNLIKELY(not first.m_it.primitive_iterator.is_begin()
or not last.m_it.primitive_iterator.is_end()))
if (JSON_HEDLEY_UNLIKELY(not first.m_it.primitive_iterator.is_begin()
or not last.m_it.primitive_iterator.is_end()))
{
JSON_THROW(invalid_iterator::create(204, "iterators out of range"));
}
@@ -2368,7 +2369,7 @@ class basic_json
/// get a boolean (explicit)
boolean_t get_impl(boolean_t* /*unused*/) const
{
if (JSON_LIKELY(is_boolean()))
if (JSON_HEDLEY_LIKELY(is_boolean()))
{
return m_value.boolean;
}
@@ -2477,7 +2478,7 @@ class basic_json
// delegate the call to get_ptr<>()
auto ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
if (JSON_LIKELY(ptr != nullptr))
if (JSON_HEDLEY_LIKELY(ptr != nullptr))
{
return *ptr;
}
@@ -2928,7 +2929,7 @@ class basic_json
reference at(size_type idx)
{
// at only works for arrays
if (JSON_LIKELY(is_array()))
if (JSON_HEDLEY_LIKELY(is_array()))
{
JSON_TRY
{
@@ -2975,7 +2976,7 @@ class basic_json
const_reference at(size_type idx) const
{
// at only works for arrays
if (JSON_LIKELY(is_array()))
if (JSON_HEDLEY_LIKELY(is_array()))
{
JSON_TRY
{
@@ -3026,7 +3027,7 @@ class basic_json
reference at(const typename object_t::key_type& key)
{
// at only works for objects
if (JSON_LIKELY(is_object()))
if (JSON_HEDLEY_LIKELY(is_object()))
{
JSON_TRY
{
@@ -3077,7 +3078,7 @@ class basic_json
const_reference at(const typename object_t::key_type& key) const
{
// at only works for objects
if (JSON_LIKELY(is_object()))
if (JSON_HEDLEY_LIKELY(is_object()))
{
JSON_TRY
{
@@ -3131,7 +3132,7 @@ class basic_json
}
// operator[] only works for arrays
if (JSON_LIKELY(is_array()))
if (JSON_HEDLEY_LIKELY(is_array()))
{
// fill up array with null values if given idx is outside range
if (idx >= m_value.array->size())
@@ -3169,7 +3170,7 @@ class basic_json
const_reference operator[](size_type idx) const
{
// const operator[] only works for arrays
if (JSON_LIKELY(is_array()))
if (JSON_HEDLEY_LIKELY(is_array()))
{
return m_value.array->operator[](idx);
}
@@ -3215,7 +3216,7 @@ class basic_json
}
// operator[] only works for objects
if (JSON_LIKELY(is_object()))
if (JSON_HEDLEY_LIKELY(is_object()))
{
return m_value.object->operator[](key);
}
@@ -3256,7 +3257,7 @@ class basic_json
const_reference operator[](const typename object_t::key_type& key) const
{
// const operator[] only works for objects
if (JSON_LIKELY(is_object()))
if (JSON_HEDLEY_LIKELY(is_object()))
{
assert(m_value.object->find(key) != m_value.object->end());
return m_value.object->find(key)->second;
@@ -3293,6 +3294,7 @@ class basic_json
@since version 1.1.0
*/
template<typename T>
JSON_HEDLEY_NON_NULL(2)
reference operator[](T* key)
{
// implicitly convert null to object
@@ -3304,7 +3306,7 @@ class basic_json
}
// at only works for objects
if (JSON_LIKELY(is_object()))
if (JSON_HEDLEY_LIKELY(is_object()))
{
return m_value.object->operator[](key);
}
@@ -3343,10 +3345,11 @@ class basic_json
@since version 1.1.0
*/
template<typename T>
JSON_HEDLEY_NON_NULL(2)
const_reference operator[](T* key) const
{
// at only works for objects
if (JSON_LIKELY(is_object()))
if (JSON_HEDLEY_LIKELY(is_object()))
{
assert(m_value.object->find(key) != m_value.object->end());
return m_value.object->find(key)->second;
@@ -3410,7 +3413,7 @@ class basic_json
ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const
{
// at only works for objects
if (JSON_LIKELY(is_object()))
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if key is found, return value and given default value otherwise
const auto it = find(key);
@@ -3482,7 +3485,7 @@ class basic_json
ValueType value(const json_pointer& ptr, const ValueType& default_value) const
{
// at only works for objects
if (JSON_LIKELY(is_object()))
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if pointer resolves a value, return it or use default value
JSON_TRY
@@ -3502,6 +3505,7 @@ class basic_json
@brief overload for a default value of type const char*
@copydoc basic_json::value(const json_pointer&, ValueType) const
*/
JSON_HEDLEY_NON_NULL(3)
string_t value(const json_pointer& ptr, const char* default_value) const
{
return value(ptr, string_t(default_value));
@@ -3646,7 +3650,7 @@ class basic_json
IteratorType erase(IteratorType pos)
{
// make sure iterator fits the current value
if (JSON_UNLIKELY(this != pos.m_object))
if (JSON_HEDLEY_UNLIKELY(this != pos.m_object))
{
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
}
@@ -3661,7 +3665,7 @@ class basic_json
case value_t::number_unsigned:
case value_t::string:
{
if (JSON_UNLIKELY(not pos.m_it.primitive_iterator.is_begin()))
if (JSON_HEDLEY_UNLIKELY(not pos.m_it.primitive_iterator.is_begin()))
{
JSON_THROW(invalid_iterator::create(205, "iterator out of range"));
}
@@ -3751,7 +3755,7 @@ class basic_json
IteratorType erase(IteratorType first, IteratorType last)
{
// make sure iterator fits the current value
if (JSON_UNLIKELY(this != first.m_object or this != last.m_object))
if (JSON_HEDLEY_UNLIKELY(this != first.m_object or this != last.m_object))
{
JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value"));
}
@@ -3766,8 +3770,8 @@ class basic_json
case value_t::number_unsigned:
case value_t::string:
{
if (JSON_LIKELY(not first.m_it.primitive_iterator.is_begin()
or not last.m_it.primitive_iterator.is_end()))
if (JSON_HEDLEY_LIKELY(not first.m_it.primitive_iterator.is_begin()
or not last.m_it.primitive_iterator.is_end()))
{
JSON_THROW(invalid_iterator::create(204, "iterators out of range"));
}
@@ -3838,7 +3842,7 @@ class basic_json
size_type erase(const typename object_t::key_type& key)
{
// this erase only works for objects
if (JSON_LIKELY(is_object()))
if (JSON_HEDLEY_LIKELY(is_object()))
{
return m_value.object->erase(key);
}
@@ -3873,9 +3877,9 @@ class basic_json
void erase(const size_type idx)
{
// this erase only works for arrays
if (JSON_LIKELY(is_array()))
if (JSON_HEDLEY_LIKELY(is_array()))
{
if (JSON_UNLIKELY(idx >= size()))
if (JSON_HEDLEY_UNLIKELY(idx >= size()))
{
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
}
@@ -4384,7 +4388,7 @@ class basic_json
future 4.0.0 of the library. Please use @ref items() instead;
that is, replace `json::iterator_wrapper(j)` with `j.items()`.
*/
JSON_DEPRECATED
JSON_HEDLEY_DEPRECATED(3.1.0)
static iteration_proxy<iterator> iterator_wrapper(reference ref) noexcept
{
return ref.items();
@@ -4393,7 +4397,7 @@ class basic_json
/*!
@copydoc iterator_wrapper(reference)
*/
JSON_DEPRECATED
JSON_HEDLEY_DEPRECATED(3.1.0)
static iteration_proxy<const_iterator> iterator_wrapper(const_reference ref) noexcept
{
return ref.items();
@@ -4812,7 +4816,7 @@ class basic_json
void push_back(basic_json&& val)
{
// push_back only works for null objects or arrays
if (JSON_UNLIKELY(not(is_null() or is_array())))
if (JSON_HEDLEY_UNLIKELY(not(is_null() or is_array())))
{
JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name())));
}
@@ -4849,7 +4853,7 @@ class basic_json
void push_back(const basic_json& val)
{
// push_back only works for null objects or arrays
if (JSON_UNLIKELY(not(is_null() or is_array())))
if (JSON_HEDLEY_UNLIKELY(not(is_null() or is_array())))
{
JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name())));
}
@@ -4899,7 +4903,7 @@ class basic_json
void push_back(const typename object_t::value_type& val)
{
// push_back only works for null objects or objects
if (JSON_UNLIKELY(not(is_null() or is_object())))
if (JSON_HEDLEY_UNLIKELY(not(is_null() or is_object())))
{
JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name())));
}
@@ -5002,7 +5006,7 @@ class basic_json
reference emplace_back(Args&& ... args)
{
// emplace_back only works for null objects or arrays
if (JSON_UNLIKELY(not(is_null() or is_array())))
if (JSON_HEDLEY_UNLIKELY(not(is_null() or is_array())))
{
JSON_THROW(type_error::create(311, "cannot use emplace_back() with " + std::string(type_name())));
}
@@ -5055,7 +5059,7 @@ class basic_json
std::pair<iterator, bool> emplace(Args&& ... args)
{
// emplace only works for null objects or arrays
if (JSON_UNLIKELY(not(is_null() or is_object())))
if (JSON_HEDLEY_UNLIKELY(not(is_null() or is_object())))
{
JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name())));
}
@@ -5123,10 +5127,10 @@ class basic_json
iterator insert(const_iterator pos, const basic_json& val)
{
// insert only works for arrays
if (JSON_LIKELY(is_array()))
if (JSON_HEDLEY_LIKELY(is_array()))
{
// check if iterator pos fits to this JSON value
if (JSON_UNLIKELY(pos.m_object != this))
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
}
@@ -5174,10 +5178,10 @@ class basic_json
iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
{
// insert only works for arrays
if (JSON_LIKELY(is_array()))
if (JSON_HEDLEY_LIKELY(is_array()))
{
// check if iterator pos fits to this JSON value
if (JSON_UNLIKELY(pos.m_object != this))
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
}
@@ -5222,24 +5226,24 @@ class basic_json
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
{
// insert only works for arrays
if (JSON_UNLIKELY(not is_array()))
if (JSON_HEDLEY_UNLIKELY(not is_array()))
{
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
}
// check if iterator pos fits to this JSON value
if (JSON_UNLIKELY(pos.m_object != this))
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
}
// check if range iterators belong to the same JSON object
if (JSON_UNLIKELY(first.m_object != last.m_object))
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
{
JSON_THROW(invalid_iterator::create(210, "iterators do not fit"));
}
if (JSON_UNLIKELY(first.m_object == this))
if (JSON_HEDLEY_UNLIKELY(first.m_object == this))
{
JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container"));
}
@@ -5275,13 +5279,13 @@ class basic_json
iterator insert(const_iterator pos, initializer_list_t ilist)
{
// insert only works for arrays
if (JSON_UNLIKELY(not is_array()))
if (JSON_HEDLEY_UNLIKELY(not is_array()))
{
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
}
// check if iterator pos fits to this JSON value
if (JSON_UNLIKELY(pos.m_object != this))
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
}
@@ -5316,19 +5320,19 @@ class basic_json
void insert(const_iterator first, const_iterator last)
{
// insert only works for objects
if (JSON_UNLIKELY(not is_object()))
if (JSON_HEDLEY_UNLIKELY(not is_object()))
{
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
}
// check if range iterators belong to the same JSON object
if (JSON_UNLIKELY(first.m_object != last.m_object))
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
{
JSON_THROW(invalid_iterator::create(210, "iterators do not fit"));
}
// passed iterators must belong to objects
if (JSON_UNLIKELY(not first.m_object->is_object()))
if (JSON_HEDLEY_UNLIKELY(not first.m_object->is_object()))
{
JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects"));
}
@@ -5365,11 +5369,11 @@ class basic_json
assert_invariant();
}
if (JSON_UNLIKELY(not is_object()))
if (JSON_HEDLEY_UNLIKELY(not is_object()))
{
JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name())));
}
if (JSON_UNLIKELY(not j.is_object()))
if (JSON_HEDLEY_UNLIKELY(not j.is_object()))
{
JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name())));
}
@@ -5416,20 +5420,20 @@ class basic_json
assert_invariant();
}
if (JSON_UNLIKELY(not is_object()))
if (JSON_HEDLEY_UNLIKELY(not is_object()))
{
JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name())));
}
// check if range iterators belong to the same JSON object
if (JSON_UNLIKELY(first.m_object != last.m_object))
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
{
JSON_THROW(invalid_iterator::create(210, "iterators do not fit"));
}
// passed iterators must belong to objects
if (JSON_UNLIKELY(not first.m_object->is_object()
or not last.m_object->is_object()))
if (JSON_HEDLEY_UNLIKELY(not first.m_object->is_object()
or not last.m_object->is_object()))
{
JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects"));
}
@@ -5492,7 +5496,7 @@ class basic_json
void swap(array_t& other)
{
// swap only works for arrays
if (JSON_LIKELY(is_array()))
if (JSON_HEDLEY_LIKELY(is_array()))
{
std::swap(*(m_value.array), other);
}
@@ -5525,7 +5529,7 @@ class basic_json
void swap(object_t& other)
{
// swap only works for objects
if (JSON_LIKELY(is_object()))
if (JSON_HEDLEY_LIKELY(is_object()))
{
std::swap(*(m_value.object), other);
}
@@ -5558,7 +5562,7 @@ class basic_json
void swap(string_t& other)
{
// swap only works for strings
if (JSON_LIKELY(is_string()))
if (JSON_HEDLEY_LIKELY(is_string()))
{
std::swap(*(m_value.string), other);
}
@@ -6068,7 +6072,7 @@ class basic_json
instead; that is, replace calls like `j >> o;` with `o << j;`.
@since version 1.0.0; deprecated since version 3.0.0
*/
JSON_DEPRECATED
JSON_HEDLEY_DEPRECATED(3.0.0)
friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
{
return o << j;
@@ -6147,7 +6151,7 @@ class basic_json
@since version 2.0.3 (contiguous containers)
*/
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json parse(detail::input_adapter&& i,
const parser_callback_t cb = nullptr,
const bool allow_exceptions = true)
@@ -6216,6 +6220,7 @@ class basic_json
@since version 3.2.0
*/
template <typename SAX>
JSON_HEDLEY_NON_NULL(2)
static bool sax_parse(detail::input_adapter&& i, SAX* sax,
input_format_t format = input_format_t::json,
const bool strict = true)
@@ -6301,6 +6306,7 @@ class basic_json
std::is_base_of<
std::random_access_iterator_tag,
typename std::iterator_traits<IteratorType>::iterator_category>::value, int>::type = 0>
JSON_HEDLEY_NON_NULL(3)
static bool sax_parse(IteratorType first, IteratorType last, SAX* sax)
{
return parser(detail::input_adapter(first, last)).sax_parse(sax);
@@ -6314,7 +6320,7 @@ class basic_json
instead; that is, replace calls like `j << i;` with `i >> j;`.
@since version 1.0.0; deprecated since version 3.0.0
*/
JSON_DEPRECATED
JSON_HEDLEY_DEPRECATED(3.0.0)
friend std::istream& operator<<(basic_json& j, std::istream& i)
{
return operator>>(i, j);
@@ -6387,6 +6393,7 @@ class basic_json
@since version 1.0.0, public since 2.1.0, `const char*` and `noexcept`
since 3.0.0
*/
JSON_HEDLEY_RETURNS_NON_NULL
const char* type_name() const noexcept
{
{
@@ -6916,7 +6923,7 @@ class basic_json
@a strict parameter since 3.0.0; added @a allow_exceptions parameter
since 3.2.0
*/
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json from_cbor(detail::input_adapter&& i,
const bool strict = true,
const bool allow_exceptions = true)
@@ -6932,7 +6939,7 @@ class basic_json
*/
template<typename A1, typename A2,
detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value, int> = 0>
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json from_cbor(A1 && a1, A2 && a2,
const bool strict = true,
const bool allow_exceptions = true)
@@ -7025,7 +7032,7 @@ class basic_json
@a strict parameter since 3.0.0; added @a allow_exceptions parameter
since 3.2.0
*/
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json from_msgpack(detail::input_adapter&& i,
const bool strict = true,
const bool allow_exceptions = true)
@@ -7041,7 +7048,7 @@ class basic_json
*/
template<typename A1, typename A2,
detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value, int> = 0>
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json from_msgpack(A1 && a1, A2 && a2,
const bool strict = true,
const bool allow_exceptions = true)
@@ -7113,7 +7120,7 @@ class basic_json
@since version 3.1.0; added @a allow_exceptions parameter since 3.2.0
*/
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json from_ubjson(detail::input_adapter&& i,
const bool strict = true,
const bool allow_exceptions = true)
@@ -7129,7 +7136,7 @@ class basic_json
*/
template<typename A1, typename A2,
detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value, int> = 0>
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json from_ubjson(A1 && a1, A2 && a2,
const bool strict = true,
const bool allow_exceptions = true)
@@ -7200,7 +7207,7 @@ class basic_json
@sa @ref from_ubjson(detail::input_adapter&&, const bool, const bool) for the
related UBJSON format
*/
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json from_bson(detail::input_adapter&& i,
const bool strict = true,
const bool allow_exceptions = true)
@@ -7216,7 +7223,7 @@ class basic_json
*/
template<typename A1, typename A2,
detail::enable_if_t<std::is_constructible<detail::input_adapter, A1, A2>::value, int> = 0>
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json from_bson(A1 && a1, A2 && a2,
const bool strict = true,
const bool allow_exceptions = true)
@@ -7590,7 +7597,7 @@ class basic_json
else
{
const auto idx = json_pointer::array_index(last_path);
if (JSON_UNLIKELY(static_cast<size_type>(idx) > parent.size()))
if (JSON_HEDLEY_UNLIKELY(static_cast<size_type>(idx) > parent.size()))
{
// avoid undefined behavior
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
@@ -7621,7 +7628,7 @@ class basic_json
{
// perform range check
auto it = parent.find(last_path);
if (JSON_LIKELY(it != parent.end()))
if (JSON_HEDLEY_LIKELY(it != parent.end()))
{
parent.erase(it);
}
@@ -7638,7 +7645,7 @@ class basic_json
};
// type check: top level value must be an array
if (JSON_UNLIKELY(not json_patch.is_array()))
if (JSON_HEDLEY_UNLIKELY(not json_patch.is_array()))
{
JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects"));
}
@@ -7658,13 +7665,13 @@ class basic_json
const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'";
// check if desired value is present
if (JSON_UNLIKELY(it == val.m_value.object->end()))
if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
{
JSON_THROW(parse_error::create(105, 0, error_msg + " must have member '" + member + "'"));
}
// check if result is of type string
if (JSON_UNLIKELY(string_type and not it->second.is_string()))
if (JSON_HEDLEY_UNLIKELY(string_type and not it->second.is_string()))
{
JSON_THROW(parse_error::create(105, 0, error_msg + " must have string member '" + member + "'"));
}
@@ -7674,7 +7681,7 @@ class basic_json
};
// type check: every element of the array must be an object
if (JSON_UNLIKELY(not val.is_object()))
if (JSON_HEDLEY_UNLIKELY(not val.is_object()))
{
JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects"));
}
@@ -7752,7 +7759,7 @@ class basic_json
}
// throw an exception if test fails
if (JSON_UNLIKELY(not success))
if (JSON_HEDLEY_UNLIKELY(not success))
{
JSON_THROW(other_error::create(501, "unsuccessful: " + val.dump()));
}
@@ -7805,7 +7812,7 @@ class basic_json
@since version 2.0.0
*/
JSON_NODISCARD
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json diff(const basic_json& source, const basic_json& target,
const std::string& path = "")
{
@@ -8097,6 +8104,7 @@ if no parse error occurred.
@since version 1.0.0
*/
JSON_HEDLEY_NON_NULL(1)
inline nlohmann::json operator "" _json(const char* s, std::size_t n)
{
return nlohmann::json::parse(s, s + n);
@@ -8115,6 +8123,7 @@ object if no parse error occurred.
@since version 2.0.0
*/
JSON_HEDLEY_NON_NULL(1)
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
{
return nlohmann::json::json_pointer(std::string(s, n));