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,70414f56d810c10c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.25.163 with SMTP id d3mr468319pbg.7.1316279982369; Sat, 17 Sep 2011 10:19:42 -0700 (PDT) Path: m9ni8355pbd.0!nntp.google.com!news1.google.com!goblin3!goblin1!goblin.stu.neva.ru!news.astraweb.com!border1.a.newsrouter.astraweb.com!multikabel.net!newsfeed10.multikabel.net!feeder.news-service.com!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: discriminant questions Date: Sat, 17 Sep 2011 19:19:40 +0200 Organization: cbb software GmbH Message-ID: References: <9f37b726-d80b-4d24-bf3f-28a14255f7fd@s20g2000yql.googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: v1unXtVHH3OmHkxoJWmV2g.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news1.google.com comp.lang.ada:18004 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2011-09-17T19:19:40+02:00 List-Id: On Sat, 17 Sep 2011 09:30:46 -0700 (PDT), ytomino wrote: > I would like to write smart pointer and make that it is able to assign- > able type, as follows: > > declare > a : the_smart_pointer (element => wrap (new Integer'(100))); > b : the_smart_pointer (element => wrap (new Integer'(200))); > begin > a.element.all.all := 300; -- a.all := 300; (if compiler supported > Implicit_Dereference) > b := a; -- it frees element of b on Finalize and add reference > count of a on Assign > end; Given: with Object.Handle; type Integer_Object is new Object.Entity with record Value : Integer; end record; type Integer_Object_Ptr is access Integer_Object'Class; package Integer_Handles is new Object.Handle (Integer_Object, Integer_Object_Ptr); use Integer_Handles; function Wrap (Value : Integer) return Handle is begin return Ref (new Integer_Object'(Object.Entity with Value)); end Wrap; You write: use Integer_Handles; A : Handle := Wrap (100); B : Handle := Wrap (200); begin A.Ptr.Value := 300; B := A; -- Frees B.Ptr, increases the count of A.Ptr For the sample sources see: http://www.dmitry-kazakov.de/ada/components.htm#Objects_etc -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de