comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: List Container Strawman 1.4
Date: Fri, 28 Dec 2001 14:49:09 -0500
Date: 2001-12-28T14:49:09-05:00	[thread overview]
Message-ID: <u2pitjhps1bp07@corp.supernews.com> (raw)
In-Reply-To: 3C2CA143.6030006@mail.com


"Hyman Rosen" <hyrosen@mail.com> wrote in message
news:3C2CA143.6030006@mail.com...
> Ted Dennison wrote:
>
> > Actually, I was thinking along the lines of an Containers.Lists.Fixed
>
>  > package that works with arrays.
>
> I think this kind of thing is where C++'s iterators and algorithms
> approach shows its superiority. Why should a List have any notion
> of other data structures to which its elements can be copied?

You're right, it shouldn't.  Iterators allow you to abstract away the
differences among different containers.  That's the whole point.

The app I will be submitting to the Ada-Belgium competition includes a list
container type that allows you to copy its items using iterators, like this:

List : Integer_Lists.List_Type;
...
declare
   Items : array (1 .. Length (List)) of Integer;
   Iter : Iterator_Type := First (List);
begin
   for I in Items'Range loop
      Items (I) := Item (Iter);
      Next (Iter);
   end loop;
end;

(My list type has selectors that return iterators designating First, Last,
Front, and Back.  The latter two are sentinals.)

It would be easy to generalize this algorithm to copy items from any
container type with an iterator:

generic
   type Iterator_Type (<>) is private;
   type Item_Type is private;
   type Item_Array is array (Positive range <>) of Item_Type;
   with function "=" (L, R : Iterator_Type) return Boolean is <>;
procedure Generic_Copy
  (First  : in      Iterator_Type;
   Back : in      Iterator_Type;
   Items : in out Items_Type);

procedure Generic_Copy (...) is
   Iter : Iterator_Type := First;
   I : Positive := Items'First;
begin
   while Iter /= Back loop
      Items (I) := Item (Iter);
      Next (Iter);
      I := I + 1;
   end loop;
end Generic_Copy;

If you wanted, you could generalize this further (as the STL does) to
abstract away the target type (in the example above we've hard-coded an
array type as the target type).  To do this for arrays you'd need an
appropriate iterator type; maybe Interfaces.C.Pointers would work.









  parent reply	other threads:[~2001-12-28 19:49 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-13  3:23 List Container Strawman 1.4 Ted Dennison
2001-12-13 18:11 ` Brian Hanson
2001-12-13 23:02 ` Nick Roberts
2001-12-14 15:19   ` Ted Dennison
2001-12-14 23:54     ` Ted Dennison
2001-12-15  2:06       ` Server - tasking and long lived connections Eric Merritt
2001-12-15  3:10         ` James Rogers
2001-12-15 12:10           ` Florian Weimer
2001-12-15 14:38         ` Larry Kilgallen
2001-12-15 16:51         ` Steve Doiel
2001-12-17  9:15         ` Thierry Lelegard
2001-12-17  9:34           ` Jean-Pierre Rosen
2001-12-17 10:16             ` Thierry Lelegard
2001-12-18  9:08               ` Jean-Pierre Rosen
2001-12-17 15:08             ` Larry Kilgallen
2001-12-17 15:39               ` Pat Rogers
2001-12-19 18:20         ` Matthew Heaney
2001-12-19 18:50           ` Eric Merritt
2001-12-15  1:20     ` List Container Strawman 1.4 Nick Roberts
2001-12-15 20:29       ` Ted Dennison
2001-12-16 18:45         ` Nick Roberts
2001-12-21 15:53           ` Ted Dennison
2001-12-21 16:42             ` Marin David Condic
2001-12-21 18:28               ` Ted Dennison
2001-12-21 18:47                 ` Marin David Condic
2001-12-21 19:39                   ` Ted Dennison
2001-12-21 19:48                     ` Marin David Condic
2001-12-22 12:29                     ` Simon Wright
2001-12-21 20:03                   ` Nick Roberts
2001-12-21 16:52             ` Marin David Condic
2001-12-21 18:41               ` Ted Dennison
2001-12-21 19:14                 ` Marin David Condic
2001-12-21 21:13                   ` Ted Dennison
2001-12-22  5:34                     ` John B. Matthews
2001-12-21 20:19                 ` Stephen Leake
2001-12-21 21:35                   ` Ted Dennison
2001-12-24 11:58               ` Florian Weimer
2001-12-24 14:42                 ` Eric Merritt
2001-12-24 22:47                 ` Ted Dennison
2001-12-25 22:15                   ` Florian Weimer
2001-12-28 13:58                     ` Ted Dennison
2001-12-21 17:43             ` Stephen Leake
2001-12-21 18:44               ` Ted Dennison
2001-12-16 21:53         ` Larry Hazel
2001-12-15 22:27           ` Ted Dennison
2001-12-16  4:32             ` Darren New
2001-12-24 13:53               ` Florian Weimer
2001-12-15 23:19 ` Florian Weimer
2001-12-16  4:46   ` Ted Dennison
2001-12-24 13:57     ` Florian Weimer
2001-12-28 14:00       ` Ted Dennison
2001-12-28 16:43         ` Hyman Rosen
2001-12-28 19:12           ` Nick Roberts
2001-12-28 19:49           ` Matthew Heaney [this message]
2001-12-29 23:23             ` Matthew Heaney
2001-12-30  6:31               ` Hyman Rosen
2002-01-03  0:09                 ` Matthew Heaney
2002-01-03  0:20                   ` Brian Rogoff
2001-12-17  8:34   ` Mark Lundquist
2001-12-18 21:56     ` Florian Weimer
2001-12-18 21:54       ` Larry Kilgallen
2001-12-18 22:34       ` Mark Lundquist
2001-12-19  4:03         ` Nick Roberts
2001-12-24 13:54           ` Florian Weimer
replies disabled

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