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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,96daa6f775bc14b9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-07-02 11:43:18 PST Path: archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!enst!enst.fr!not-for-mail From: "Beard, Frank" Newsgroups: comp.lang.ada Subject: RE: Generics??? Date: Mon, 2 Jul 2001 14:42:19 -0400 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C10326.B9CA4FAE" X-Trace: avanie.enst.fr 994099396 81229 137.194.161.2 (2 Jul 2001 18:43:16 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Mon, 2 Jul 2001 18:43:16 +0000 (UTC) To: "'comp.lang.ada@ada.eu.org'" Return-Path: X-Mailer: Internet Mail Service (5.5.2448.0) Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.4 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:9343 Date: 2001-07-02T14:42:19-04:00 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C10326.B9CA4FAE Content-Type: text/plain; charset="iso-8859-1" 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 ------_=_NextPart_000_01C10326.B9CA4FAE Content-Type: application/octet-stream; name="GenericOperations.ads" Content-Disposition: attachment; filename="GenericOperations.ads" generic type Item is private; with function "+" (the_Left, the_Right : Item) return Item; with function "-" (the_Left, the_Right : Item) return Item; with function "*" (the_Left, the_Right : Item) return Item; with function "/" (the_Left, the_Right : Item) return Item; package GenericOperations is function Add (the_Left : Item; the_Right : Item) return Item; function Subtract (the_Left : Item; the_Right : Item) return Item; function Multiply (the_Left : Item; the_Right : Item) return Item; function Divide (the_Left : Item; the_Right : Item) return Item; end GenericOperations; ------_=_NextPart_000_01C10326.B9CA4FAE Content-Type: application/octet-stream; name="GenericOperations.adb" Content-Disposition: attachment; filename="GenericOperations.adb" package body GenericOperations is function Add (the_Left : Item; the_Right : Item) return Item is begin return the_Left + the_Right; end Add; function Subtract (the_Left : Item; the_Right : Item) return Item is begin return the_Left - the_Right; end Subtract; function Multiply (the_Left : Item; the_Right : Item) return Item is begin return the_Left * the_Right; end Multiply; function Divide (the_Left : Item; the_Right : Item) return Item is begin return the_Left / the_Right; end Divide; end GenericOperations; ------_=_NextPart_000_01C10326.B9CA4FAE Content-Type: application/octet-stream; name="GenericOperationsTest.ada" Content-Disposition: attachment; filename="GenericOperationsTest.ada" with Ada.Text_Io; with GenericOperations; procedure GenericOperationsTest is package FloatOperations is new GenericOperations(Item => float, "+" => "+", "-" => "-", "*" => "*", "/" => "/"); x : float := 10.0; y : float := 2.0; char : character := ' '; begin Ada.Text_Io.New_Line(2); Ada.Text_Io.Put_Line("Add => " & float'image(FloatOperations.Add(x,y))); Ada.Text_Io.Put_Line("Subtract => " & float'image(FloatOperations.Subtract(x,y))); Ada.Text_Io.Put_Line("Multiply => " & float'image(FloatOperations.Multiply(x,y))); Ada.Text_Io.Put_Line("Divide => " & float'image(FloatOperations.Divide(x,y))); Ada.Text_Io.New_Line(2); Ada.Text_Io.Put("Hit any key ..."); Ada.Text_Io.Get_Immediate(char); end GenericOperationsTest; ------_=_NextPart_000_01C10326.B9CA4FAE--