-
Notifications
You must be signed in to change notification settings - Fork 274
Fix a selection of const
related issues with ranget
.
#3833
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
Fix a selection of const
related issues with ranget
.
#3833
Conversation
I would squash this slightly more, e.g., put the test into the commit of the change. |
Also, I'd change the return types of
for consistency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: 7a5ff90).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/97863971
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: 20cc2dd).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/97872239
unit/util/range.cpp
Outdated
[&](const std::string &s) { return s.length() == 4; }); | ||
auto it = filtered_range.begin(); | ||
REQUIRE(*it == "cdef"); | ||
++it; | ||
REQUIRE(it == filtered_range.end()); | ||
} | ||
THEN("A const filter iterator can mutate the input collection.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest rephrasing, since "const filter iterator" sounds an awful lot like a const_iterator
, which this is not
Dereferencing a `filter_iteratort` from filtering a const collection with `ranget` would previously introduce a compile error, due to a `const` to non-const conversion. This commit fixes this, by using the same return type as the iterator which it wraps around. This commit includes a test for using range to filter a `const` collection.
Dereferencing a `concat_iteratort` from concating const collections with `ranget` would previously introduce a compile error, due to a `const` to non-const conversion. This commit fixes this, by using the same return type as the iterator which it wraps around. This commit includes a test for using range to concat `const` collections.
It was previously impossible to iterate over a `const` range, because you couldn't call `.begin()` on it. This fixes that issue. Changing this to `const` does not allow the internals of the range to be mutated, as it returns a copy of the begin iterator, not a reference to it. This commit adds `const` to ranges in range unit test to show that ranges can be made const correct, using this fix.
Algorithms which are written expecting a STL container may reference a `value_type` member, as this is the name of the member in STL containers. Therefore this needs to be named the same way in `ranget` in order to be compatible with such algorithms. This commit includes a unit test of `ranget` having correct the `value_type` defined.
Given that `filter` and `concat` didn't work with const input collections, it seems prudent to test that `map` works with const input collections as well. There is no corresponding fix to make this test pass in this PR.
Deferencing a `const` iterator which refers to a non-const value should enable mutation of that value. This is consistent with how iterators in the STL work. It means that we only need to provide a single const overload of these operators, not both the const and non-const variations. So the benefit of this commit is better consistency with the STL and fewer operator overloads to maintain.
20cc2dd
to
a89ca18
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: a89ca18).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/97929087
Attempting to use
ranget
on const input collections or attempting to use aconst ranget
would previously cause compile errors. This PR fixes these issues.