comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Amount of copying on returned constant objects
Date: Tue, 19 Jun 2007 10:26:38 +0200
Date: 2007-06-19T10:23:50+02:00	[thread overview]
Message-ID: <hp1l1z4lxqgd.awjqgpudndp5.dlg@40tude.net> (raw)
In-Reply-To: f56pjg$nlr$1@jacob-sparre.dk

On Mon, 18 Jun 2007 15:25:33 -0500, Randy Brukardt wrote:

> "Pascal Obry" <pascal@obry.net> wrote in message
> news:4676C27D.2050608@obry.net...

>> Or in a more Ada 2005 way:
>>
>>    function Element
>>      (Key : Key_Type) return access constant Element_Type;
> 
> That's
> why the containers access-in-place routines use access-to-subprograms,
> because they can have tampering checks that prevent the dangling access
> problem (you get Program_Error if you try to do something that could make
> the element inaccessible). That makes them much safer than returning a raw
> pointer.

In Ada, which has no procedural types closure itself is a problem because
an access type is still there (now to the procedure). Further, this
approach does not work if we needed to access several elements of the same
or different containers. How to do this:

   (Get (A, First (A)) + Get (A, Last (A))) / 2;

with closures in a more or less readable form?

> Dmitry might (will?) tell us that a user-defined ".all" operation would do
> the trick, but it's not obvious how to define that operation so that the
> ".all" definition itself would not expose the original problem.

Well, for all, there is a problem of complexity introduced by each new type
here. There is a type of the container, there are types of the element and
the index. That's already triply dispatching in the most general case.
[Actually, it is far more if ranges and other subsets of index are
introduced] I don't want yet another type of the access to element, or a
type of the procedure to access to the element etc. It is a mess when the
container gets derived from. We have no any language mechanism to bind all
these geometrically exploding combinations of types together.

BTW, which problem we are talking about. There are at least two:

1. An "easy" one is Alex's example:

   if Container.Element (Key).Is_Nice then

What he actually needs here is to force the compiler to infer from
Element's Is_Nice a new container operation:

   if Is_Nice (Container, Key) then

composed out of container's Element and element's Is_Nice.

2. A difficult one:

   declare
      X : Item renames Get (Container, Key_1);
      Y : Item renames Get (Container, Key_2);
   begin
      Remove (Container, From => Key_3, To => Key_4);
      X := Y;
   end; -- This must be safe and efficient

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2007-06-19  8:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-15 16:19 Amount of copying on returned constant objects Alex R. Mosteo
2007-06-15 16:32 ` Ludovic Brenta
2007-06-18 17:26   ` Alex R. Mosteo
2007-06-19 10:22     ` Alex R. Mosteo
2007-06-15 22:03 ` Georg Bauhaus
2007-06-18 17:23   ` Alex R. Mosteo
2007-06-18 17:35     ` Pascal Obry
2007-06-18 18:04       ` Alex R. Mosteo
2007-06-18 20:25       ` Randy Brukardt
2007-06-19  8:26         ` Dmitry A. Kazakov [this message]
2007-06-19 10:24         ` Alex R. Mosteo
2007-06-19 21:33           ` Randy Brukardt
2007-06-20  1:31             ` Markus E Leypold
2007-06-20  6:25               ` Georg Bauhaus
2007-06-20 13:00                 ` Markus E Leypold
2007-06-20  7:34             ` Dmitry A. Kazakov
2007-06-18 18:34     ` Georg Bauhaus
2007-06-16  6:48 ` Dmitry A. Kazakov
2007-06-18 17:14   ` Alex R. Mosteo
replies disabled

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