comp.lang.ada
 help / color / mirror / Atom feed
From: "Björn Persson" <spam-away@nowhere.nil>
Subject: Re: Generics and selection based on type
Date: Fri, 12 Jan 2007 21:43:57 GMT
Date: 2007-01-12T21:43:57+00:00	[thread overview]
Message-ID: <xiTph.28964$E02.11872@newsb.telia.net> (raw)
In-Reply-To: eo8coc$kjc$1@cernne03.cern.ch

Maciej Sobczak wrote:

> I would like to write a generic function that returns the string
> representation of its parameter, which can be a number or a string.

[...]

> For this, it would be good to be able to select the implementation of
> To_String based on what the type is. If it's numeric - the 'Image
> attribute can be used. If it's already String - just return the
> argument. And so on.
> 
> Is it possible?

I think that's impossible. You can only do things with the parameter that
you can do with all types that the generic function can be instantiated
with. I also don't see the point. Why don't you simply write a set of
overloaded functions? It won't take more work or more code, as you'll have
to write all the different implementations either way. Generics are for
cases where you can use the same implementation for different types.

-- 
Bj�rn Persson                              PGP key A88682FD
                   omb jor ers @sv ge.
                   r o.b n.p son eri nu



  reply	other threads:[~2007-01-12 21:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-12 16:24 Generics and selection based on type Maciej Sobczak
2007-01-12 21:43 ` Björn Persson [this message]
2007-01-12 21:50 ` Jeffrey R. Carter
2007-01-13  9:14 ` Dmitry A. Kazakov
replies disabled

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