comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Generic type parameters
Date: 1999/06/15
Date: 1999-06-15T00:00:00+00:00	[thread overview]
Message-ID: <m37lp6cm5h.fsf@mheaney.ni.net> (raw)
In-Reply-To: 7k3ae5$stk$1@nnrp1.deja.com

On 14 Jun 1999 16:25, dommo1234@my-deja.com wrote:

> generic
>     type TypeX is private;
> package Example is
>     function One(..) return TypeX;
>     function Two(..) return TypeX_A;
>     function Three(..) return TypeX_AC;
> end Example;
> 
> ... where 'TypeX_A' needs to be "access all TypeX"
>     and   'TypeX_AC' needs to be "access constant TypeX".
> 
> The problem is that if I delcare the two types 'TypeX_A' and 'TypeX_AC'
> inside the generic, then any code containing variables that catch the
> values of functions 'Two' and 'Threee' inside my generic must be of type
> <generic inst>.Type_A etc. This is not very readable or convenient!
> 
> The only (not so sensible) solution I can think of is provide the
> generic with 3 formal parameters, ie. TypeX, TypeX_A and TypeX_AC ....
> 
> Does anyone have a neater solution to this??


I don't know about "neater," but you can create another generic package
in which to declare the access types, and import an instantiation of
that package as a generic formal package:

generic
  type TypeX is private;
package TypeX_Access_Types_G is

  type TypeX_A is access all TypeX;

  type TypeX_AC is access constant TypeX;

end;


with TypeX_Access_Types_G;

generic

  with package TypeX_Access_Types is
    new TypeX_Access_Types_G (<>);

  use TypeX_Access_Types;

package Example is

  <as above>

end;





  




  reply	other threads:[~1999-06-15  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-14  0:00 Generic type parameters dommo1234
1999-06-15  0:00 ` Matthew Heaney [this message]
1999-06-15  0:00   ` dommo1234
replies disabled

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