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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,43b6c5f649185450 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-03 21:39:34 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc54.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: generic type identification References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 12.234.13.56 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc54 1041658774 12.234.13.56 (Sat, 04 Jan 2003 05:39:34 GMT) NNTP-Posting-Date: Sat, 04 Jan 2003 05:39:34 GMT Organization: AT&T Broadband Date: Sat, 04 Jan 2003 05:39:34 GMT Xref: archiver1.google.com comp.lang.ada:32516 Date: 2003-01-04T05:39:34+00:00 List-Id: > generic > type New_Type is range <>; > Is it possible to identify the type of New_Type in the Some_Procedure > procedure? Suppose: type Snowmans_Pleasant_Farenheit is range 18 .. 24; type My_Pleasant_Centigrade is range 18 .. 24; package My_Procedure is new Example.Some_Procedure(My_Pleasant_Centigrade); How could your Some_Procedure tell whether it was instantiated with Farenheit or Centigrade temperatures, especially since the code that instantiates it, and the two temperature "types", may not have even existed when you wrote your package Example? > Another thing that I couldn't find an answer to, is it possible to constrain > the allowed generic types. Like specifying that New_Type has to be either > Integer or Float? > generic > type New_Type is range <>; type Other_Type is digits <>; New_Type is a signed integer of some sort. (Perhaps My_Pleasant_Centigrade) Other_Type is some kind of floating point type. And there are other notations for modular, fixed, private, discrete, etc. > The alternative, I guess, would be to not use a generic package and instead > overload Some_Procedure with those types that I want to be able to use but > this will clutter the specification file =(. Not to mention that you will have to add to package Example every time someone wants to use your Some_Procedure with a new type. Why do you want Some_Procedure to know what type it was instantiated with? How much does it need to know about that type - just whether it's integer or float or modular, or does it need to know whether it's My_Pleasant_Centigrade or not?