From 2197f5f0a6ed9ff1894f1494ca05c1646d46267c Mon Sep 17 00:00:00 2001 From: Robert Marki Date: Wed, 13 Apr 2016 13:49:53 +0200 Subject: [PATCH] Make the indirection and dereference operators of iterator const fixes #233 --- src/json.hpp | 4 ++-- src/json.hpp.re2c | 4 ++-- test/unit.cpp | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 8f671fb0..6ed82738 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -7000,13 +7000,13 @@ class basic_json } /// return a reference to the value pointed to by the iterator - reference operator*() + reference operator*() const { return const_cast(base_iterator::operator*()); } /// dereference the iterator - pointer operator->() + pointer operator->() const { return const_cast(base_iterator::operator->()); } diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index ebf83d83..33e1a4eb 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -7000,13 +7000,13 @@ class basic_json } /// return a reference to the value pointed to by the iterator - reference operator*() + reference operator*() const { return const_cast(base_iterator::operator*()); } /// dereference the iterator - pointer operator->() + pointer operator->() const { return const_cast(base_iterator::operator->()); } diff --git a/test/unit.cpp b/test/unit.cpp index ab96364c..2fa63ea9 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -12407,5 +12407,16 @@ TEST_CASE("regression tests") CHECK(j3b.dump() == "1E04"); CHECK(j3c.dump() == "1e04"); } + + SECTION("issue #233 - Can't use basic_json::iterator as a base iterator for std::move_iterator") + { + json source = {"a", "b", "c"}; + json expected = {"a", "b"}; + json dest; + + std::copy_n(std::make_move_iterator(source.begin()), 2, std::back_inserter(dest)); + + CHECK(dest == expected); + } }