comp.lang.ada
 help / color / mirror / Atom feed
Subject: Re: Generic formal access types
Date: Thu, 01 May 2003 10:58:35 +0200
Date: 2003-05-01T10:58:35+02:00	[thread overview]
Message-ID: <3eb0e1be$1@epflnews.epfl.ch> (raw)
In-Reply-To: x7vllxrlra3.fsf@smaug.pushface.org

Simon Wright wrote:
> Rodrigo Garc�a <rodrigo.garcia.ARROBA.epfl.ch> writes:
> 
> 
>>Does anybody know why Ada does not have something like:
>>
>>generic
>>    type Access_Type is access (<>);  --  ?
>>
>>I would like to specify in a generic package that it should be
>>instantiated by an access type, no matter what type it is pointing
>>to.
>>
>>Ok, it is not very useful to have an access type if you do not know
>>its content, but the package implements a list and I am just storing
>>them. I "need" that because I want to return the value "null" from a
>>function in the generic package that returns "Access_Type".
>>
>>There is a possible workaround:
>>
>>generic
>>    type Element is (<>);
>>    type Access_Type is access Element;
>>
>>But I do not like it because it forces me to pass also the "Element"
>>in the instantiation.
> 
> 
> I think 'type Element is limited private' would be better (I can't
> rememer if you can allow it to be unconstrained as well, 'type Element
> (<>) is limited private' ... GNAT is happy).

Sorry, I meant:

generic
    type Elment (<>) is private;
    --  Yes, (<>) allows Element to be unconstrained.
    type Access_Type is access Element;

But the "problem" is still there. I have to pass an actual "Element" as 
well as an actual "Access_Type" when I instantiate the generic package. 
I would like to only pass the "Access_Type".

> I can understand why a formal type has to be tagged for you to declare
> it abstract, you would have thought a private constraint { (<>) }
> would have been a possibility here ..

You are probably right, but I am not dealing with tagged types here. My 
problem is much simpler.

> There's no way I can see that you can instantiate a generic with an
> access-to-subprogram, but I'm not sure that the uses would be worth
> the trouble!

Hmmm... I was not thinking of that either. Just access to objects by 
now.  :^)

Rodrigo




  reply	other threads:[~2003-05-01  8:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-30 18:30 Generic formal access types 
2003-04-30 19:27 ` Simon Wright
2003-05-01  8:58   `  [this message]
2003-04-30 21:42 ` Chad R. Meiners
2003-05-01  9:06   ` 
2003-05-01  9:58     ` Martin Krischik
2003-05-01 13:00       ` 
2003-05-02  9:14         ` Ludovic Brenta
2003-05-02 10:43           ` 
2003-05-02 10:50             ` 
2003-05-01 10:09     ` 
2003-05-02  1:14 ` tmoran
2003-05-02  9:52   ` 
2003-05-02 16:18     ` tmoran
2003-05-02 16:57       ` Robert A Duff
2003-05-02 19:39         ` Randy Brukardt
2003-05-05  8:14         ` 
2003-05-05 16:40         ` Matthew Heaney
2003-05-05 17:34           ` Robert A Duff
replies disabled

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