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); + } }