comp.lang.ada
 help / color / mirror / Atom feed
From: "Alejandro R. Mosteo" <alejandro@mosteo.com>
Subject: Traits and iterators (was: Mixing operators and dot notation)
Date: Tue, 7 Jun 2016 13:24:33 +0200
Date: 2016-06-07T13:24:33+02:00	[thread overview]
Message-ID: <nj6ati$nij$1@dont-email.me> (raw)
In-Reply-To: <fe0d3b8d-0849-42ff-8b94-65fdff9c42ea@googlegroups.com>

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.

  parent reply	other threads:[~2016-06-07 11:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-02 21:38 Mixing operators and dot notation Alejandro R. Mosteo
2016-06-02 21:42 ` Alejandro R. Mosteo
2016-06-02 22:28 ` Robert A Duff
2016-06-02 23:26   ` Randy Brukardt
2016-06-03 11:09     ` Alejandro R. Mosteo
2016-06-03 12:19       ` Dmitry A. Kazakov
2016-06-03 14:45       ` G.B.
2016-06-03 17:31       ` Shark8
2016-06-03 20:41         ` Alejandro R. Mosteo
2016-06-06  8:14           ` briot.emmanuel
2016-06-06 13:51             ` Alejandro R. Mosteo
2016-06-07 11:24             ` Alejandro R. Mosteo [this message]
2016-06-08  7:31               ` Traits and iterators (was: Mixing operators and dot notation) briot.emmanuel
2016-06-08 11:18                 ` Traits and iterators Alejandro R. Mosteo
2016-06-06  8:10       ` Mixing operators and dot notation briot.emmanuel
2016-06-06 13:58         ` Alejandro R. Mosteo
2016-06-02 23:05 ` Jeffrey R. Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox