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-Google-Thread: 103376,6dcdd5b561500c28 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!e1g2000pra.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: smart pointer dangerous (no -> operator) Date: Fri, 16 Jan 2009 13:16:22 -0800 (PST) Organization: http://groups.google.com Message-ID: <8f16c403-4f55-4bc4-bab8-e2020792ad8d@e1g2000pra.googlegroups.com> References: <20090116220816.81773601.tero.koskinen@iki.fi> NNTP-Posting-Host: 83.76.207.254 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1232140582 24563 127.0.0.1 (16 Jan 2009 21:16:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 16 Jan 2009 21:16:22 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: e1g2000pra.googlegroups.com; posting-host=83.76.207.254; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:3398 Date: 2009-01-16T13:16:22-08:00 List-Id: On 16 Sty, 21:08, Tero Koskinen wrote: > If you want to manipulate the original object behind the smart pointer > without using access types, you can use generics (or access to procedure)= : > > generic > =A0 =A0type Element (<>) is limited private; > =A0 =A0type Element_Access is access Element; > package Smart_Pointer is > =A0 =A0type Pointer is new Ada.Finalization.Controlled with private; > =A0 =A0function Create (Object : Element_Access) return Pointer; > > =A0 =A0generic > =A0 =A0 =A0 with procedure Action (Object : in out Element) is <>; > =A0 =A0procedure Update (Pointer_Object : Pointer); I was thinking rather about something similar in spirit to Update_Element/Query_Element in Ada.Containers.Vector. One generic less -> easier to use. Actually, it all comes with analogy. There is no indexing operator in Vector (I mean - nothing like operator[] in C++, which returns a reference to contained element), which is exactly the same kind of problem as the lack of dereference in smart pointers. If the problems are similar, why not go for similar solutions? This, however, brings important question: what about performance? Is it common for the compilers to inline such constructs (calls with callbacks to local subprograms)? -- Maciej Sobczak * www.msobczak.com * www.inspirel.com Database Access Library for Ada: www.inspirel.com/soci-ada