FixedMap and FixedOrderedMultimap Iterators differ from std:map implementation #36
Labels
No Label
API Change
Breaking API Change
bug
build
cosmetics
Documentation
duplicate
feature
help wanted
hotfix
invalid
question
Refactor
Tests
wontfix
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: fsfw/fsfw#36
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
For both iterators, the * and the -> operators are overloaded to return value->second (here and there), which reduces typing work, as one can directly access the stored values writing iterator->member instead if iterator->second.member.
In std::map, the operator is not overloaded and returns the underlying pair, giving the above syntax.
@Robin.Mueller recognized this and proposed in #35 to add first() and second() member functions.
I think it would cleaner to follow the syntax of the stdlib to try and avoid user confusion.
This would break existing code, but grepping through the FLP FSW, only about half of the usage of FixedMap use the shorthand, while the other half is using iterator->value.second, which is even longer than the stdlib syntax.
Proposed solution would be to delete the overload of these two functions.
Accepted solution
The std::map differs a little bit more from our implementation:
The implementation I checked returns a reference if using the *operator on the iterator. Our implementation at the moment returns a copy of the value.
This is the proposed change in ArrayList<..>::Iterator (Value is a T*):
This differs as well from the stdlib. The standard iterator in std::map has only these versions:
If you want a const_iterator you have to get that explictly. This is another downside of auto. const auto does not return a const_iterator for std::map. It returns a const Iterator which does not return const Types as shown above!
const_iterator would be:
I'm not sure wether this makes sense. If we use the const ... const () way we can have a const Iterator in our implementation which can be used with const auto. This looks better to me in comparison with const_iterator.
Usage comparison std::map:
and our map:
Interesstingly, the C++ standard does not say anything about the required return type of the dereferencing operator:
from: https://en.cppreference.com/w/cpp/named_req/Iterator
Another issue:
At the moment, it is possible to change the key with:
Output:
The Map definition should be const for key, but this breaks our way of setting up the map.