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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.26.203 with SMTP id a194mr4276420ioa.22.1516839741753; Wed, 24 Jan 2018 16:22:21 -0800 (PST) X-Received: by 10.157.65.183 with SMTP id p52mr756154ote.3.1516839741618; Wed, 24 Jan 2018 16:22:21 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!feeder.erje.net!2.eu.feeder.erje.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!g80no306822itg.0!news-out.google.com!s63ni4472itb.0!nntp.google.com!g80no306819itg.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 24 Jan 2018 16:22:21 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2a01:e35:2ecd:88c0:39b8:82a9:583e:570d; posting-account=O1Kt4QoAAABKYAjrg-cGai_vZLnN2LEw NNTP-Posting-Host: 2a01:e35:2ecd:88c0:39b8:82a9:583e:570d User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <61ba3677-0041-4dba-af9b-a5df48f3ce8a@googlegroups.com> Subject: Iterable container as generic parameter From: Lionel Draghi Injection-Date: Thu, 25 Jan 2018 00:22:21 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:50125 Date: 2018-01-24T16:22:21-08:00 List-Id: I would like to make a generic function containing this simple code : for E of L loop Put_Line (Image (E)); end loop; And I would like to have this generic compatible with all "iterable container". I thought it would be possible by just providing as generic parameters the Image function, and an Ada.Iterator_Interfaces instantiation, but without referencing the container. Isn't the iterator supposed to encapsulates both the cursor and the container? Something like : generic type Cursor is (<>); with function Image (C : Cursor) return String; with package Iterator_Interfaces is new Ada.Iterator_Interfaces (Cursor, others => <>); function List_Image return String; But I couldn't figure out a simple way to do the body : 1. using the "for E of L" or the "for C in L.Iterate" loop refers to L, the Iterable container : why should I need that here? 2. and it's not clear for me how to directly use a Cursor with First and Next functions provided by Iterator_Interfaces, that need a Forward_Iterator parameter. Any hints? Thanks, -- -- Lionel