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 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!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns13feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Containers - nontrivial element access References: <1191275759.184463.238350@n39g2000hsh.googlegroups.com> <1191343440.985588.143470@d55g2000hsg.googlegroups.com> <1191440425.737861.140360@50g2000hsm.googlegroups.com> In-Reply-To: <1191440425.737861.140360@50g2000hsm.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <2kUMi.133748$Fc.79421@attbi_s21> NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1191448958 12.201.97.213 (Wed, 03 Oct 2007 22:02:38 GMT) NNTP-Posting-Date: Wed, 03 Oct 2007 22:02:38 GMT Organization: AT&T ASP.att.net Date: Wed, 03 Oct 2007 22:02:38 GMT Xref: g2news2.google.com comp.lang.ada:2280 Date: 2007-10-03T22:02:38+00:00 List-Id: Maciej Sobczak wrote: > > Imagine I haven an *array* of Person(s) and I do this: > > Swap (People (X).Salary, People (Y).Salary); > > This is Ada. > > (is it value semantics for you, btw?) > > Now I want to do the same with vector. You can want to do anything, but that's a good way to be disappointed. Let's deal with the simpler People (X).Salary := S; so we're not mislead by the call to Swap. With an array, there are no operations (subprograms or entries) invoked. With a data structure, you must invoke an operation to get at a value stored in it. That's what causes the difference. The operations on the data structure return values, so modifying them does not change the value stored in the data structure. > In other words, I want to use Ada in the Ada spirit. No, the Ada spirit is generally to deal with values (as Ada.Containers does), not anonymous references, as is common in C/++ and the STL (since everything in C/++ is aliased), though one could argue that the addition of anonymous access types and values in Ada 95, and its expansion in Ada 07 (things I don't like; pointers should be as difficult to use as possible), changes the spirit. > If we realize that vector is a generalization of array, is it > revolutionary to expect that the common functionality should have > common interface? If we realize that package Ada.Containers.Vectors is an unbounded-sequence data structure (as is Doubly_Linked_Lists), then we would not expect anything of the kind. There are hints in the discussion and some of the operations that Vectors is intended specifically for an array implementation, but an implementation built on top of Doubly_Linked_Lists would be perfectly legal and correct. There are analogs of array operations, but they are only analogs. Ada.Containers is quite general and as safe as possible; it is unlikely to be appropriate for many applications. It may be that you should write your own, with "access Element" prevalent, for your specific needs. If not, you'll have to use the syntax and semantics of the existing packages. -- Jeff Carter "Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!" Monty Python's Flying Circus 53