-
Notifications
You must be signed in to change notification settings - Fork 52
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
[slot_map] R1/R2 criticisms #147
Comments
I'm intrigued by the idea of There's nothing inherently wrong with making algorithms into member functions when that's the performant or correct thing to do: see
Personally I'd be strongly in favor of public access to the container — |
Maybe you can correct my assumption, cplusplus.com lists I'll start experimenting with those iterators and see where (if) they break.
I agree, lets not do that. |
Here I was thinking in terms of standardization. I have no experience in that regard, I just thought this might come up. Good to hear it's not an issue. |
The Cpp17Iterator requirements require that "lvalues of type However, that's talking about swapping iterators. Swapping iterators themselves doesn't ever
Based on my intuition, I'd argue that
|
Thanks for the details and example. I was confusing So, to reiterate, the goal would be to specialize cppreference's "possible implementation" of |
But surely you agree that the following is correct?
So you're asking for But I should be quiet and let you bang your own head against it for a while. I'll try to. :) |
Yes absolutely! What I intend to happen is
Haha it's ok, you have much more experience than I do in these areas. I'm not that fluent in iterators. This will be a good experiment to get up to speed. Plus, I have no super complicated c++ to bang my head on these days :) |
@Quuxplusone You are right it isn't as simple as I thought to "specialize" or overload Here is another point I would like to bring up : What about serialization/deserialization? Could we offer a (potentially limited) way to insert an object at key |
Serialization is an interesting use-case. I could see a use for "serialize this whole slotmap
In the context of serialization, no, I assume we'd serialize/deserialize a whole slotmap at once. A priori I think the slotmap ought to have control over its keys, so no. If I have a made-up
A priori I think the user really shouldn't crack open |
Since I do not use boost (and gaming Providing access to the underlying vector Ultimately, we need a way to serialize/deserialize.
I'm not so sure, but I'm happy with letting this go until I have another use-case than serialization. |
I think all you need for the most naïve serialization is a way to get "for each item in the slotmap, print out the item and its key." You can do all of this today except for "...and its key"; and #141 proposes a
And then for deserialization, you'd need a way to forcibly "insert item at (non-colliding) key." Or, more arcanely, since the keys always come in numerical order by index, "insert item with forced generation number g" would do the trick. But yeah, I think we'd need to see a use-case before trying to actually design. |
A working [hackish] implementation of custom It doesn't work with It will "fixup" the keys when To make safer iterators work, we need to wrap the adapted container iterators. I used a similar implementation as one would with reverse iterators. The non-const iterator provides a static I needed to specialize A seperate proposal to change Further experimentation is required to find out if |
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
andend
.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.
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 theslot_map
api will grow, with many custom cases that will need special implementations. It is already starting : #133An 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 useslot_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.
The text was updated successfully, but these errors were encountered: