🐛 fix logics
This commit is contained in:
parent
d40e98ecef
commit
b0730f29cf
@ -5657,13 +5657,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
/// @note: This uses std::distance to support GCC 4.8,
|
/// @note: This uses std::distance to support GCC 4.8,
|
||||||
/// see https://github.com/nlohmann/json/pull/1257
|
/// see https://github.com/nlohmann/json/pull/1257
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
iterator insert_iterator(const_iterator pos, typename iterator::difference_type cnt, Args&& ... args)
|
iterator insert_iterator(const_iterator pos, Args&& ... args)
|
||||||
{
|
{
|
||||||
iterator result(this);
|
iterator result(this);
|
||||||
JSON_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);
|
auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator);
|
||||||
const auto capacity = m_value.array->capacity();
|
|
||||||
m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
|
m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
|
||||||
result.m_it.array_iterator = m_value.array->begin() + insert_pos;
|
result.m_it.array_iterator = m_value.array->begin() + insert_pos;
|
||||||
|
|
||||||
@ -5671,17 +5670,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
// 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);
|
||||||
// but the return value of insert is missing in GCC 4.8, so it is written this way instead.
|
// but the return value of insert is missing in GCC 4.8, so it is written this way instead.
|
||||||
|
|
||||||
if (capacity == m_value.array->capacity())
|
|
||||||
{
|
|
||||||
// capacity has not changed: updating parent of inserted elements is sufficient
|
|
||||||
set_parents(result, cnt);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// capacity has changed: update all elements' parents
|
|
||||||
set_parents();
|
set_parents();
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5719,7 +5708,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert to array and return iterator
|
// insert to array and return iterator
|
||||||
return insert_iterator(pos, static_cast<typename iterator::difference_type>(1), val);
|
return insert_iterator(pos, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
|
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
|
||||||
@ -5770,7 +5759,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert to array and return iterator
|
// insert to array and return iterator
|
||||||
return insert_iterator(pos, static_cast<typename iterator::difference_type>(cnt), cnt, val);
|
return insert_iterator(pos, cnt, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
|
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
|
||||||
@ -5832,7 +5821,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert to array and return iterator
|
// insert to array and return iterator
|
||||||
return insert_iterator(pos, std::distance(first, last), first.m_it.array_iterator, last.m_it.array_iterator);
|
return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -5874,7 +5863,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert to array and return iterator
|
// insert to array and return iterator
|
||||||
return insert_iterator(pos, static_cast<typename iterator::difference_type>(ilist.size()), ilist.begin(), ilist.end());
|
return insert_iterator(pos, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -22692,13 +22692,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
/// @note: This uses std::distance to support GCC 4.8,
|
/// @note: This uses std::distance to support GCC 4.8,
|
||||||
/// see https://github.com/nlohmann/json/pull/1257
|
/// see https://github.com/nlohmann/json/pull/1257
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
iterator insert_iterator(const_iterator pos, typename iterator::difference_type cnt, Args&& ... args)
|
iterator insert_iterator(const_iterator pos, Args&& ... args)
|
||||||
{
|
{
|
||||||
iterator result(this);
|
iterator result(this);
|
||||||
JSON_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);
|
auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator);
|
||||||
const auto capacity = m_value.array->capacity();
|
|
||||||
m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
|
m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
|
||||||
result.m_it.array_iterator = m_value.array->begin() + insert_pos;
|
result.m_it.array_iterator = m_value.array->begin() + insert_pos;
|
||||||
|
|
||||||
@ -22706,17 +22705,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
// 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);
|
||||||
// but the return value of insert is missing in GCC 4.8, so it is written this way instead.
|
// but the return value of insert is missing in GCC 4.8, so it is written this way instead.
|
||||||
|
|
||||||
if (capacity == m_value.array->capacity())
|
|
||||||
{
|
|
||||||
// capacity has not changed: updating parent of inserted elements is sufficient
|
|
||||||
set_parents(result, cnt);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// capacity has changed: update all elements' parents
|
|
||||||
set_parents();
|
set_parents();
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22754,7 +22743,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert to array and return iterator
|
// insert to array and return iterator
|
||||||
return insert_iterator(pos, static_cast<typename iterator::difference_type>(1), val);
|
return insert_iterator(pos, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
|
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
|
||||||
@ -22805,7 +22794,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert to array and return iterator
|
// insert to array and return iterator
|
||||||
return insert_iterator(pos, static_cast<typename iterator::difference_type>(cnt), cnt, val);
|
return insert_iterator(pos, cnt, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
|
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
|
||||||
@ -22867,7 +22856,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert to array and return iterator
|
// insert to array and return iterator
|
||||||
return insert_iterator(pos, std::distance(first, last), first.m_it.array_iterator, last.m_it.array_iterator);
|
return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -22909,7 +22898,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert to array and return iterator
|
// insert to array and return iterator
|
||||||
return insert_iterator(pos, static_cast<typename iterator::difference_type>(ilist.size()), ilist.begin(), ilist.end());
|
return insert_iterator(pos, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -117,6 +117,8 @@ TEST_CASE("Better diagnostics")
|
|||||||
json j_arr = json::array();
|
json j_arr = json::array();
|
||||||
j_arr.push_back(json::object());
|
j_arr.push_back(json::object());
|
||||||
j_arr.push_back(json::object());
|
j_arr.push_back(json::object());
|
||||||
|
j_arr.push_back(json::object());
|
||||||
|
j_arr.push_back(json::object());
|
||||||
json j_obj = json::object();
|
json j_obj = json::object();
|
||||||
j_obj["key"] = j_arr;
|
j_obj["key"] = j_arr;
|
||||||
}
|
}
|
||||||
@ -127,6 +129,8 @@ TEST_CASE("Better diagnostics")
|
|||||||
auto object = json::object();
|
auto object = json::object();
|
||||||
j_arr.push_back(object);
|
j_arr.push_back(object);
|
||||||
j_arr.push_back(object);
|
j_arr.push_back(object);
|
||||||
|
j_arr.push_back(object);
|
||||||
|
j_arr.push_back(object);
|
||||||
json j_obj = json::object();
|
json j_obj = json::object();
|
||||||
j_obj["key"] = j_arr;
|
j_obj["key"] = j_arr;
|
||||||
}
|
}
|
||||||
@ -136,6 +140,8 @@ TEST_CASE("Better diagnostics")
|
|||||||
json j_arr = json::array();
|
json j_arr = json::array();
|
||||||
j_arr.emplace_back(json::object());
|
j_arr.emplace_back(json::object());
|
||||||
j_arr.emplace_back(json::object());
|
j_arr.emplace_back(json::object());
|
||||||
|
j_arr.emplace_back(json::object());
|
||||||
|
j_arr.emplace_back(json::object());
|
||||||
json j_obj = json::object();
|
json j_obj = json::object();
|
||||||
j_obj["key"] = j_arr;
|
j_obj["key"] = j_arr;
|
||||||
}
|
}
|
||||||
@ -145,6 +151,8 @@ TEST_CASE("Better diagnostics")
|
|||||||
json j_arr = json::array();
|
json j_arr = json::array();
|
||||||
j_arr.insert(j_arr.begin(), json::object());
|
j_arr.insert(j_arr.begin(), json::object());
|
||||||
j_arr.insert(j_arr.begin(), json::object());
|
j_arr.insert(j_arr.begin(), json::object());
|
||||||
|
j_arr.insert(j_arr.begin(), json::object());
|
||||||
|
j_arr.insert(j_arr.begin(), json::object());
|
||||||
json j_obj = json::object();
|
json j_obj = json::object();
|
||||||
j_obj["key"] = j_arr;
|
j_obj["key"] = j_arr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user