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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,711b9e86dd6927b9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-14 08:04:54 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: Charles: missing vector iterators Date: 14 Nov 2002 08:04:54 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0211140804.42621077@posting.google.com> References: <3dd29387$0$303$bed64819@news.gradwell.net> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1037289894 6997 127.0.0.1 (14 Nov 2002 16:04:54 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 14 Nov 2002 16:04:54 GMT Xref: archiver1.google.com comp.lang.ada:30881 Date: 2002-11-14T16:04:54+00:00 List-Id: porton@ex-code.com (Victor Porton) wrote in message news:<3dd29387$0$303$bed64819@news.gradwell.net>... > Why in Charles.Vectors iterators are missing even despite it is > modelled after STL? Because iterators for vectors are too fragile. An unbounded vector automatically grows as necessary during insertions. This works by deallocating the existing internal array, reallocating a new (longer) array, and copying the existing elements onto the new array. The issue is that an iterator designates the old array, which gets deallocated. It's too easy for forget this fact, which means dangling references occur. The whole problem goes away by simply using the index subtype to refer to elements in the vector, instead of an iterator. Realize that the iterator exists in the STL because of the nature of template expansion in C++. In Ada, a separate iterator is not necessary because the generic actual subprogram only needs to match the signature of the generic formal, not its name (which is not the case in C++). Remember that Charles is *modelled* on the STL, but it is not a literal port of the STL. Charles is first and foremost an Ada library, and it takes advantage of specific features of the Ada language, specifically nested subprograms. > Iterators are good for many things, including reliability: Just the opposite. A vector iterator is very UNreliable. >Probability to mess iterators is > lesser than to mess natural number indexes because iterators are more > type-safe. Wrong for vectors. I don't know what would ever motivate you to think this, when iteration over a scalar range is so high level in Ada: for I in I_Subtype loop for J in J_Subtype loop ... This is hard to get wrong. > Please add these. Your suggestion is noted, and rejected. > BTW, may be put Chrles on SourceForge or something that if e.g. I will > want to submit a patch it would become simpler? You can get more immediate feedback by sending me email directly. CLA is probably not the most suitable forum for discussing Charles features. mheaney at on2 dot com