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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,55f6e230b02eff2f X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news.germany.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Containers - nontrivial element access Date: Wed, 03 Oct 2007 01:23:34 +0200 Message-ID: <5mg27nFdco18U1@mid.individual.net> References: <1191275759.184463.238350@n39g2000hsh.googlegroups.com> <5mdfipFcv1dsU1@mid.individual.net> <1191358077.531499.198290@o80g2000hse.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: individual.net CKCoGa7YMmY+acTIZwoy5wvt7fkn8c/wtmkUst2O8bhGT0LyU= Cancel-Lock: sha1:Cowo++sOloD3MTpX2p4MNophDMw= User-Agent: KNode/0.10.5 Xref: g2news2.google.com comp.lang.ada:2258 Date: 2007-10-03T01:23:34+02:00 List-Id: Maciej Sobczak wrote: > On 2 Pa , 01:52, "Alex R. Mosteo" wrote: > >> I'm not sure the solution is clunky, unless you consider verbose=clunky. > > The point is that in order to swap data, you need to pass the new > value to the modifying procedure. Since there are no on-the-fly > binders, this value has to be provided by additional variable, which > exists outside of the procedure, which access is passed. This looks > like a dodgy hack: I provide a procedure, which is not self-contained > anyway, so I also sneak around the value. Uh? I think Matthew's solution doesn't use anything extra? Further example: imagine that containers had this subprogram: procedure Operate (This : in out Vector; I, J : Index_Type; Op : access not null procedure (L, R : in out Element_Type)); Now, this Operate procedure does Matthew's nested accessing in place and calls the provided Op procedure. Swapping (or anything else) would be: declare procedure Swap (L, R : in out Whatever) is -- You know the deal begin My_Vector.Operate (X, Y, Swap'Access); end; Does it look good? This isn't in the containers, but you can provide it yourself. Is what I thought of yesterday night, but I (mistakenly) thought you were more concerned with verbosity so I didn't bothered to exemplify. > > I have nothing against the procedure, even if it is longer (/= clunky) > than what I can do in C++. I have, however, a *serious* problem with > sneaking this value around. > This *is* clunky. Can you summarize it for me? Is Matthew's solution satisfactory? I've passed a bit fast over the thread :) > >> There are additional differences, if I'm not mistaken (my C++ is a bit >> outdated). [] is, I think, unchecked (unlike .at()), so you could get a >> violation with that code that shouldn't be possible in Ada. > > You are half right. The standard does not require [] to be checked. It > does not forbid it, either. > > The point is not about [], actually, but about references. I might > have written my example like this: > > swap(people.at(x).salary, people.at(y).salary); > > and then you would not have been able to nit-pick on the possible > violation. :-) Of course :). It was just something that came to me when reading your post and just throw it in with the rest of the lot. > > -- > Maciej Sobczak * www.msobczak.com * www.inspirel.com