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,eca91508b02e7e97 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Amount of copying on returned constant objects Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <5dfsfnF1qav8bU1@mid.individual.net> <46730bf5$0$23134$9b4e6d93@newsspool1.arcor-online.net> <5dntd6F35jc57U1@mid.individual.net> <4676C27D.2050608@obry.net> Date: Tue, 19 Jun 2007 10:26:38 +0200 Message-ID: NNTP-Posting-Date: 19 Jun 2007 10:23:50 CEST NNTP-Posting-Host: ddd04232.newsspool4.arcor-online.net X-Trace: DXC=Jm9OF5=f2NQV;Ef1`Jk54\4IUKkgR`b478M_7\JW X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:16230 Date: 2007-06-19T10:23:50+02:00 List-Id: On Mon, 18 Jun 2007 15:25:33 -0500, Randy Brukardt wrote: > "Pascal Obry" 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