This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: forward list patch
On 10/25/2010 09:48 PM, François Dumont wrote:
> 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.
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>.
Paolo.