-
Notifications
You must be signed in to change notification settings - Fork 54
Description
I would like to challenge some decisions made in P0661r1 from SG14.
P0661r2 states the following question was asked and answered.
R1 | Should raw access to the underlying container be provided? | No. | SG14
This is inconsistent with the current behavior, as the container returns the underlying container iterators. This means you already have access to the underlying container either through begin and end.
I believe const access to the underlying container should be available, at a minimum. I would prefer full access to the underlying container. See my next contention point for more details on why this is preferred.
Another decision I would like to challenge is direct access to the underlying container iterators.
It also provides the following iterator type aliases. Note that the adapted container must provide iterators satisfying the constraints of RandomAccessIterator.
using iterator = typename Container<value_type>::iterator;
using const_iterator = typename Container<value_type>::const_iterator;
using reverse_iterator = typename Container<value_type>::reverse_iterator;
using const_reverse_iterator = typename Container<value_type>::const_reverse_iterator;
The access to the underlying container iterators is dangerous. I've already shot myself in the foot assuming coherent behavior between slot_map iterators and its keys. I believe many more will.
Furthermore, it precludes using standard algorithms like std::partition. I fear the slot_map api will grow, with many custom cases that will need special implementations. It is already starting : #133
An alternative would be to provide custom, "smart and safe", iterators that do not invalidate the relationship between keys and elements stored in the container. Iterator swap, for example, should swap elements and shouldn't invalidate keys. In fact, no iterator operation should invalidate keys, ever.
This may make slot_map iterators heavy or less performant (TBD in test implementation), which may be a problem. Again, I believe direct access to the underlying container would be a better way to deal with this issue. When a user accesses the underlying container, it is clear he is in "no mans land". When you use slot_map iterators, operations should be safe, always.
Currently, using slot_map iterators is no mans land... Yet SG14 doesn't agree underlying container access is a good idea. This doesn't seem coherent.
I would appreciate some feedback on the types of pitfall you may fall into with custom iterators.
Thank you, looking forward to your feedback.