Topic: list::end() persistence


Author: James.Kanze@dresdner-bank.com
Date: Mon, 11 Dec 2000 17:43:13 GMT
Raw View
In article <ur93lkm4a.wl@mapc7.cse.canon.co.jp>,
  "MYO'KI Yutaka" (=?ISO-2022-JP?B?GyRCTC9MWhsoQiAbJEJNNRsoQg==?=)
<myoki.yutaka@canon.co.jp> wrote:
> In ISO/IEC 14882:1998 "23.2.2.3 list modifiers", there are notes
> that say modifications does not invalidate any iterators except that
> to the erased elements. Does this assertion apply to list::end()
> returns?  i.e. Can I save the iterator list::end() returns, do some
> modifications to the list, and use the saved iterator?

I would expect so, since the standard says so.

> example:

>     #include <list>
>     using namespace std;

>     list<int> l;
>     list<int>::iterator i;

>     i = l.end();
>     l.push_back(1);            // *1
>     if (i == l.end())
>        // Is this always true? // *2

> I have tested and concluded that *2 is always evaluated true no
> matter what modifications *1 are /w Visual C++ 6.0 (Japanese Ed.)
> . I want to know whether this is true or not in terms of IS.

This would be the behavior I would expect.  The end is the end,
always.  More concretely, if you imagine end() pointing to some
phantom element, you cannot insert behind this element, so even
push_back must insert in front of it.

>From an implementation point of view, any other behavior would be
almost impossible as well.

--
James Kanze                               mailto:kanze@gabi-soft.de
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
Ziegelh   ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "MYO'KI Yutaka" (=?ISO-2022-JP?B?GyRCTC9MWhsoQiAbJEJNNRsoQg==?=)
Date: Fri, 8 Dec 2000 14:59:36 GMT
Raw View
In ISO/IEC 14882:1998 "23.2.2.3 list modifiers", there are notes that
say modifications does not invalidate any iterators except that to the
erased elements. Does this assertion apply to list::end() returns?
i.e. Can I save the iterator list::end() returns, do some
modifications to the list, and use the saved iterator?

example:

    #include <list>
    using namespace std;

    list<int> l;
    list<int>::iterator i;

    i = l.end();
    l.push_back(1);            // *1
    if (i == l.end())
       // Is this always true? // *2

I have tested and concluded that *2 is always evaluated true no matter
what modifications *1 are /w Visual C++ 6.0 (Japanese Ed.) . I want to
know whether this is true or not in terms of IS.

This is only my technical interest. I don't want to use this behavior
in my real life ;-)

Thanks in advance.

--
  MYO'KI, Yutaka / Internet Business Development Center, Canon Inc.
* mailto:myoki.yutaka@canon.co.jp

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]