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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a6b:6d19:: with SMTP id a25-v6mr1372971iod.16.1528294700182; Wed, 06 Jun 2018 07:18:20 -0700 (PDT) X-Received: by 2002:a9d:740d:: with SMTP id n13-v6mr128656otk.12.1528294700068; Wed, 06 Jun 2018 07:18:20 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!v8-v6no1919387itc.0!news-out.google.com!f20-v6ni2233itd.0!nntp.google.com!u74-v6no1910906itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 6 Jun 2018 07:18:19 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2400:416e:1ba5:1200:5cfd:2e60:57e1:ef5b; posting-account=Mi71UQoAAACnFhXo1NVxPlurinchtkIj NNTP-Posting-Host: 2400:416e:1ba5:1200:5cfd:2e60:57e1:ef5b References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Generic formal type with 'Image From: ytomino Injection-Date: Wed, 06 Jun 2018 14:18:20 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:52956 Date: 2018-06-06T07:18:19-07:00 List-Id: On Wednesday, June 6, 2018 at 10:03:24 PM UTC+9, Alejandro R. Mosteo wrote: > I'm pretty sure the answer is "no", but just in case: > > Is there a formal for a generic that serves for any type that has a > predefined 'Image? > > The purpose is to avoid: > > generic > type Printable is ... -- What should go here? > with function Image (P : Printable) return String is <>; > package > > and then have to pass the 'Image attribute as the Image function in all > instantiations. > > The closest thing I can think of is (<>) but that won't do for floating > point types. > > I understand this is an unusually narrow case (I need a generic for many > numeric types, both discrete and floating, and this would save me some > typing -- that I have already spent here anyway.) > > With these issues I feel a kind of overlap/missed connection between > attributes and interfaces. > > Thanks, > Alex. If AI12-0020-1 (http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai12s/ai12-0020-1.txt?rev=1.7&raw=N) is adopted, 'Image will be able to be used in anywhere. As the available but unrecommended solution, there is GNAT's Type_Class attribute. generic type Printable is private; package P is procedure Print (Item : Printable); end P; package body P is procedure Print (Item : Printable) is begin case Printable'Type_Class is when Type_Class_Floating_Point => -- We have to convert from the formal private type to some float type, with some dirty hack. -- This is the case of using streams: Printable'Write (temporary-stream, Item); Set_Index (temporary-stream, 1); case Printable_Type'Stream_Size is when Float'Stream_Size => Float'Read (temporary-stream, Float_Var); when Long_Float'Stream_Size => Long_Float'Read (temporary-stream, Long_Float_Var); ... Or, as disappointing answer, we have to write normally. generic type Printable is private; with function Image (P : Printable) return String is <>; with function "+" (Left, Right : Printable) return Printable is <>; -- Maybe you need "-", "*", "/", "<", "<=", Zero, One, etc package