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: Hyman Rosen Subject: Re: Wanted: Ada STL. Reward: Ada's Future Date: 1999/02/04 Message-ID: <36B9E159.C072ECDA@prolifics.com>#1/1 X-Deja-AN: 440670657 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 X-Complaints-To: usenet@panix.com X-Trace: news.panix.com 918151491 28442 207.19.14.254 (4 Feb 1999 18:04:51 GMT) Organization: Prolifics Mime-Version: 1.0 NNTP-Posting-Date: 4 Feb 1999 18:04:51 GMT Newsgroups: comp.lang.ada Date: 1999-02-04T18:04:51+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? STL iterators are analogous to C pointers; one goal of the STL design is to be able to use C pointers as iterators in any STL algorithm. Given that C allows a one-past-the-end pointer to an array, it becomes natural to express STL ranges as [i,j). This allows an entire array to be spanned, as well as allowing an empty range to be easily specified. > 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? Because you don't always want to operate on the entire container, of course. STL algorithms take a pair of iterators when they need a range specified, and this allows them to work on arbitrary sections of a container. Also, when an algorithm requires a bidirectional iterator, you can go back from a past-the-end iterator, but not from a null pointer.