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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "Alejandro R. Mosteo" Newsgroups: comp.lang.ada Subject: Traits and iterators (was: Mixing operators and dot notation) Date: Tue, 7 Jun 2016 13:24:33 +0200 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 7 Jun 2016 11:24:34 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="df6c13c4617621ca1de5ec657b563bf1"; logging-data="24147"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fZYK9rR2iElDjYtjvP2QE" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 In-Reply-To: Cancel-Lock: sha1:wKdQSHirCBb0Gqc2zAxqU22fBew= Xref: news.eternal-september.org comp.lang.ada:30645 Date: 2016-06-07T13:24:33+02:00 List-Id: On 06/06/16 10:14, briot.emmanuel@gmail.com wrote: > We are working on a containers library using this, so that algorithms, for instance, > can be made independent of containers, and that users can configure a lot of the > behavior of containers (checks or not, bounded or not, definite or indefine > elements) by the proper usage of formal package parameters. > See https://github.com/AdaCore/ada-traits-containers if you want more info. I've now been going over the documentation and it is very good. It clarifies a lot of things that were still a bit muddy in my head. A question arises (actually a lot of them, sorry for not being clearer since I'm lacking the final grasp): if one wants to receive via generics a type to which the "of" operator can be applied, what would be the minimal signature? Is it doable? I understand the compiler recognizes such types from the aspects in the type declaration (I'm looking at Doubly_Linked_Lists for example) so... should the type be descended from some other type having the aspects? This example, IIUC, says that: http://www.adacore.com/adaanswers/gems/gem-128-iterators-in-ada-2012-part-2/ OTOH, I see the example for the traits containers given as: generic with package Elements is new Elements_Policy (<>); type Container is private; type Cursor is private; with function First (Self : Container) return Cursor is <>; with function Has_Element (Self : Container; C : Cursor) return Boolean is <>; with function Element (C : Cursor) return Elements.Element is <>; with procedure Next (C : in out Cursor) is <>; package Forward_Cursors_Policy is end Forward_Cursors_Policy; That, in itself, I don't think will give the ability to use "of" in iterations, although it enables one to iterate over an unknown type. I guess what I'm asking for is what's the simplest way to say that some type is "iterable", in the "of"-applicability sense, via generics. Another my guess is that, from a Cursors policy package, one could have a wrapper type with the proper aspects declared using these subprograms. Sorry for the barrage of not very clear questions/musings. Thanks, Álex.