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: Re: Traits and iterators Date: Wed, 8 Jun 2016 13:18:41 +0200 Organization: A noiseless patient Spider Message-ID: References: <7d9aaa87-1dd2-4432-a958-aaa98125a01f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 8 Jun 2016 11:19:31 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="df6c13c4617621ca1de5ec657b563bf1"; logging-data="10256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Gd2LVoRxpmUJ4tXwjtzTV" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 In-Reply-To: <7d9aaa87-1dd2-4432-a958-aaa98125a01f@googlegroups.com> Cancel-Lock: sha1:lWul8uWdcu4a4yJaXE0jbyRCLEU= Xref: news.eternal-september.org comp.lang.ada:30660 Date: 2016-06-08T13:18:41+02:00 List-Id: On 08/06/16 09:31, briot.emmanuel@gmail.com wrote: >> 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. > > > Indeed, this signature package allows you to write an explicit iteration loop, where > you manipulate cursors explicitly. I don't know, and I don't think it is doable, how to > pass a formal type and mention that it should be iterable in the sense of the "for..of" > loop. > That means that any generic algorithm we write will take the above Policy package, > but will not be able to use "for..of". That's a bit more work to write, but just as > efficient in the end, but perhaps a limitation in the language. Thanks for the confirmation. Sometimes I miss interfaces for these things in the language. Álex.