Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the indirection and dereference operators of iterator const #234

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<reference>(base_iterator::operator*());
}

/// dereference the iterator
pointer operator->()
pointer operator->() const
{
return const_cast<pointer>(base_iterator::operator->());
}
Expand Down
4 changes: 2 additions & 2 deletions src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -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<reference>(base_iterator::operator*());
}

/// dereference the iterator
pointer operator->()
pointer operator->() const
{
return const_cast<pointer>(base_iterator::operator->());
}
Expand Down
11 changes: 11 additions & 0 deletions test/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}