Topic: Koenig's proposed iterator conventions


Author: kanze@us-es.sel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 05 Dec 1994 17:58:17 GMT
Raw View
|> Matt Austern (matt@physics2.berkeley.edu) wrote:
|> : (Personally, my taste in iterators is slightly different: I prefer
|> : iterators that look like integral indices, not iterators that look

|> : like pointers.  On the other hand, I'm not silly enough to want to
|> : write my own collection class library because of a small issue like
|> : this: pointer-semantics iterators are the way things are, and people
|> : like me will just have to get used to it.)

Actually, I don't think one excludes the other.  My own classes have
always used iterators (called cursors) with index semantics.  But I
don't think it will be any big deal using templates to add a wrapper
which takes a cursor and a contain, and makes an STL compatible
iterator.  (Some work may be needed to handle end conditions, but that
is about it.)  And the fact that raw pointers (into a C style array)
are also compatible shouldn't be neglected.

So locally, I will continue to use the indexing idiom, and convert to
the STL compatible forms whenever necessary (much like I did in C,
when I would convert an indexed array reference to a pointer).

An interesting thought: most of my index operators actually return
proxies.  So I overload operator& in the proxy to return the STL
iterator?  The results:

 for ( MyCursor i( myContainer ) ; ! i.finished() ; ++ i )
     functionWithSTLConventions( &myContainer[ i ] ) ;

