comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: smart pointer dangerous (no -> operator)
Date: Fri, 16 Jan 2009 13:16:22 -0800 (PST)
Date: 2009-01-16T13:16:22-08:00	[thread overview]
Message-ID: <8f16c403-4f55-4bc4-bab8-e2020792ad8d@e1g2000pra.googlegroups.com> (raw)
In-Reply-To: 20090116220816.81773601.tero.koskinen@iki.fi

On 16 Sty, 21:08, Tero Koskinen <tero.koski...@iki.fi> 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
>    type Element (<>) is limited private;
>    type Element_Access is access Element;
> package Smart_Pointer is
>    type Pointer is new Ada.Finalization.Controlled with private;
>    function Create (Object : Element_Access) return Pointer;
>
>    generic
>       with procedure Action (Object : in out Element) is <>;
>    procedure 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



  reply	other threads:[~2009-01-16 21:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-16 10:04 smart pointer dangerous (no -> operator) Oliver Kowalke
2009-01-16 11:09 ` Dmitry A. Kazakov
2009-01-16 11:42   ` Georg Bauhaus
2009-01-16 12:43     ` Dmitry A. Kazakov
2009-01-16 21:21     ` Maciej Sobczak
2009-01-17 19:07       ` Georg Bauhaus
2009-01-16 11:46   ` Oliver Kowalke
2009-01-16 12:45     ` Dmitry A. Kazakov
2009-01-17  0:43   ` Brian Drummond
2009-01-17  9:28     ` Dmitry A. Kazakov
2009-01-16 20:08 ` Tero Koskinen
2009-01-16 21:16   ` Maciej Sobczak [this message]
2009-01-18 12:21 ` Samuel Tardieu
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox