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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a6b:2552:: with SMTP id l79-v6mr2251680iol.22.1527309857381; Fri, 25 May 2018 21:44:17 -0700 (PDT) X-Received: by 2002:a9d:5543:: with SMTP id h3-v6mr536188oti.13.1527309857210; Fri, 25 May 2018 21:44:17 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!u74-v6no2846549itb.0!news-out.google.com!f20-v6ni2513itd.0!nntp.google.com!v8-v6no2852196itc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 25 May 2018 21:44:16 -0700 (PDT) In-Reply-To: <574749990.548999719.627915.laguest-archeia.com@nntp.aioe.org> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=96.247.198.106; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 96.247.198.106 References: <574749990.548999719.627915.laguest-archeia.com@nntp.aioe.org> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <05c268e9-9dfc-44d5-b500-5332eae7b854@googlegroups.com> Subject: Re: Multiple iterators for a type From: Jere Injection-Date: Sat, 26 May 2018 04:44:17 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:52689 Date: 2018-05-25T21:44:16-07:00 List-Id: On Friday, May 25, 2018 at 11:57:47 PM UTC-4, Luke A. Guest wrote: > Stephen Leake <> wrote: >=20 > > An "iterator" can be anything you want it to be. As Randy pointed out, > > there can be only one that gets special treatment from the compiler, bu= t > > you did not mention that as a requirement. > >=20 >=20 > I=E2=80=99m attempting to implement a Unicode string using UTF-8, so I wa= nt the > basic iterator over octets, then the next will iterate over the octets an= d > generate code points, then another will be graph=C3=A8me clusters. When I did multiple iterators I ended up making a package for it, which I= =20 later adapted just for fun to provide iteration of types in generics. =20 The steps I ended up doing were: 1. Create my Cursor type and Has Element 2. Create a set of functions returning reference types, but use a package to do it so I could pass them into another generic 3. Instantiate Iterator_Interfaces for my cursor 4. Implement my iterator 5. Pass it into a package that created an iterable wrapper Technically if you just want "in" iteration, you stop at #4, but I like the "of" version so that is why I made a package for step 5. In the end I was able to get something like: for E of Iterable(Container_Object) loop E.Do_Things; end loop; where Iterable is a function from my generic package that returns an iterable version of Container object. It was handy for generics and having multiple iterators, though it comes at a performance cost since it uses a layer on top of the container. Package for making reference types: https://github.com/jeremiahbreeden/bullfrog/blob/master/src/bullfrog-access= _types-references.ads Package for making "of" iterable wrappers: https://github.com/jeremiahbreeden/bullfrog/blob/master/src/bullfrog-contai= ners-iterable_wrappers.ads Package with some predefined wrappers of the standard containers to my iterable wrappers: https://github.com/jeremiahbreeden/bullfrog/blob/master/src/bullfrog-contai= ners-predefined_iterable_wrappers.ads Some testing of the predefined wrappers that I made: https://github.com/jeremiahbreeden/bullfrog/blob/master/src/tests/test_gene= ric_iteration.adb