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

From: Alan Johnson (alanwj_at_mailandnews.com)
Date: 06/06/04


Date: Sat, 05 Jun 2004 19:45:58 -0500

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



Relevant Pages

  • Re: Storing a tree in a std::list<>
    ... > Dave wrote: ... > that the standard actually requires it. ... > invalidate any iterators to elements of the list. ... But yes, technically not pointers. ...
    (comp.lang.cpp)
  • Re: "<>", a relational operator?
    ... And in Standard C there are significant restrictions ... OTOH in BCPL and B pointers were ... has no whole array operations; if you want something done to all (or ... the Standard isn't vague at all -- this is specifically ...
    (comp.lang.fortran)
  • Re: Requesting advice how to clean up C code for validating string represents integer
    ... The standard form is like this, ... 1108 The sizeof operator ... ... being able to compare unrelated pointers, ... So long as the pointers are of the same type, ...
    (comp.lang.c)
  • Re: bug in visual studio .net 2003 - breakpoints and memcpy
    ... Posix is a standard too with no less (some would say ... > platforms that support the conversion. ... Conversion between code pointers to integers does not exist for the sole ...
    (microsoft.public.win32.programmer.kernel)
  • Re: "Mastering C Pointers"....
    ... I'm not talking about your pointer response, which was generally good, as I ... Together they will help you understand pointers. ... >> Maybe for understanding the C standard. ... > principles laid out in the Standard is vital. ...
    (comp.lang.c)