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: Brian Rogoff Subject: Re: Wanted: Ada STL. Reward: Ada's Future Date: 1999/02/05 Message-ID: #1/1 X-Deja-AN: 441056412 References: <790f4q$3l@bgtnsc01.worldnet.att.net> <36B856E4.D921C1D@bton.ac.uk> <36BAEA8B.5B375A30@bton.ac.uk> Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: nntp1.ba.best.com 918235452 16676 bpr@206.184.139.136 MIME-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-02-05T00:00:00+00:00 List-Id: On Fri, 5 Feb 1999, John English wrote: > 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 Let me take this opportunity to independently plug John's book. While I think it is aimed at beginning programmers, there are quite a few very nice examples, and some nice Ada tricks. > 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.). Exactly true. Anyone seeking to achieve the seamlessness of STL in Ada will fail. Since you can't overload array indexing or pointer operations in Ada, *no* pure Ada library will achieve this. Another strength of C++ is in automatic instantiation of generic subprograms. This reduces the number of instantiations, and makes code a lot more readable, IMO, in the same way that overloading properly used makes code more readable. There really are some nice features of C++, its just too bad that the language as a whole suffers so much from its C lineage. -- Brian