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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!newsprint.newsread.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!bigboote.WPI.EDU!news.tufts.edu!uunet!spool.news.uu.net!ash.uu.net!newsfd02.forthnet.gr!not-for-mail From: Ioannis Vranos Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: Fri, 25 Mar 2005 04:19:02 +0200 Organization: FORTHnet S.A., Atthidon 4, GR-17671 Kalithea, Greece, Tel: +30 2109559000, Fax: +30 2109559333, url: http://www.forthnet.gr Message-ID: <1111717144.891831@athnrd02> References: <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <1110329098.642196@athnrd02> <1110361741.551255@athnrd02> <422edaec$0$26554$9b4e6d93@newsread4.arcor-online.net> <1111464133.508323@athnrd02> <423fe9df$0$11476$9b4e6d93@newsread2.arcor-online.net> <1111521825.653841@athnrd02> <424094b0$0$11481$9b4e6d93@newsread2.arcor-online.net> <1111568404.687226@athnrd02> <42416659$0$11476$9b4e6d93@newsread2.arcor-online.net> <1111611226.253249@athnrd02> <4241f47a$0$24073$9b4e6d93@newsread4.arcor-online.net> <1111627358.387482@athnrd02> <424222df$0$24057$9b4e6d93@newsread4.arcor-online.net> <1111632436.374702@athnrd02> <1111698643.735412.144620@l41g2000cwc.googlegroups.com> <424362cc$0$11478$9b4e6d93@newsread2.arcor-online.net> NNTP-Posting-Host: athnrd02.forthnet.gr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: athprx02.forthnet.gr 1111717144 15029 193.92.150.73 (25 Mar 2005 02:19:04 GMT) X-Complaints-To: abuse@forthnet.gr NNTP-Posting-Date: Fri, 25 Mar 2005 02:19:04 +0000 (UTC) User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en In-Reply-To: <424362cc$0$11478$9b4e6d93@newsread2.arcor-online.net> Cache-Post-Path: newsfd02!unknown@ppp16-adsl-51.ath.forthnet.gr Xref: g2news1.google.com comp.lang.ada:9949 comp.lang.c++:47157 comp.realtime:1701 comp.software-eng:5312 Date: 2005-03-25T04:19:02+02:00 List-Id: Georg Bauhaus wrote: > One difference is a 1:1 correspondence of index values and > indexed items. This suggests not using p[-1] or somearray[1] > interchangeably: > > There is one named index type. > There is one named array type. > The index type is used in the declaration of the array type, > stating the set of permissible array index values. Again, one can easily define an array container that accepts user defined indexes. The philosophical question that arises is *why no one has done it to this day*. However I am going to make such one in some weekend (perhaps this!) to see if I can find any real use of it. Doing it sounds really simple: template class Array: public vector { // Only provide definitions for operator at() and operator[] that // really *only* explicitly call the base ones with the proper index. // And the few constructors doing the same, *only* explicitly passing // the *same* arguments to the base constructors plus checking MIN and // MAX (only once). }; I think it is *that* simple. Of course it is only about container index ranges, not stored value ranges. > type Item_Array is array (Index_Type) of Item; > > Values in the index type designate items in the problem domain. > This propagates into the declaration of the array type. > It also propagates into its use. > > Ioannis really started, I think, from this 1:1 correspondence. > He had (intuitively?) mapped these kinds of array to std::map > in sample programs. Conceptually this seems right because the > specific index values and the items are associated 1:1 in the > array. For simple things I have been using a vector like this: [real situation comment:] // For [-200, -101] values of Something vector counter(100); [something is in range of -200, -101 (by concept)] counter[something-200]++; For more diverse things, maps are suitable (I guess in Ada too). > From this perspective, after choosing an associative container > for representing the (index, item) pairs, you can no longer > use somemap[-1] or somemap[1] interchangeably. The perspective > has shifted from computing offsets to an association. 1 is > associated with one item in the array, -1 is associated with > another. > > In this sense, p[-1] and somearray[1] are different. > In a sense, -1 and 1 are treated as names rather than > computable index values. > > (Ada-like arrays have STL's key_type so to speak.) key_type is used only in maps! -- Ioannis Vranos http://www23.brinkster.com/noicys