comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: Missing in Booch: range operations
Date: 13 Nov 2002 12:17:39 -0800
Date: 2002-11-13T20:17:40+00:00	[thread overview]
Message-ID: <1ec946d1.0211131217.1a300d32@posting.google.com> (raw)
In-Reply-To: x7vznsizw0n.fsf@smaug.pushface.org

Simon Wright <simon@pushface.org> wrote in message news:<x7vznsizw0n.fsf@smaug.pushface.org>...
> mheaney@on2.com (Matthew Heaney) writes:
> 
> > The problem is that iterators only know about elements -- they don't
> > know anything about containers.  Neither Charles nor the STL attempts
> > to detect this error.
> 
> Matt, you say this as though it were a law of nature! There is nothing
> in the notion of iterator that prevents them knowing about the
> container. Indeed (being pedantic) the very name iterator indicates
> that there is a container involved (otherwise, what would you be
> iterating over?)

When I speak of an iterator, I am refering to what STL and Charles do.
 In that model, iterators don't know about containers.

Charles iterators are modelled on iteration thru a linked list, for
example:

  List : List_Type;

  declare
    Node : Node_Access := List.Head;
  begin
    while Node /= null loop
      <do something with Node.Element>
      Node := Node.Next;
    end loop;
  end;

In other words, the "iterator" Node_Access doesn't know anything about
the list object.  It only knows about the nodes in the list (and nodes
in the list don't know anything about the list, either).

Of course, it is possible to implement an iterator type as a "fat"
pointer, comprising a pointer to the internal node, and another
pointer to the container.  But this is not necessary in order to have
a working iterator, and it does incur a space penalty.

Charles has been optimized for flexibility and efficiency, and it is
general enough that such a layer (comprising a "fat" iterator) on top
of the existing infrastructure can be implemented quite easily.  As
much as possible I prefer to defer issues as this ("thin" vs. "fat"
iterators) to the library user.



  reply	other threads:[~2002-11-13 20:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-08 10:09 Missing in Booch: range operations Victor Porton
2002-11-08 15:01 ` Stephen Leake
2002-11-08 21:07 ` Matthew Heaney
2002-11-09 13:56   ` Simon Wright
2002-11-13 20:17     ` Matthew Heaney [this message]
2002-11-08 21:35 ` Matthew Heaney
2002-11-09  8:24 ` Victor Porton
2002-11-13 20:22   ` Matthew Heaney
2002-11-13 22:28     ` Stephen Leake
2002-11-09  8:46 ` Victor Porton
2002-11-09 14:12   ` Simon Wright
2002-11-09 14:04 ` Simon Wright
2002-11-09 16:12 ` Victor Porton
2002-11-09 20:00   ` Simon Wright
2002-11-11  5:41 ` Victor Porton
2002-11-11  6:39   ` Simon Wright
2002-11-11  7:50 ` Victor Porton
2002-11-13 20:26   ` Matthew Heaney
2002-11-13 22:28     ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox