From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: Wanted: Ada STL. Reward: Ada's Future
Date: 1999/02/05
Date: 1999-02-05T00:00:00+00:00 [thread overview]
Message-ID: <u4sp051dw.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 36B9E159.C072ECDA@prolifics.com
Hyman Rosen <hymie@prolifics.com> writes:
> Stephen Leake wrote:
> > I thought Matthew just did that, but you haven't answered the question
> > "why does the STL allow iteration past the end of the array". This
> > bugs me too. Is there a real reason here, or is it an accident of the
> > implementation?
>
> STL iterators are analogous to C pointers; one goal of the STL design is to
> be able to use C pointers as iterators in any STL algorithm. Given that C
> allows a one-past-the-end pointer to an array, it becomes natural to
> express
> STL ranges as [i,j). This allows an entire array to be spanned, as well as
> allowing an empty range to be easily specified.
Ok, that's what I thought. The STL style of expressing ranges as [i,j)
is an consequence of the implementation, not a requirement of the
design.
I don't see why allowing pointers as iterators is a good idea in the
first place. How do you efficiently maintain the head and tail
pointers, or other list-wide state, for a doubly linked list when you
insert from a plain pointer? Apparently you don't!
So for an Ada "STL", we can either use [i,j) to be somewhat compatible
with C++ STL, or we can use [i .. j] to be more Ada-like. I'm not
clear what the best choice would be, but I lean towards being
Ada-like. I'd rather woo good Ada programers than ex-C++ programers :).
> > Perhaps it is the most general way to define an iterator that points
> > to nothing? Certainly if the underlying implementation of a collection
> > is an array, this makes sense. But if the underlying implementation is
> > a list, then a null pointer makes more sense. Why not make the
> > abstraction resemble a null pointer, rather than an out-of-bounds
> > index?
>
> Because you don't always want to operate on the entire container, of
> course.
> STL algorithms take a pair of iterators when they need a range specified,
> and
> this allows them to work on arbitrary sections of a container. Also, when
> an
> algorithm requires a bidirectional iterator, you can go back from a
> past-the-end
> iterator, but not from a null pointer.
Depends on what else you store in the iterator data structure. If you
store a pointer to the container itself, you can do what's required.
Again, insisting that a plain pointer can be an iterator is too
restricting.
-- Stephe
next prev parent reply other threads:[~1999-02-05 0:00 UTC|newest]
Thread overview: 102+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-01-31 0:00 Wanted: Ada STL. Reward: Ada's Future Alexy V Khrabrov
1999-01-31 0:00 ` Simon Wright
1999-02-01 0:00 ` Jeff Carter
1999-02-08 0:00 ` Michael F Brenner
1999-02-01 0:00 ` Brian Rogoff
1999-02-01 0:00 ` Ehud Lamm
1999-02-02 0:00 ` Pointer Arithmetic (was: Wanted: Ada STL....) adam
1999-02-02 0:00 ` William Clodius
1999-02-03 0:00 ` adam
1999-02-03 0:00 ` robert_dewar
1999-02-03 0:00 ` Jean-Pierre Rosen
1999-02-03 0:00 ` William Clodius
1999-02-03 0:00 ` Nick Roberts
1999-02-03 0:00 ` Nick Roberts
1999-02-03 0:00 ` robert_dewar
1999-02-03 0:00 ` Robert A Duff
1999-02-03 0:00 ` robert_dewar
1999-02-02 0:00 ` Wanted: Ada STL. Reward: Ada's Future Brian Rogoff
1999-02-02 0:00 ` robert_dewar
1999-02-04 0:00 ` Ehud Lamm
1999-02-03 0:00 ` John English
1999-02-03 0:00 ` Matthew Heaney
1999-02-03 0:00 ` Brian Rogoff
1999-02-04 0:00 ` Stephen Leake
1999-02-04 0:00 ` Matthew Heaney
1999-02-04 0:00 ` Brian Rogoff
1999-02-05 0:00 ` Stephen Leake
1999-02-05 0:00 ` Brian Rogoff
1999-02-04 0:00 ` Hyman Rosen
1999-02-05 0:00 ` Stephen Leake [this message]
1999-02-05 0:00 ` Hyman Rosen
1999-02-05 0:00 ` John English
1999-02-05 0:00 ` Brian Rogoff
1999-02-06 0:00 ` Matthew Heaney
1999-02-05 0:00 ` Tucker Taft
1999-02-05 0:00 ` Brian Rogoff
1999-02-05 0:00 ` Richard D Riehle
1999-02-05 0:00 ` Nick Roberts
1999-02-05 0:00 ` John English
1999-02-04 0:00 ` Ehud Lamm
1999-02-04 0:00 ` Al Christians
1999-02-04 0:00 ` Pat Rogers
1999-02-04 0:00 ` Larry Kilgallen
1999-02-04 0:00 ` Pat Rogers
1999-02-04 0:00 ` Larry Kilgallen
1999-02-05 0:00 ` robert_dewar
1999-02-05 0:00 ` Tom Moran
1999-02-05 0:00 ` dewar
1999-02-05 0:00 ` Tom Moran
1999-02-05 0:00 ` dewar
1999-02-05 0:00 ` dennison
1999-02-06 0:00 ` dewar
1999-02-08 0:00 ` dennison
1999-02-08 0:00 ` robert_dewar
1999-02-08 0:00 ` dennison
1999-02-09 0:00 ` robert_dewar
1999-02-09 0:00 ` dennison
1999-02-09 0:00 ` Nick Roberts
1999-02-07 0:00 ` Simon Wright
1999-02-08 0:00 ` Corey Minyard
1999-02-08 0:00 ` Open Source Licensing (was: Wanted: Ada STL. Reward: Ada's Future) dennison
1999-02-08 0:00 ` Corey Minyard
1999-02-09 0:00 ` dennison
1999-02-09 0:00 ` Corey Minyard
1999-02-09 0:00 ` robert_dewar
1999-02-09 0:00 ` Corey Minyard
1999-02-09 0:00 ` Wanted: Ada STL. Reward: Ada's Future robert_dewar
1999-02-09 0:00 ` dennison
1999-02-10 0:00 ` robert_dewar
1999-02-07 0:00 ` Simon Wright
1999-02-05 0:00 ` Larry Kilgallen
[not found] ` <36ba730b.35540068@ <79fmg1$fn0$1@nnrp1.dejanews.com>
1999-02-06 0:00 ` Larry Kilgallen
1999-02-05 0:00 ` robert_dewar
1999-02-05 0:00 ` robert_dewar
1999-02-05 0:00 ` Larry Kilgallen
1999-02-05 0:00 ` robert_dewar
[not found] ` <79f24e$t14 <36BB4162.52FC6D9F@averstar.com>
1999-02-05 0:00 ` dennison
1999-02-05 0:00 ` robert_dewar
1999-02-05 0:00 ` dennison
1999-02-05 0:00 ` robert_dewar
1999-02-05 0:00 ` dennison
1999-02-06 0:00 ` Nick Roberts
1999-02-05 0:00 ` Tucker Taft
1999-02-04 0:00 ` Brian Rogoff
1999-02-05 0:00 ` Matthew Heaney
1999-02-05 0:00 ` Brian Rogoff
1999-02-08 0:00 ` John English
1999-02-05 0:00 ` John English
1999-02-09 0:00 ` micro_ada
1999-02-05 0:00 ` Nick Roberts
1999-02-08 0:00 ` John English
1999-02-02 0:00 ` Richard D Riehle
1999-02-03 0:00 ` robert_dewar
1999-02-01 0:00 ` Matthew Heaney
1999-02-01 0:00 ` Alexy V Khrabrov
1999-02-01 0:00 ` Matthew Heaney
1999-02-01 0:00 ` Jeff Carter
1999-02-01 0:00 ` Stanley R. Allen
1999-02-01 0:00 ` dennison
1999-02-01 0:00 ` Jerry van Dijk
1999-02-01 0:00 ` Marin David Condic
1999-02-05 0:00 ` Corey Minyard
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox