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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6dcdd5b561500c28 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!cyclone1.gnilink.net!gnilink.net!nx01.iad.newshosting.com!newshosting.com!zen.net.uk!demorgan.zen.co.uk!news2.euro.net!multikabel.net!newsfeed20.multikabel.net!eweka.nl!lightspeed.eweka.nl!npeer.de.kpn-eurorings.net!npeer-ng1.de.kpn-eurorings.net!npeer-ng2.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: smart pointer dangerous (no -> operator) Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <6j22n4ll4932l07nqc1c8d5q5rubrj9c3a@4ax.com> Date: Sat, 17 Jan 2009 10:28:01 +0100 Message-ID: <138mfqjaug7ie.c1nu0yulmks7.dlg@40tude.net> NNTP-Posting-Date: 17 Jan 2009 10:28:02 CET NNTP-Posting-Host: 2b03817d.newsspool2.arcor-online.net X-Trace: DXC=7XRDGQA3RoSYQ5E:lab_9hBh;kKD?SP X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:4376 Date: 2009-01-17T10:28:02+01:00 List-Id: On Sat, 17 Jan 2009 00:43:17 +0000, Brian Drummond wrote: > On Fri, 16 Jan 2009 12:09:16 +0100, "Dmitry A. Kazakov" > wrote: > >>1. In Ada 95 I declare the proxy type tagged controlled. The handle is >>created through a instantiation in the private part of the generic package >>Handle: >> >> type X_Handle is new Ada.Finalization.Controlled with private; >> -- Repeat all operations of the target >> procedure Foo (Object : X_Handle); >> ... -- and so on >>private >> package Handles is not Object.Handle (...); -- Instantiation >> type X_Handle is new Handles.Handle with null record; >> >>The implementation of Foo goes as follows: >> >> procedure Foo (Object : X_Handle) is >> begin >> Foo (Ptr (Object).all); >> end Foo; >> >>this is extremely tedious, but the best way I know. > > As an Ada newbie, I've probably lost track of something important, but > I can't see a reason not to create a generic procedure, and simply > instantiate it for each Foo, which would be slightly less boring if it > worked.. I am not sure what you mean. To have a generic subprogram in addition to each primitive operation of the target type? That would be even more boring. The problem is: You have a target type: type T is ...; procedure Foo (X : T); function Bar return T; procedure Baz (X : T; Y : in out T; Z : Float); ... Now you want to create a type T_Handle which would in its implementation Ada.Finalization.Controlled with a pointer to an instance of T and all operations of T delegated to the pointer's target: type T_Handle is Ada.Finalization.Controlled with private; procedure Foo (X : T_Handle); function Bar return T_Handle; procedure Baz (X : T_Handle; Y : in out T_Handle; Z : Float); ... Generics do not solve that. What does is delegation + interface inheritance from concrete type (T). Ada has neither. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de