comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <no.spam@no.spam.com>
Subject: Generics and selection based on type
Date: Fri, 12 Jan 2007 17:24:44 +0100
Date: 2007-01-12T17:24:44+01:00	[thread overview]
Message-ID: <eo8coc$kjc$1@cernne03.cern.ch> (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/



             reply	other threads:[~2007-01-12 16:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-12 16:24 Maciej Sobczak [this message]
2007-01-12 21:43 ` Generics and selection based on type Björn Persson
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