From: Lionel Draghi <lionel.draghi@gmail.com>
Subject: Iterable container as generic parameter
Date: Wed, 24 Jan 2018 16:22:21 -0800 (PST)
Date: 2018-01-24T16:22:21-08:00 [thread overview]
Message-ID: <61ba3677-0041-4dba-af9b-a5df48f3ce8a@googlegroups.com> (raw)
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
next reply other threads:[~2018-01-25 0:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-25 0:22 Lionel Draghi [this message]
2018-01-25 3:36 ` Iterable container as generic parameter Randy Brukardt
2018-01-25 14:58 ` Lionel Draghi
2018-01-25 18:26 ` briot.emmanuel
2018-01-26 4:50 ` Randy Brukardt
2018-01-26 9:09 ` briot.emmanuel
2018-01-26 22:32 ` Lionel Draghi
2018-01-27 7:03 ` Randy Brukardt
2018-01-27 11:38 ` Lionel Draghi
2018-01-27 14:31 ` Jere
2018-01-28 18:08 ` Lionel Draghi
2018-01-29 13:34 ` briot.emmanuel
2018-01-29 22:26 ` Lionel Draghi
2018-01-29 23:00 ` Randy Brukardt
2018-01-30 22:35 ` Lionel Draghi
2018-01-30 23:32 ` Lionel Draghi
2018-01-31 0:15 ` Lionel Draghi
2018-01-30 15:13 ` Shark8
2018-01-26 23:07 ` Lionel Draghi
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox