From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,81e608b9d333eaff,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Generics and selection based on type Date: Fri, 12 Jan 2007 17:24:44 +0100 Organization: CERN News Message-ID: NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Trace: cernne03.cern.ch 1168619084 21100 137.138.37.241 (12 Jan 2007 16:24:44 GMT) X-Complaints-To: news@@cern.ch NNTP-Posting-Date: Fri, 12 Jan 2007 16:24:44 +0000 (UTC) User-Agent: Thunderbird 1.5.0.9 (X11/20061220) Xref: g2news2.google.com comp.lang.ada:8119 Date: 2007-01-12T17:24:44+01:00 List-Id: 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/