comp.lang.ada
 help / color / mirror / Atom feed
From: briot.emmanuel@gmail.com
Subject: Re: Iterable container as generic parameter
Date: Fri, 26 Jan 2018 01:09:20 -0800 (PST)
Date: 2018-01-26T01:09:20-08:00	[thread overview]
Message-ID: <3af9cfc4-d434-4d60-a4ed-17a16f75717f@googlegroups.com> (raw)
In-Reply-To: <p4ec3b$ai2$1@franka.jacob-sparre.dk>

> But I probably would just use your original spec and add the container type 
> and iterator function, something like:
> 
> generic
>    type Cursor is (<>);
>    with function Image (C : Cursor) return String;
>    type Container (<>) is private;
>    with package Iterator_Interfaces is
>      new Ada.Iterator_Interfaces (Cursor, others => <>);
>    with function Iterator (C : Container) return 
> Iterator_Interfaces.Forward_Iterator'Class;
> function List_Image return String;
> 

I think that's a good starting point.
When this works, and if you have a similar need for another algorithm, then you can start thinking of signature packages and introduce some of them.

I started my work on the traits containers when I wanted to write algorithms that would work for any of the standard containers (later on I realized that those containers, at least in the GNAT implementation) had a lot of duplicate code between definite/indefinite variants, that could be factored away with an Elements traits package, so I introduced that. And so on.

I definitely agree with Randy here that we should not construct signature packages in the abstract, but start from existing and working code.

The only drawback is that introducing them breaks the existing API:
    - instantiating the generic now uses different set of formals.
       We have proposed http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai12s/ai12-0205-1.txt?rev=1.2&raw=N for the next revision of the language, which might help a little

   - moving out some code out of an existing package and into a generic means you need to introduce a lot of renamings to preserve existing API.
      We have proposed http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai12s/ai12-0229-1.txt?rev=1.3&raw=N to help.

I recently made changes to GNATCOLL so that people could chose which kind of reference counting they want to use for GNATCOLL.Strings. Either no counter (in which case we don't do copy-on-write), non-atomic counters or atomic counters. This could only be done via a signature package, since declaring a type with aspect "Atomic" generates some memory fence operations which are slow. That leads to a 3 to 4% speed improvement. Just another example of possible signature package.

Emmanuel


  reply	other threads:[~2018-01-26  9:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-25  0:22 Iterable container as generic parameter Lionel Draghi
2018-01-25  3:36 ` 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 [this message]
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