This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: forward list patch


On 10/24/2010 12:12 PM, Paolo Carlini wrote:
Hi,
Do you have n3126 at hand? Please fetch it from the ISO web site, if you
didn't already.
I have it now.
  I see that 23.2.1/11 explicitly says that swap can
invalidate end(), I wonder if it should explicitly say something similar
about before_begin?!? After all, aren't the two otherwise very similar?
What do you think?
Yes, end and before begin looks similar. However, with current libstdc++ implementation there is a major difference. end has no relation with the forward list but before begin is tighly link to it with no way to associate it with any other forward list instance.
Because, really, that looping, etc, part of swap
seems just crazy to me: it's a very, very basic design idea in the
standard (even more now in the move semantics era) that swap is a very
fast constant time operation, is just about exchanging a few pointers.
If we cannot manage to implement it like that, either the standard
should be slightly tweaked somewhere, or... we should try harder ;)
I agree that it is not something you would expect in a swap implementation. At least not in the normal form and the whole Standard is written in such a way that swap is easy to write in a performant way. However the safe mode is not Standard and it is not surprising that as long as you keep links between iterators and sequences then some operations become more difficult to implement.

So here is an other proposition. This time I made the forward list _M_swap method much closer to the basic version. If you check the basic version in debug.cc you will see that there are already 4 for loops to update the sequence reference for all safe iterators. In the forward list _M_swap version I have the same 4 for loops except that at the same time I look for before begin iterators and move them back to the list they should belong to.

At the same time your remark about end and before begin similarities made me realized that I also miss to change _M_invalidate_all so that it do not invalidate before begin iterator.

François

Attachment: ChangeLog.entry
Description: Text document

Attachment: forward_list.patch
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]