From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fed2e7871ca258cd X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-28 11:44:51 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: List Container Strawman 1.4 Date: Fri, 28 Dec 2001 14:49:09 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <87lmfsn2jj.fsf@deneb.enyo.de> <3C2CA143.6030006@mail.com> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:18365 Date: 2001-12-28T14:49:09-05:00 List-Id: "Hyman Rosen" 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.