comp.lang.ada
 help / color / mirror / Atom feed
From: "Alex R. Mosteo" <devnull@mailinator.com>
Subject: Re: Containers - nontrivial element access
Date: Wed, 03 Oct 2007 01:23:34 +0200
Date: 2007-10-03T01:23:34+02:00	[thread overview]
Message-ID: <5mg27nFdco18U1@mid.individual.net> (raw)
In-Reply-To: 1191358077.531499.198290@o80g2000hse.googlegroups.com

Maciej Sobczak wrote:

> On 2 Pa , 01:52, "Alex R. Mosteo" <devn...@mailinator.com> 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




  reply	other threads:[~2007-10-02 23:23 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-01 21:55 Containers - nontrivial element access Maciej Sobczak
2007-10-01 23:52 ` Alex R. Mosteo
2007-10-02 16:40   ` Matthew Heaney
2007-10-02 23:16     ` Alex R. Mosteo
2007-10-02 20:47   ` Maciej Sobczak
2007-10-02 23:23     ` Alex R. Mosteo [this message]
2007-10-02  0:39 ` Jeffrey R. Carter
2007-10-02 16:44   ` Matthew Heaney
2007-10-03  0:20     ` Jeffrey R. Carter
2007-10-03 19:40       ` Maciej Sobczak
2007-10-03 19:56         ` Matthew Heaney
2007-10-03 20:21           ` Dmitry A. Kazakov
2007-10-03 22:37             ` Matthew Heaney
2007-10-04  8:06               ` Dmitry A. Kazakov
2007-10-03 22:02         ` Jeffrey R. Carter
2007-10-04  0:16         ` Robert A Duff
2007-10-07  8:41           ` Jacob Sparre Andersen
2007-10-11 19:15             ` Robert A Duff
2007-10-14  4:59               ` Jacob Sparre Andersen
2007-10-14  7:24                 ` Dmitry A. Kazakov
2007-10-14 13:49                   ` Georg Bauhaus
2007-10-14 15:07                     ` Dmitry A. Kazakov
2007-10-02 20:50   ` Maciej Sobczak
2007-10-03  0:22     ` Jeffrey R. Carter
2007-10-03  8:26       ` Dmitry A. Kazakov
2007-10-03 18:49         ` Jeffrey R. Carter
2007-10-03 19:09           ` Matthew Heaney
2007-10-03 19:15           ` Simon Wright
2007-10-03 19:48             ` Maciej Sobczak
2007-10-03 19:58             ` Matthew Heaney
2007-10-03 19:35           ` Dmitry A. Kazakov
2007-10-02  2:34 ` Randy Brukardt
2007-10-02 16:47   ` Matthew Heaney
2007-10-02  7:23 ` Dmitry A. Kazakov
2007-10-02 16:37 ` Matthew Heaney
2007-10-02 21:02   ` Maciej Sobczak
2007-10-02 22:20     ` Matthew Heaney
2007-10-03 19:59       ` Maciej Sobczak
2007-10-03 22:55         ` Matthew Heaney
2007-10-04  0:22         ` Robert A Duff
2007-10-04 13:01         ` Georg Bauhaus
2007-10-04 14:01           ` Matthew Heaney
2007-10-04 21:58           ` Matthew Heaney
replies disabled

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