comp.lang.ada
 help / color / mirror / Atom feed
* Generics and selection based on type
@ 2007-01-12 16:24 Maciej Sobczak
  2007-01-12 21:43 ` Björn Persson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Maciej Sobczak @ 2007-01-12 16:24 UTC (permalink / raw)


Hi,

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

generic
   type T is ...
function To_String(X : T) return String;

I want to use it this way:

function Int_To_String is new To_String(Integer);
function Positive_To_String is new To_String(Positive);
function Float_To_String is new To_String(Float);
function Identity is new To_String(String);

So that:

Int_To_String(7) = "7";
Positive_To_String(5) = "5";
Float_To_String(3.14) = "3.14";
Identity("Hello") = "Hello";

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?

-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-01-13  9:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-12 16:24 Generics and selection based on type Maciej Sobczak
2007-01-12 21:43 ` Björn Persson
2007-01-12 21:50 ` Jeffrey R. Carter
2007-01-13  9:14 ` Dmitry A. Kazakov

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