Re: Storing a tree in a std::list<>

From: Dave (better_cs_now_at_yahoo.com)
Date: 06/06/04


Date: Sat, 5 Jun 2004 18:29:07 -0700


"Alan Johnson" <alanwj@mailandnews.com> wrote in message
news:40c267a1$1@news.ua.edu...
> Dave wrote:
> > Hello all,
> >
> > After perusing the Standard, I believe it is true to say that once you
> > insert an element into a std::list<>, its location in memory never
changes.
> > This makes a std::list<> ideal for storing vertices of an arbitrary
n-ary
> > tree where a vertex contain pointers to its parent / children. These
parent
> > / child vertices need to stay put if we've got pointers to them
somewhere!
> >
> > Am I correct in my assertion?
> >
> > Thanks,
> > Dave
> >
> >
>
> While that probably is true for almost any implementation, I don't think
> that the standard actually requires it. What it does require is that
> adding/removing elements (as well as most other operations) do not
> invalidate any iterators to elements of the list.
>
> Alan

Hmmm, references too. But yes, technically not pointers. I wonder if one
can assume that iterators and references not being invalidated implies that
pointers are not invalidated...



Relevant Pages

  • Re: Storing a tree in a std::list<>
    ... Dave wrote: ... > tree where a vertex contain pointers to its parent / children. ... that the standard actually requires it. ... adding/removing elements do not ...
    (comp.lang.cpp)
  • Re: pointer to an elment in a stl vector
    ... it is blessed by the standard. ... >> If the vector increases in size could it invalidate that pointer? ... > This will invalidate all iterators and pointers derived from ... And of course also pointers not derived from iterators. ...
    (comp.lang.cpp)
  • Re: Wait cursor not always displaying ?
    ... I think this is it and I assume it is standard across devices: ... Dave ... If the system is really stressed then the wait cursor can ... >> especially notice this with networking operations. ...
    (microsoft.public.pocketpc.developer)
  • Re: maximum Number object
    ... Happy to see all your attentions...I tested the MaxInt() ... functions given by Dave, both verions. ... standard Number.MAX_VALUE. ...
    (microsoft.public.scripting.jscript)
  • Re: OT: pikey Freeview box review and FOAK question
    ... So the Tevion box is a penny short of 20 quid. ... Plugged in to my standard, been there for at least ten ... scart connection but only 17 quid. ... On checking again I shouldn't be able to get Dave until after switch ...
    (uk.rec.motorcycles)