Looks somehow familiar, already.
--
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                              -- Beratung in industrieller Datenverarbeitung






Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Tue, 6 Dec 1994 15:08:24 GMT
Raw View
In article   writes:
>itoba.ca!newsflash.concordia.ca!CC.UMontreal.CA!cdec.polymtl.ca!mauchly!linh
>From: linh@info.polymtl.ca (Li~nh)
>Newsgroups: comp.std.c++
>Subject: Re: Koenig's proposed iterator conventions
>Date: 1 Dec 1994 16:36:20 GMT
>Organization: Ecole Polytechnique de Montreal
>Lines: 15
>Message-ID: <3bku24$ecu@charles.cdec.polymtl.ca>
>References: <THOTH.94Nov30115233@native.cis.ufl.edu> <MATT.94Nov30092440@physics2.berkeley.edu>
>NNTP-Posting-Host: mauchly.info.polymtl.ca
>X-Newsreader: TIN [version 1.2 PL2]
>
>Matt Austern (matt@physics2.berkeley.edu) wrote:
>: (Personally, my taste in iterators is slightly different: I prefer
>: iterators that look like integral indices, not iterators that look
>
>Me too :-((((
>
>LD.
>
>: like pointers.  On the other hand, I'm not silly enough to want to
>: write my own collection class library because of a small issue like
>: this: pointer-semantics iterators are the way things are, and people
>: like me will just have to get used to it.)
>: --
>
>:                                --matt


--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189




Author: thoth@native.cis.ufl.edu (Robert Forsman)
Date: 30 Nov 1994 16:52:33 GMT
Raw View
  A friend handed me an article from some journal where Andrew Koenig
discussed a proposal for iterator conventions.  Basically iterators
would be used in a way similar to pointers:

void do_work (ThingIter iter, ThingIter beyond)
{
 while (iter<beyond) {
  f( *(iter++));
 }
}

  He discussed iterators that could go forward and backward, and a few
other things.  However, he didn't go into enough detail on the exact
interface.  What I want to see is something like a header file that
details the exact operations that are provided on iterators of the
various types.

  Anyone have a clue?
--
Eat now this hot-dog with ketchup, flesh of his flesh, blood of his blood.
Supercalafragalisticextrasacreligious
I deal with Reality as you _don't_ understand it.
blah = realloc(blah, sizeof(*blah)*(blahsize*=2)); /* (TM) */




Author: matt@physics2.berkeley.edu (Matt Austern)
Date: 30 Nov 1994 17:24:40 GMT
Raw View
In article <THOTH.94Nov30115233@native.cis.ufl.edu> thoth@native.cis.ufl.edu (Robert Forsman) writes:

>   He discussed iterators that could go forward and backward, and a few
> other things.  However, he didn't go into enough detail on the exact
> interface.  What I want to see is something like a header file that
> details the exact operations that are provided on iterators of the
> various types.

I haven't seen Andrew Koenig's paper; I suspect, though, considering
that he contributed to the design of the STL, that the iterators he
proposed are very similar to the STL iterators.  The STL does have
forward iterators, reverse iterators, const iterators, and so on.
More to the point, the STL defines a set of standard conventions that
any iterator of each type must adhere to.

The STL iterators are now part of the language, so it's probably a
good idea for all of us to be familiar with them anyway...

(Personally, my taste in iterators is slightly different: I prefer
iterators that look like integral indices, not iterators that look
like pointers.  On the other hand, I'm not silly enough to want to
write my own collection class library because of a small issue like
this: pointer-semantics iterators are the way things are, and people
like me will just have to get used to it.)
--

                               --matt




Author: cks@crl8.crl.com (Christopher K. St. John)
Date: 30 Nov 1994 19:04:29 GMT
Raw View
matt@physics2.berkeley.edu (Matt Austern):
>I haven't seen Andrew Koenig's paper; I suspect, though, considering
>that he contributed to the design of the STL, that the iterators he
>proposed are very similar to the STL iterators.  The STL does have

I have skimmed the Stepanov & Lee paper "The Standard Template Library"
and hp's sample STL code, and I did not see the void* cast operator
that would allow while(iter) { ... }.

Is this not part of STL? It seems to be a common idiom. Note that I
said skimmed, so I might be missing something here.


--
----------------------------------------------------------------------
      - christopher kelly st. john - cks@crl.com -
----------------------------------------------------------------------




Author: Pete Becker <pete@borland.com>
Date: Wed, 30 Nov 1994 19:39:05 GMT
Raw View
> I have skimmed the Stepanov & Lee paper "The Standard Template Library"
> and hp's sample STL code, and I did not see the void* cast operator
> that would allow while(iter) { ... }.
>
> Is this not part of STL? It seems to be a common idiom. Note that I
> said skimmed, so I might be missing something here.
>
>
> --
> ----------------------------------------------------------------------
>       - christopher kelly st. john - cks@crl.com -
> ----------------------------------------------------------------------

 Be very careful about what assumptions you make here. In
particular, an "iterator" in STL is almost certainly not what you
think it is. The basic model is that iterators work like pointers. You
can increment a pointer, dereference it, and compare it to another
pointer. Same thing with iterators. In practice this means that the
way you test for completion is to compare one iterator to another.
Like this:

 int a[100];

 int *begin = a;  // current object
 int *end = a+100; // past-the-end
 while( begin != end )
  {
  cout << *begin << endl;
  begin++;
  }

    -- Pete






Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 30 Nov 1994 20:57:16 GMT
Raw View
In article 94Nov30110430@crl8.crl.com, cks@crl8.crl.com (Christopher K. St. John) writes:
>
>I have skimmed the Stepanov & Lee paper "The Standard Template Library"
>and hp's sample STL code, and I did not see the void* cast operator
>that would allow while(iter) { ... }.
>
>Is this not part of STL? It seems to be a common idiom. Note that I
>said skimmed, so I might be missing something here.

You don't use that idiom with STL. You typically compare an iterator
with the 'begin' or 'end' component of a container, or you use
an algorithm function template which takes iterators as parameters.
You need to read the paper.


---
Steve Clamage, stephen.clamage@eng.sun.com






Author: ark@research.att.com (Andrew Koenig)
Date: Wed, 30 Nov 1994 20:28:55 GMT
Raw View
In article <THOTH.94Nov30115233@native.cis.ufl.edu> thoth@native.cis.ufl.edu (Robert Forsman) writes:

>   A friend handed me an article from some journal where Andrew Koenig
> discussed a proposal for iterator conventions.  Basically iterators
> would be used in a way similar to pointers:

> void do_work (ThingIter iter, ThingIter beyond)
> {
>  while (iter<beyond) {
>   f( *(iter++));
>  }
> }

I guess I didn't say it clearly enough in the article:
these conventions are the ones STL uses.  So ftp over
to butler.hpl.hp.com and read the STL document if you
want to see all the gory details.
--
    --Andrew Koenig
      ark@research.att.com




Author: linh@info.polymtl.ca (Li~nh)
Date: 1 Dec 1994 16:36:20 GMT
Raw View
Matt Austern (matt@physics2.berkeley.edu) wrote:
: (Personally, my taste in iterators is slightly different: I prefer
: iterators that look like integral indices, not iterators that look

Me too :-((((

LD.

: like pointers.  On the other hand, I'm not silly enough to want to
: write my own collection class library because of a small issue like
: this: pointer-semantics iterators are the way things are, and people
: like me will just have to get used to it.)
: --

:                                --matt