From 3f97a5d5ad8f102a2c401706755ce9f0567564e8 Mon Sep 17 00:00:00 2001 From: Niels Date: Wed, 22 Jun 2016 20:05:44 +0200 Subject: [PATCH] a conceptual quick fix for #269 --- src/json.hpp | 7 +++++-- src/json.hpp.re2c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 9d6687dd..09b6a800 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -10002,13 +10002,16 @@ basic_json_parser_63: // in a second pass, traverse the remaining elements // remove my remaining elements + const auto end_index = static_cast(result.size()); while (i < source.size()) { - result.push_back(object( + // add operations in reverse order to avoid invalid + // indices + result.insert(result.begin() + end_index, { {"op", "remove"}, {"path", path + "/" + std::to_string(i)} - })); + }); ++i; } diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 9681bed2..c5de9246 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -9312,13 +9312,16 @@ class basic_json // in a second pass, traverse the remaining elements // remove my remaining elements + const auto end_index = static_cast(result.size()); while (i < source.size()) { - result.push_back(object( + // add operations in reverse order to avoid invalid + // indices + result.insert(result.begin() + end_index, { {"op", "remove"}, {"path", path + "/" + std::to_string(i)} - })); + }); ++i; }