-
Notifications
You must be signed in to change notification settings - Fork 62
Make link collection iterators behave consistently with generated collection iterators #922
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
Conversation
m-fila
left a comment
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.
We had value_type in iterators defined to immutable type to fulfill some of the "Container" requirements.
We already don't fulfill "Container" for a number of reasons, so it should be fine to break it slightly more as long as we don't break requirements for iterators and ranges (which aren't affected by it)
|
Right, so some nuances still here. We don't really change any behavior that allows to break things that weren't already broken before, I think. Just to confirm, the main thing that now is possible that wasn't before is this: ExampleClusterCollection coll{};
for (auto& elem : coll) {
coll.setEnergy(42); // not possible before because elem would not have a setter
}One would have to do this (which is also already possible now) for (size_t i = 0; i < coll.size(); ++i) {
coll[i].setEnergy(42); // possible because operator[] returns a mutable handle on non-const collections
}What is broken regardless of these changes is assigning a new handle to the element, I think. Or does that also change with this change? (Do we have a test for that that I simply missed?). Anyhow, the main reason I wanted to have this feature, is because it makes it behave the same as the podio/include/podio/detail/LinkCollectionIterator.h Lines 11 to 15 in 35e65ce
(i.e. we also have the |
Does it compile now? I thought it still shouldn't since
This is a separate problem that isn't affected by this PR. Dataobject assignment changes which internal object is held instead of changing members of internal object. For temporaries that was very confusing and made no sense so we disabled it in #743.
We could also make it consistent in the other direction: have both immutable and mutable iterators to link collection use immutable type as |
You are correct, it doesn't compile at the moment. But since
Yes, exactly. Looking at the possible can of worms this opens here, I think it would be easier to do that. |
f7ec3a4 to
f14ce00
Compare
|
How about we make it requirement in requires std::same_as<typename T::value_type, typename std::iterator_traits<typename T::iterator>::value_type>;
requires std::same_as<typename T::value_type, typename std::iterator_traits<typename T::const_iterator>::value_type>; |
non-const collections give access to mutable handles via operator[] and at(). Hence, they should also model ranges over mutable handles. The fix is straight forward: Make sure the iterators report the correct value_type.
Making sure that the value_type of the LinkCollectionIterator is always an immutable handle since that is what is also done for generated collections.
e5cae8a to
aadfec1
Compare
original outset of this PR:
non-const collections give access to mutable handles via operator[] and at(). Hence, they should also model ranges over mutable handles. The fix is straight forward: Make sure the iterators report the correct value_type.See the discussion below for why we now make the link collections behave the same as the generated ones.
BEGINRELEASENOTES
LinkCollectionIteratorT::value_typean immutableLinkalways for consistency with the behavior of generated collection iterators.ENDRELEASENOTES
@m-fila am I missing something obvious here?