comp.lang.ada
 help / color / mirror / Atom feed
From: "Anders Wirzenius" <anders.wirzenius@pp.qnet.fi>
Subject: Re: Generics???
Date: Tue, 03 Jul 2001 10:32:24 GMT
Date: 2001-07-03T10:32:24+00:00	[thread overview]
Message-ID: <Yah07.80$Qb2.6962@read2.inet.fi> (raw)
In-Reply-To: mailman.994099384.29806.comp.lang.ada@ada.eu.org


Beard, Frank wrote in message ...
>You can do it as a private, but you have to pass in the operations.
>Attached is an example of what I'm talking about.  Is this what
>you're after?
>
>Frank
>
>
>-----Original Message-----
>From: Michael Andersson [mailto:a98mican@ida.his.se]
>
>Hi!
>How do I specify that the generic parameter is a integer or a float. I
>know that you can use
>type T is range <> to specify that T is any Integer-type and that you
>can use type T is digit <> to specify that T is any type of float. But
>how can I use both at the same time?
>I've tried to use type T is private but then I can't use any of the
>+,-,*,/ operators.
>
>Need your help, please!
>/Michael Andersson
>_______________________________________________
>comp.lang.ada mailing list
>comp.lang.ada@ada.eu.org
>http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
>

May I join the thread with an additional question:
Suppose I use the example provided by Frank Beard and want to round up the
result when the type is an integer.
How do I test which type the parameter (in the example: Item) is?
Something like the pseudocode:

   function Divide (the_Left  : Item;
                    the_Right : Item) return Item is
   begin
      case Item is
         when  integer =>
            round up;
         when  float =>
            just divide ;
         when others =>
            null;
      end case;
      return result of division;
   end Divide;

Anders Wirzenius





  reply	other threads:[~2001-07-03 10:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-02 18:42 Generics??? Beard, Frank
2001-07-03 10:32 ` Anders Wirzenius [this message]
2001-07-03 17:31   ` Generics??? Stephen Leake
2001-07-03 19:09   ` Generics??? tmoran
2001-07-04  5:30     ` Generics??? Anders Wirzenius
  -- strict thread matches above, loose matches on Subject: below --
2001-07-02 22:33 Generics??? Michael Andersson
2001-07-02 17:48 ` Generics??? James Rogers
2001-07-02 18:54   ` Generics??? Ehud Lamm
1992-09-14 15:00 Generics? cis.ohio-state.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!jvnc.net!net
1992-09-09  5:26 Generics? Andrew Dunstan
1992-09-09  1:34 Generics?  Rob Allen
replies disabled

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