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.31.137 with SMTP id f131mr7518808iof.7.1516904785774; Thu, 25 Jan 2018 10:26:25 -0800 (PST) X-Received: by 10.157.1.193 with SMTP id e59mr905542ote.13.1516904785454; Thu, 25 Jan 2018 10:26:25 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.am4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!w142no644279ita.0!news-out.google.com!s63ni156itb.0!nntp.google.com!g80no644167itg.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 25 Jan 2018 10:26:25 -0800 (PST) In-Reply-To: <6427a793-91a4-4feb-b067-ed89b4c04421@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=62.119.166.9; posting-account=6yLzewoAAABoisbSsCJH1SPMc9UrfXBH NNTP-Posting-Host: 62.119.166.9 References: <61ba3677-0041-4dba-af9b-a5df48f3ce8a@googlegroups.com> <6427a793-91a4-4feb-b067-ed89b4c04421@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Iterable container as generic parameter From: briot.emmanuel@gmail.com Injection-Date: Thu, 25 Jan 2018 18:26:25 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Body-CRC: 1931839058 X-Received-Bytes: 4739 Xref: reader02.eternal-september.org comp.lang.ada:50148 Date: 2018-01-25T10:26:25-08:00 List-Id: Lionel, This won't provide an answer to your specific question (I also haven't been= able to achieve that). Some ideas that you might find interesting. I have spent some time last year working on "traits containers" (https://gi= thub.com/AdaCore/ada-traits-containers for some code). The idea is to split= the large set of formal parameters you showed in your example into several= smaller sets, which are then passed via a signature package (aka traits). For instance, to implement your List_Item, we need to know a few things on = the container (but not its specific type), and how to iterate. To create th= e container, we need to know what elements it stores. This could lead to th= e following (untested) signature packages: generic type T (<>) is limited private; type Stored_T is private; with function Store (E : T) return Stored_T; with function Retrieve (E : Stored_T) return T; package Elements is end Elements; -- How to store elements in a data structure. If T is definite, we s= imply copy, but if -- if is indefinite, we need to allocate memory for instance. generic with package Elems is new Elements (<>); type Iterable (<>) is limited private; type Cursor is private; with function First (Self : Iterable) return Cursor; with function Next (C : Cursor) return Cursor; with function Get (C : Cursor) return Elems.T; package Iterables is end Iterables; generic with package Iterable is new Iterables (<>); -- A container is an iterable data structure, that we can also= modify with procedure Append (Self : in out Iterable.Iterable; E : Iter= able.Elems.T); package Containers is subtype Container is Iterable.Iterable; end Containers; Then if you create a specific container type (or wrap one of the predefined= Ada containers), you provide an instance of those predefined packages when= applicable. As shown above, although the signature packages themselves sho= uld contain any code, they can provide instances for other signature packag= es (think: in C++, a random-access cursor is also a forward cursor). Finally, your algorithm is generic in terms of those generic packages: generic with package Iterable is new Iterables (<>); function Image (Self : Iterable.Iterable) return String; It receives an object, for which it knows how to create a cursor and manipu= late that cursor. The instances of the signature packages we created above = are bricks, and your algorithm works in terms of those bricks. This is a promising scheme. In fact, the more such elementary bricks you ha= ve (one to describe how to store elements in other data structure, one to d= escribe iterables, one to describe hashables, ...) the more interesting it = becomes, since you can combine them in unexpected ways. BUT: my containers were using the GNAT 'Iterable' aspect, not the more comp= lex Ada iterators, and I did not find a way to describe via the generic par= ameters that a "for..of" loop would work on them.=20 This is related to your question, but unfortunately (and sorry) does not pr= ovide a solution. Emmanuel