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


Hi,
> Yes, I agree that the new _M_swap is big and is not something you
> would expect in a swap implementation. The problem rely in the
> before_begin and swap  implementations:
>
>       const_iterator
>       before_begin() const
>       { return const_iterator(&this->_M_impl._M_head); }
>
>       void
>       swap(forward_list& __list)
>       { std::swap(this->_M_impl._M_head._M_next,
> __list._M_impl._M_head._M_next); }
>
> You see, the swap operation swap only starting at begin iterator, but
> before begin never gets swap. The added test swap.cc show this
> problem. When run in normal mode it works, when run in debug mode it
> fails without the patch because the debug mode signal that the test is
> trying to compare iterators from different containers.
>
> Are the specifications saying something about management of
> before_begin on swap operation ? If it says nothing we could perhaps
> change the forward_list implementation so that even the before begin
> iterator comes from a dynamic allocation that could then be swap like
> the others. However it would be abnormal to change the normal
> implementation because of an issue in the debug mode.
Do you have n3126 at hand? Please fetch it from the ISO web site, if you
didn't already. 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? 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 ;)
> Do you want me to move it to a forward_list.tcc file ?
If we are going to add only one large out of line function, I think that
adding a .tcc file would be overkilling, just moving it out of line in
the main file is ok. Actually, I see a few more which would be better
moved out of line, but this is a minor detail.

Paolo.


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