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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,55f6e230b02eff2f,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!n39g2000hsh.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Containers - nontrivial element access Date: Mon, 01 Oct 2007 14:55:59 -0700 Organization: http://groups.google.com Message-ID: <1191275759.184463.238350@n39g2000hsh.googlegroups.com> NNTP-Posting-Host: 85.3.253.180 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" X-Trace: posting.google.com 1191275759 26596 127.0.0.1 (1 Oct 2007 21:55:59 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 1 Oct 2007 21:55:59 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: n39g2000hsh.googlegroups.com; posting-host=85.3.253.180; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:2240 Date: 2007-10-01T14:55:59-07:00 List-Id: I was thinking recently about what is wrong with the containers interface. ;-) Consider the following problem: 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. 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 people; // ... swap(people[x].salary, people[y].salary); 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. What would you suggest as the Ada solution for this problem? 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? -- Maciej Sobczak * www.msobczak.com * www.inspirel.com