You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by "Farid Zaripov (JIRA)" <ji...@apache.org> on 2007/11/02 15:49:51 UTC

[jira] Issue Comment Edited: (STDCXX-635) std::deque::swap invalidates begin() and end() iterators on empty container

    [ https://issues.apache.org/jira/browse/STDCXX-635?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12539602 ] 

farid edited comment on STDCXX-635 at 11/2/07 7:48 AM:
---------------------------------------------------------------

Personally, I don't think that this is a bug.

After swap operation the d1.begin() == d1.end() and they are valid end iterators for the d1 (d2.begin() == d2.end() and they are valid end iterators for the d2). The only thing that was changed is the binary representation of the iterators, so that operator==(d1.begin() before swap, d2.begin() after swap) returns false.

BTW the Dinkumware STL has the same behavior even on non-empty deque's, because its std::deque::iterator has member deque*_Mycont, so the before swap d1.begin()._Mycont == &d1; after swap d2.begin()._Mycont == &d2; and as a result d1.begin() != d2.begin() in any case.


      was (Author: farid):
    Personally, I don't think that this is a bug.

After swap operation the d1.begin() == d1.end() and they are valid end iterators for the d1 (d2.begin() == d2.end() and they are valid end iterators for the d2). The only thing that was changes is the binary representation of the iterators, so that operator==(d1.begin() before swap, d2.begin() after swap) returns false.

BTW the Dinkumware STL has the same behavior even on non-empty deque's, because its std::deque::iterator has member deque*_Mycont, so the before swap d1.begin()._Mycont == &d1; after swap d2.begin()._Mycont == &d2; and as a result d1.begin() != d2.begin() in any case.

  
> std::deque::swap invalidates begin() and end() iterators on empty container
> ---------------------------------------------------------------------------
>
>                 Key: STDCXX-635
>                 URL: https://issues.apache.org/jira/browse/STDCXX-635
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: 23. Containers
>    Affects Versions: 4.2
>         Environment: All
>            Reporter: Farid Zaripov
>            Priority: Minor
>             Fix For: 4.2.1
>
>
> The program below aborts on assert.
> #include <deque>
> #include <cassert>
> int main ()
> {
>     typedef std::deque<int> Deque;
>     typedef Deque::iterator Iter;
>     Deque d1, d2;
>     Iter iters [2][2] = {
>         { d1.begin (), d1.end () },
>         { d2.begin (), d2.end () }
>     };
>     d1.swap (d2);
>     assert (d2.begin () == iters [0][0]);
>     assert (d2.end ()== iters [0][1]);
>     assert (d1.begin () == iters [1][0]);
>     assert (d1.end ()== iters [1][1]);
>     return 0;
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.