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: <36BABA14.22DCA8D9@bton.ac.uk>#1/1 X-Deja-AN: 440957406 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: Matthew Heaney wrote: > John English writes: > > > In Ada this isn't possible -- e.g. type Foo is array(Boolean) of Bar > > has no "beyond the end" index that can be used to form non-inclusive > > ranges [i,j). This makes it hard to support arrays as "just another > > collection type" in the way that the STL does, so you can't easily > > define algorithms which can be applied impartially to arrays or > > vectors or maps or whatever. > > The problem in your example is your array index. The rule in Ada is > that an enumeration type is its own base type, and type Boolean has no > other values than True and False. Indeed. > If you need to fall off the beginning or end of an array, you just need > to make sure the base type of the index subtype has at least one extra > value on either end, something like: > > type Color_Base is (First, Red, Green, Blue, Last); > > subtype Color_Type is Color_Base > range Color_Base'Succ (First) .. Color_Base'Pred (Last); ... which means that you couldn't apply STL-type algorithms to *any* array the way you can in C++. IMHO the nice thing about STL is the way it lets you deal with arrays and user-defined containers in a completely uniform manner. > The idioms in both languages are completely different. So forget about > the STL as a model for an Ada library. Indeed. But *something* is needed; having everyone invent their own propietary versions of common data types and algorithms is a complete waste of time. Even if the STL model doesn't fit Ada, it's useful as a reminder of what can/should be provided. ----------------------------------------------------------------- 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 -----------------------------------------------------------------