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=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1fa85f3df5841ae1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!usenet-fr.net!news.enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Re: Ada.Containers.Vectors - querying multiple elements Date: Thu, 28 Apr 2005 15:53:02 +0200 Organization: Cuivre, Argent, Or Message-ID: References: <426e4c2b$0$7515$9b4e6d93@newsread2.arcor-online.net> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1114696398 7871 212.85.156.195 (28 Apr 2005 13:53:18 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Thu, 28 Apr 2005 13:53:18 +0000 (UTC) Cc: comp.lang.ada@ada-france.org To: Matthew Heaney Return-Path: In-Reply-To: X-Mailer: Evolution 2.2.1.1 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:10781 Date: 2005-04-28T15:53:02+02:00 Hi Matthew, thanks for your detailed explanation. > > When you have a container that is an extensible array, wanting to be > > able to directly access slices of it as an array seems normal (and > > useful) to me. > > In the STL way of doing things, you don't write algorithms in terms of a > specific container. You write algorithms in terms of an "abstract > container." Iterators allow you to view a container in a > container-neutral way, as merely a "sequence of items," described using > an iterator pair to bound the sequence, and with iterator operations for > navigating among the elements of the sequence. ... > The problem you're having is that you have an algorithm written in terms > of a specific container: an array. And now you want to apply that > algorithm to a different kind of container: a vector. This is precisely > the kind of problem the STL algorithm model was designed to solve. > > You can do this in Ada too, by writing algorithms in a way that is > container neutral. See for example generic_anonymous_array_sort, which > is declared like this: ... > Had you written your algorithm as above, then you wouldn't be having the > difficulties you're having now. It would work for an array: ... > Now, don't you think that's better than what you did? You are certainly correct that when I quickly reworked the routine in question to take a vector rather than an array, I should have done it in a more abstract way, as in your example. As for the other code I have in mind, at some point things really have to be contiguous arrays for efficiency reasons. As pointed out in the AI discussion, efficiency was not the main goal of the container libraries - people who need something super efficient should write their own custom object. That's fine by me. > > I guess the point is that Vector is not an extensible array - the > > designers chose a more abstract design. > > An extensible array is the model for a vector, but of course a vector > doesn't have to be implemented that way. Extensible arrays are useful - it would have been nice to have them. > You want to view the elements in a vector as a contiguous array, but > that wouldn't confer any benefits unless if the underlying > implementation is a contiguous array. That's not entirely true, but in any case it would seem to go against the philosophy you outlined above. All the best, Duncan.