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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,effb80d4bb7716dd X-Google-Attributes: gid103376,public From: John English Subject: Re: Wanted: Ada STL. Reward: Ada's Future Date: 1999/02/05 Message-ID: <36BAEA8B.5B375A30@bton.ac.uk>#1/1 X-Deja-AN: 441041517 Content-Transfer-Encoding: 7bit References: <790f4q$3l@bgtnsc01.worldnet.att.net> <36B856E4.D921C1D@bton.ac.uk> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: University of Brighton Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-02-05T00:00:00+00:00 List-Id: Stephen Leake wrote: > I thought Matthew just did that, but you haven't answered the question > "why does the STL allow iteration past the end of the array". This > bugs me too. Is there a real reason here, or is it an accident of the > implementation? A "past-the-end" value makes it easy to insert items into collections -- you always insert BEFORE a particular position, so inserting before the past-the-end position will append to the end. In the case of arrays you can't insert anything, but at least you have read access to arrays in exactly the same way as any other collection type. This means that non-mutating algorithms (searching, counting, ...) can all be used on arrays just as easily as on a linked list. And there's no performance penalty either. > Perhaps it is the most general way to define an iterator that points > to nothing? Certainly if the underlying implementation of a collection > is an array, this makes sense. But if the underlying implementation is > a list, then a null pointer makes more sense. Why not make the > abstraction resemble a null pointer, rather than an out-of-bounds > index? But which list is the null pointer pointing to? I did something like this in my Ada book (plug, plug :-); there's an iterator for linked lists which is a record with two components: a pointer to the list, and a pointer to the position within the list (null = past-the-end). And of course, if the pointer to the list is null, it means that the iterator is invalid. But anyway: a strength of the STL which seems difficult (impossible?) to reproduce in Ada is the ability to treat built-in collection types (arrays) in *exactly* the same way as user-defined collection types (vectors, maps, etc.). ----------------------------------------------------------------- John English | mailto:je@brighton.ac.uk Senior Lecturer | http://www.it.bton.ac.uk/staff/je Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS ** University of Brighton | -- see http://burks.bton.ac.uk -----------------------------------------------------------------