You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@stdcxx.apache.org by "Farid Zaripov (JIRA)" <ji...@apache.org> on 2008/03/16 06:22:24 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&focusedCommentId=12579162#action_12579162 ] 

farid edited comment on STDCXX-635 at 3/15/08 10:21 PM:
----------------------------------------------------------------

Fixed thus: http://svn.apache.org/viewvc?rev=637539&view=rev

The _C_cur data member of the deque iterator equal to 0 if and only if the deque is empty.
So if one of the iterators passed as arguments to operator-() is iterator of the empty deque, we can return the difference between _C_cur members of these iterators. So if both of them are iterators from the same deque - the result == 0 is valid. If these iterators are from different deque's, the result is undefined, but standard says nothing about result of subtracting the iterators of the different containers. Also if both of these iterators are iterators from different empty deque's, the result will be 0, but this result is still meets the standard requirements (0 value is part of undefined values range).


      was (Author: farid):
    Fixed thus: http://svn.apache.org/viewvc?rev=637539&view=rev

The _C_cur data member of the deque iterator equal to 0 iff the deque is empty.
So if one of the iterators passed as arguments to operator-() is iterator of the empty deque, we can return the difference between _C_cur members of these iterators. So if both of them are iterators from the same deque - the result == 0 is valid. If these iterators are from different deque's, the result is undefined, but standard says nothing about result of subtracting the iterators of the different containers. Also if both of these iterators are iterators from different empty deque's, the result will be 0, but this result is still meets the standard requirements (0 value is part of undefined values range).

  
> 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.0
>         Environment: All
>            Reporter: Farid Zaripov
>            Assignee: Farid Zaripov
>            Priority: Minor
>             Fix For: 4.2.1
>
>   Original Estimate: 2h
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> 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.