From: Matthew Heaney <mheaney@on2.com>
Subject: Re: Containers - nontrivial element access
Date: Tue, 02 Oct 2007 09:37:51 -0700
Date: 2007-10-02T09:37:51-07:00 [thread overview]
Message-ID: <1191343071.685478.146710@19g2000hsx.googlegroups.com> (raw)
In-Reply-To: <1191275759.184463.238350@n39g2000hsh.googlegroups.com>
On Oct 1, 5:55 pm, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
>
> There is a record type (for example Person) with a couple of fields
> (for example Salary) that together make the whole a bit heavy, so that
> unnecessary copying of the whole is to be avoided. Objects of this
> type are stored in the container.
Right, so you probably want to avoid operations Element or
Replace_Element, and use Query_Element or Update_Element instead.
> I would like to swap salaries of two guys which I can refer with the
> index/iterator/cursor/etc. The reference method is not really
> important - what is important is the problem of modifying more than
> one element in the container.
>
> C++ example is easy:
>
> vector<Person> people;
> // ...
> swap(people[x].salary, people[y].salary);
V : Person_Vectors.Vector;
declare
procedure Process_X (PX : in out Person) is
procedure Process_Y (PY : in out Person) is
SX : constant Salary_Type := PX.Salary;
begin
PX.Salary := PY.Salary;
PY.Salary := SX;
end;
begin
V.Update_Element (Y, Process_Y'Access);
end;
begin
V.Update_Element (X, Process_X'Access);
end;
> I hope it is obvious what it does (suppose x and y are some indices
> into the vector). Just in case it isn't - all the components of the
> two records stay intact except the salary, which is swapped between
> the two. C++ makes it possible by explicitly returning a reference
> from the method that accesses the element.
Right, but Ada doesn't have explicit reference types, so you have to
use Update_Element, which allows in-place editing.
> What would you suggest as the Ada solution for this problem?
See above.
> The Update_Element procedure with its access to the user-provided
> modifying procedure requires to pass data "under the table" (like with
> a separate variable declared aside the modifying procedure) - and
> seems to be just clunky. Is this the only possibility?
I don't understand what you think the problem is. There is no need
for a separate variable or anything else.
next prev parent reply other threads:[~2007-10-02 16:37 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
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 [this message]
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