diff --git a/brion/detail/json.hpp b/brion/detail/json.hpp index fd430fab..95723ce3 100644 --- a/brion/detail/json.hpp +++ b/brion/detail/json.hpp @@ -1,3 +1,5 @@ +/* clang-format off */ + /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ @@ -125,7 +127,7 @@ using json = basic_json<>; "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" #endif #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) -#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900 +#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 #error \ "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" #endif @@ -10983,6 +10985,23 @@ class basic_json return object.release(); } + /// helper for insertion of an iterator (supports GCC 4.8+) + template + iterator insert_iterator(const_iterator pos, Args&& ... args) + { + iterator result(this); + 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)...); + result.m_it.array_iterator = m_value.array->begin() + insert_pos; + + // For GCC 4.9+ only, this could become: + // result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val); + + return result; + } + //////////////////////// // JSON value storage // //////////////////////// @@ -15203,10 +15222,7 @@ class basic_json } // insert to array and return iterator - iterator result(this); - result.m_it.array_iterator = - m_value.array->insert(pos.m_it.array_iterator, val); - return result; + return insert_iterator(pos, val); } JSON_THROW(type_error::create(309, "cannot use insert() with " + @@ -15259,10 +15275,7 @@ class basic_json } // insert to array and return iterator - iterator result(this); - result.m_it.array_iterator = - m_value.array->insert(pos.m_it.array_iterator, cnt, val); - return result; + return insert_iterator(pos, cnt, val); } JSON_THROW(type_error::create(309, "cannot use insert() with " + @@ -15329,12 +15342,10 @@ class basic_json } // insert to array and return iterator - iterator result(this); - result.m_it.array_iterator = - m_value.array->insert(pos.m_it.array_iterator, - first.m_it.array_iterator, - last.m_it.array_iterator); - return result; + return insert_iterator( + pos, + first.m_it.array_iterator, + last.m_it.array_iterator); } /*! @@ -15378,11 +15389,7 @@ class basic_json } // insert to array and return iterator - iterator result(this); - result.m_it.array_iterator = - m_value.array->insert(pos.m_it.array_iterator, ilist.begin(), - ilist.end()); - return result; + return insert_iterator(pos, ilist.begin(), ilist.end()); } /*! @@ -17933,15 +17940,15 @@ class basic_json @since version 3.0.0 */ - void merge_patch(const basic_json& patch) + void merge_patch(const basic_json& jspatch) { - if (patch.is_object()) + if (jspatch.is_object()) { if (not is_object()) { *this = object(); } - for (auto it = patch.begin(); it != patch.end(); ++it) + for (auto it = jspatch.begin(); it != jspatch.end(); ++it) { if (it.value().is_null()) { @@ -17955,7 +17962,7 @@ class basic_json } else { - *this = patch; + *this = jspatch; } }