stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farid Zaripov" <>
Subject RE: 23.deque.special
Date Mon, 09 Jul 2007 16:53:30 GMT
> -----Original Message-----
> From: Martin Sebor [] On Behalf Of Martin Sebor
> Sent: Monday, July 09, 2007 7:40 AM
> To:
> Subject: Re: 23.deque.special
> Farid Zaripov wrote:
> >   Below is a part of the 23.deque.special test. These rw_assert's 
> > fails because of deque::end() internal representation is 
> dependent on 
> > object and cannot be swapped.
> I'm not sure I understand.

  The std::deque<>::iterator type has two members: pointer to the
current element and pointer
to the array containing the element (include/deque, line 188):

    // `cur' points at the curent element or is null (for the end
    // `node' points to the array containing the element or &cur (for
    pointer         _C_cur;
    _C_node_pointer _C_node;

  For the end iterator _C_node == &_C_cur.

  In case swapping two empty deque, two end iterators being swapped.

  Let's iter1 is the iterator of some deque1 and iter2 is the iterator
of another deque2 before swap.
And let's iter3 is the iterator of deque1 and iter4 is the iterator of
deque2 after swap.

Before swap:

  iter1._C_cur == 0;
  iter1._C_node == &deque1._C_end._C_cur;

  iter2._C_cur == 0;
  iter2._C_node == &deque2._C_end._C_cur;

After swap still:

  iter3._C_cur == 0;
  iter3._C_node == &deque1._C_end._C_cur;

  iter4._C_cur == 0;
  iter4._C_node == &deque2._C_end._C_cur;

The iterators mebmer values aren't swapped, because if they would
swapped these iterators
wouldn't be "end iterators" in terms of our deque implementation.

  iter3 != iter2 and iter4 != iter1

So in our deque implementation we shouldn't compare end iterators after
swap operation.

> Swapping two deques is required not to invalidate any iterators, isn't
that right?

  If iter3 should == iter2 and iter4 should == iter1, then we need to
change the deque implementation.

> Are you suggesting to loosen the test so as not to exercise this
  I suggest only not to exercise iterators if one deque is empty.


View raw message