comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <nholsti@icon.fi>
Subject: Re: attributes in generic procedure
Date: 1999/11/29
Date: 1999-11-29T00:00:00+00:00	[thread overview]
Message-ID: <3841CE51.862ACED3@icon.fi> (raw)
In-Reply-To: 383DC78E.63A556E5@callnetuk.com

Nick Roberts wrote:
> 
> daelen@my-deja.com wrote:
> >
> > I would like to create a generic procedure as shown below which will only be
> > used for scalar types. Does anybody have a hint how to accomplish this?
> >
> > generic
> >    type A_Type is private;
> > ...
> > end Update;
> 
> The answer is simple:
> 
>    generic
>       type A_Type is (<>);
>    ...

According to RM 12.5.2, this is a formal discrete type definition,
not a formal scalar type definition. This means that it allows only
enumeration and integer types, but not real types (3.2(3)).

In fact, there is no formal_scalar_definition in the RM. I, too, would
have liked to have one when I recently wrote a generic function to
take the maximum value of a vector of some generic element type.
The Max function needs only the attributes 'first and 'max, which
exist for all scalar types, but different generic functions are
needed for a discrete element type and a real element type, although
the bodies of the two functions are identical. One can of course work
around this by making 'first and 'max be additional generic formal
parameters, instead of using type attributes, but it is a little messy.

I don't know if it's worthwhile to consider adding a formal scalar
class to Ada. It might be difficult for compilers that share generic
code across instantiations 

Niklas Holsti
Working at but not speaking for Space Systems Finland Ltd.




  reply	other threads:[~1999-11-29  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-21  0:00 attributes in generic procedure daelen
1999-11-21  0:00 ` Matthew Heaney
1999-11-25  0:00 ` Nick Roberts
1999-11-29  0:00   ` Niklas Holsti [this message]
1999-11-29  0:00     ` Robert Dewar
1999-12-03  0:00       ` Nick Roberts
replies disabled

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