From 00f9296db517b2617f004d78cb35f9fba37a655c Mon Sep 17 00:00:00 2001 From: Niels Date: Tue, 22 Dec 2015 18:07:51 +0100 Subject: [PATCH] some cleanup for #83 --- src/json.hpp | 4 ++-- src/json.hpp.re2c | 4 ++-- test/unit.cpp | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index ee6b1743..a2760d60 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -6163,7 +6163,7 @@ class basic_json { private: /// the container to iterate - basic_json& container; + typename basic_json::reference container; /// the type of the iterator to use while iteration using json_iterator = decltype(std::begin(container)); @@ -6236,7 +6236,7 @@ class basic_json public: /// construct iterator wrapper from a container - iterator_wrapper(basic_json& cont) + iterator_wrapper(typename basic_json::reference cont) : container(cont) {} diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index cea396d6..44fc320f 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -6163,7 +6163,7 @@ class basic_json { private: /// the container to iterate - basic_json& container; + typename basic_json::reference container; /// the type of the iterator to use while iteration using json_iterator = decltype(std::begin(container)); @@ -6236,7 +6236,7 @@ class basic_json public: /// construct iterator wrapper from a container - iterator_wrapper(basic_json& cont) + iterator_wrapper(typename basic_json::reference cont) : container(cont) {} diff --git a/test/unit.cpp b/test/unit.cpp index 3a89e94f..c7ce8a47 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -9555,6 +9555,10 @@ TEST_CASE("iterator_wrapper") { CHECK(i.key() == "A"); CHECK(i.value() == json(1)); + + // change the value + i.value() = json(11); + CHECK(i.value() == json(11)); break; } @@ -9562,6 +9566,10 @@ TEST_CASE("iterator_wrapper") { CHECK(i.key() == "B"); CHECK(i.value() == json(2)); + + // change the value + i.value() = json(22); + CHECK(i.value() == json(22)); break; } @@ -9573,6 +9581,9 @@ TEST_CASE("iterator_wrapper") } CHECK(counter == 3); + + // check if values where changed + CHECK(j == json({{"A", 11}, {"B", 22}})); } SECTION("const value") @@ -9690,6 +9701,10 @@ TEST_CASE("iterator_wrapper") { CHECK(i.key() == "0"); CHECK(i.value() == "A"); + + // change the value + i.value() = "AA"; + CHECK(i.value() == "AA"); break; } @@ -9697,6 +9712,10 @@ TEST_CASE("iterator_wrapper") { CHECK(i.key() == "1"); CHECK(i.value() == "B"); + + // change the value + i.value() = "BB"; + CHECK(i.value() == "BB"); break; } @@ -9708,6 +9727,9 @@ TEST_CASE("iterator_wrapper") } CHECK(counter == 3); + + // check if values where changed + CHECK(j == json({"AA", "BB"})); } SECTION("const value")