Skip to content

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

Merged
merged 6 commits into from
Jan 19, 2019

Conversation

thomasspriggs
Copy link
Contributor

@thomasspriggs thomasspriggs commented Jan 18, 2019

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Attempting to use ranget on const input collections or attempting to use a const ranget would previously cause compile errors. This PR fixes these issues.

@kroening
Copy link
Member

I would squash this slightly more, e.g., put the test into the commit of the change.

@kroening
Copy link
Member

kroening commented Jan 18, 2019

Also, I'd change the return types of

const value_type &operator*() const
const value_type *operator->() const

for consistency.

Copy link
Contributor

@allredj allredj left a 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

Copy link
Contributor

@allredj allredj left a 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

[&](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.")
Copy link
Contributor

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.
@thomasspriggs thomasspriggs merged commit 5730633 into diffblue:develop Jan 19, 2019
Copy link
Contributor

@allredj allredj left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants