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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!news3.google.com!feeder.news-service.com!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!xlned.com!feeder1.xlned.com!newsfeed-fusi2.netcologne.de!195.14.215.230.MISMATCH!news.netcologne.de!newsfeed-hp2.netcologne.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 16 Jan 2009 12:42:17 +0100 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: smart pointer dangerous (no -> operator) References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <49707299$0$32667$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 16 Jan 2009 12:42:17 CET NNTP-Posting-Host: 830d7db7.newsspool2.arcor-online.net X-Trace: DXC=5W6a>Q;EZ\DlU`@c^jLCbJA9EHlD;3YcB4Fo<]lROoRA^YC2XCjHcbI@3CKQ\5Q69A;9OJDO8_SKFNSZ1n^B98iJTY Dmitry A. Kazakov schrieb: > On Fri, 16 Jan 2009 11:04:57 +0100, Oliver Kowalke wrote: > >> Ada doesn't support the dereference operator -> as C++. >> >> So Ada provides only two ways to access the managed object? > Two major problems > are: > > 1. Lack of delegation in order to automate generation of wrappers like Foo. > 2. Lack of MI, because one base type is required and used further extension > of the target type becomes practically impossible. Frequently overlooked, I think, Ada has nested scopes, useful in many ways here. (Except, perhaps, if reuse is only be perceived to be possible with flat library level compiled brick stone, and not by reusing source code and some programming...) 1 - Ownership of objects can be strictly confined in scopes. 2 - Types can be declared where they are needed. See 1. 3 - Finalization is performed when a scope ends. These may not directly address the original question, but why design a program around C++ imported hindrances, if you will? with Ada.Finalization, Ada.Text_IO; procedure Scoped_Pointer is procedure Local is -- architectural unit type T is new Ada.Finalization.Controlled with record Data: Character; end record; overriding procedure Finalize(Object: in out T) is begin Ada.Text_IO.Put_Line("F!"); end Finalize; procedure Next(Item: in out T) is -- may raise begin Item.Data := Character'Val (Natural'Succ(Character'Pos(Item.Data))); end Next; -- Pointer whose objects do not exist outside Local: type T_Ptr is access T; X: T_Ptr; begin -- Local X := new T'(Ada.Finalization.Controlled with Data => '*'); loop Next(X.all); -- passed by reference; raises end loop; end Local; begin -- Local.T does not exist Local; -- Local.T does not exist, neither does Local.X.all, -- as it has been finalized automatically. end Scoped_Pointer;