From: Jere <jhb.chat@gmail.com>
Subject: Re: Multiple iterators for a type
Date: Fri, 25 May 2018 21:44:16 -0700 (PDT)
Date: 2018-05-25T21:44:16-07:00 [thread overview]
Message-ID: <05c268e9-9dfc-44d5-b500-5332eae7b854@googlegroups.com> (raw)
In-Reply-To: <574749990.548999719.627915.laguest-archeia.com@nntp.aioe.org>
On Friday, May 25, 2018 at 11:57:47 PM UTC-4, Luke A. Guest wrote:
> Stephen Leake <> wrote:
>
> > 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, but
> > you did not mention that as a requirement.
> >
>
> I’m attempting to implement a Unicode string using UTF-8, so I want the
> basic iterator over octets, then the next will iterate over the octets and
> generate code points, then another will be graphème clusters.
When I did multiple iterators I ended up making a package for it, which I
later adapted just for fun to provide iteration of types in generics.
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-containers-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-containers-predefined_iterable_wrappers.ads
Some testing of the predefined wrappers that I made:
https://github.com/jeremiahbreeden/bullfrog/blob/master/src/tests/test_generic_iteration.adb
next prev parent reply other threads:[~2018-05-26 4:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-25 16:49 Multiple iterators for a type Lucretia
2018-05-25 19:50 ` Jacob Sparre Andersen
2018-05-25 21:50 ` Randy Brukardt
2018-05-26 3:13 ` Stephen Leake
2018-05-26 3:57 ` Luke A. Guest
2018-05-26 4:44 ` Jere [this message]
2018-05-26 6:59 ` Dmitry A. Kazakov
2018-05-26 12:33 ` Dan'l Miller
2018-05-26 13:03 ` Lucretia
2018-05-26 13:52 ` Dmitry A. Kazakov
2018-05-26 14:22 ` Dan'l Miller
2018-05-26 7:14 ` G.B.
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox