Martin Sebor
Mon, 09 Jul 2007 12:05:29 -0700
Farid Zaripov wrote: [...]
But that would only hide the bug. swapping empty deques needs to work (and not invalidate iterators) just as well as swapping ones with elements.Are you suggesting to loosen the test so as not to exercise thisrequirement? I suggest only not to exercise iterators if one deque is empty.But in current implementation iterator not invalidated. Yes, it's mebmers has changed, but it's still valid "end iterator".
But it doesn't point to the right container. Unless I'm still
missing something this needs to pass:
#include <assert.h>
#include <deque>
int main ()
{
std::deque<int> x, y;
std::deque<int>::iterator i = x.begin (), j = x.end ();
std::deque<int>::iterator k = y.begin (), l = y.end ();
std::swap (x, y);
assert (i == y.begin () && j == y.end ());
assert (k == y.begin () && l == y.end ());
}
If we decide to set deque<>._C_end._C_node = 0 for end iterator of empty deque It would be a big change (we should change the all places where _C_end._C_node member dereferenced).
Couldn't we just repoint _C_end._C_node in swap()? I thought that's what we were doing anyway so I guess I still don't fully understand the problem. Martin