forward list patch

François Dumont francois.cppdevs@free.fr
Tue Oct 26 20:44:00 GMT 2010


On 10/25/2010 10:13 PM, Paolo Carlini wrote:
>
> Maybe I didn't clearly make my point: I suspect that the standard should
> be changed to explicitly say that the iterator returned by before_begin
> can be invalidated by swap. Assuming that is the case, do we have to go
> through special contortions in forward_list? Also note that in all my
> tests just incrementing such iterator after the swap leads to a behavior
> in debug mode indistinguishable from normal-mode. Eg, things like:
>
>    std::forward_list<int>  fl1(10, 0);
>    std::forward_list<int>  fl2(10, 1);
>
>    auto it1_b = fl1.before_begin();
>    auto it1_e = fl1.end();
>
>    fl1.swap(fl2);
>
>    ++it1_b;
>
>    for (auto it = it1_b; it != it1_e; ++it)
>      std::cout<<  *it<<  std::endl;
>
> work already perfectly well. I'm not convinced we need all that code in
> <forward_list>.
>    
And the result of this code is a bunch of '1' so it means that it1_b is 
still pointing to fl1 list. But if you add a small check after the swap 
like:

VERIFY( it1_b == it1.before_begin() )

and run it in debug mode then the execution will fail with a message 
saying that you try to compare iterators from different sequence.

I will try to think about what could be done if the Standard say that we 
can invalidate before begin on swap but franckly I don't see the point 
of considering the before begin as invalid if the underlying normal 
iterator is not. Do you also thing that normal implementation should be 
changed too so that normal before begin cannot be used anymore ? Or that 
after the swap it1_b points to fl2 ?

François



More information about the Libstdc++ mailing list