mirror of
https://github.com/nlohmann/json.git
synced 2025-07-31 10:24:23 +03:00
Merge pull request #2242 from nlohmann/issue2239
Make assert configurable via JSON_ASSERT
This commit is contained in:
@ -35,7 +35,6 @@ SOFTWARE.
|
||||
#define NLOHMANN_JSON_VERSION_PATCH 0
|
||||
|
||||
#include <algorithm> // all_of, find, for_each
|
||||
#include <cassert> // assert
|
||||
#include <cstddef> // nullptr_t, ptrdiff_t, size_t
|
||||
#include <functional> // hash, less
|
||||
#include <initializer_list> // initializer_list
|
||||
@ -924,7 +923,7 @@ class basic_json
|
||||
};
|
||||
std::unique_ptr<T, decltype(deleter)> object(AllocatorTraits::allocate(alloc, 1), deleter);
|
||||
AllocatorTraits::construct(alloc, object.get(), std::forward<Args>(args)...);
|
||||
assert(object != nullptr);
|
||||
JSON_ASSERT(object != nullptr);
|
||||
return object.release();
|
||||
}
|
||||
|
||||
@ -1219,10 +1218,10 @@ class basic_json
|
||||
*/
|
||||
void assert_invariant() const noexcept
|
||||
{
|
||||
assert(m_type != value_t::object or m_value.object != nullptr);
|
||||
assert(m_type != value_t::array or m_value.array != nullptr);
|
||||
assert(m_type != value_t::string or m_value.string != nullptr);
|
||||
assert(m_type != value_t::binary or m_value.binary != nullptr);
|
||||
JSON_ASSERT(m_type != value_t::object or m_value.object != nullptr);
|
||||
JSON_ASSERT(m_type != value_t::array or m_value.array != nullptr);
|
||||
JSON_ASSERT(m_type != value_t::string or m_value.string != nullptr);
|
||||
JSON_ASSERT(m_type != value_t::binary or m_value.binary != nullptr);
|
||||
}
|
||||
|
||||
public:
|
||||
@ -1515,7 +1514,7 @@ class basic_json
|
||||
m_type = value_t::discarded;
|
||||
break;
|
||||
default: // LCOV_EXCL_LINE
|
||||
assert(false); // LCOV_EXCL_LINE
|
||||
JSON_ASSERT(false); // LCOV_EXCL_LINE
|
||||
}
|
||||
assert_invariant();
|
||||
}
|
||||
@ -1915,8 +1914,8 @@ class basic_json
|
||||
std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int>::type = 0>
|
||||
basic_json(InputIT first, InputIT last)
|
||||
{
|
||||
assert(first.m_object != nullptr);
|
||||
assert(last.m_object != nullptr);
|
||||
JSON_ASSERT(first.m_object != nullptr);
|
||||
JSON_ASSERT(last.m_object != nullptr);
|
||||
|
||||
// make sure iterator fits the current value
|
||||
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
|
||||
@ -3633,7 +3632,7 @@ class basic_json
|
||||
// const operator[] only works for objects
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
assert(m_value.object->find(key) != m_value.object->end());
|
||||
JSON_ASSERT(m_value.object->find(key) != m_value.object->end());
|
||||
return m_value.object->find(key)->second;
|
||||
}
|
||||
|
||||
@ -3725,7 +3724,7 @@ class basic_json
|
||||
// at only works for objects
|
||||
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||
{
|
||||
assert(m_value.object->find(key) != m_value.object->end());
|
||||
JSON_ASSERT(m_value.object->find(key) != m_value.object->end());
|
||||
return m_value.object->find(key)->second;
|
||||
}
|
||||
|
||||
@ -5493,7 +5492,7 @@ class basic_json
|
||||
iterator insert_iterator(const_iterator pos, Args&& ... args)
|
||||
{
|
||||
iterator result(this);
|
||||
assert(m_value.array != nullptr);
|
||||
JSON_ASSERT(m_value.array != nullptr);
|
||||
|
||||
auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator);
|
||||
m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
|
||||
@ -8258,7 +8257,7 @@ class basic_json
|
||||
|
||||
// if there exists a parent it cannot be primitive
|
||||
default: // LCOV_EXCL_LINE
|
||||
assert(false); // LCOV_EXCL_LINE
|
||||
JSON_ASSERT(false); // LCOV_EXCL_LINE
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user