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-15 01:13:18 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!peer1.news.newnet.co.uk!lon1-news.nildram.net!news-peer.gradwell.net!not-for-mail Newsgroups: comp.lang.ada From: porton@ex-code.com (Victor Porton) Date: Fri, 15 Nov 2002 12:27:32 +0500 References: <3dd29387$0$303$bed64819@news.gradwell.net> Organization: Extreme Code Software (http://ex-code.com) Subject: Re: Charles: missing vector iterators Mime-Version: 1.0 X-Newsreader: knews 1.0b.1 Content-Type: text/plain; charset=us-ascii X-URL: http://www.ex-code.com/ Message-ID: <3dd4baae$0$304$bed64819@news.gradwell.net> NNTP-Posting-Date: 15 Nov 2002 09:13:18 GMT NNTP-Posting-Host: 195.149.39.13 X-Trace: 1037351598 news.gradwell.net 304 mail2news/195.149.39.13 X-Complaints-To: news-abuse@gradwell.net Xref: archiver1.google.com comp.lang.ada:30919 Date: 2002-11-15T09:13:18+00:00 List-Id: In article <1ec946d1.0211140804.42621077@posting.google.com>, mheaney@on2.com (Matthew Heaney) writes: > 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. type Iterator_Type is private; ... type Iterator_Type is record Contaner: Container_Access; Index: Index_Type; end record; It is probably space inefficient but otherwise good. With a good compiler we seemingly can even live without space inefficiency using my previously posted to c.l.a idea of per container instance iterators: type Iterator_Type(Contaner: Container_Access) is record Index: Index_Type; end record; Now we can introduce a space efficient Range_Type (if compiler well optimized records with discriminants for space): type Range_Type(Contaner: Container_Access) is record First, Last: Iterator_Type(Container); end record; With a good compiler (if these exist) here it will be optimized to keep only one value of Container_Access for Range_Type variables. Well, may be someday I will write my own containers library with features like this container-specific Range_Type. BTW, for conveniency ranges should be transfered not as two separate values, but as records with two components. > The whole problem goes away by simply using the index subtype to refer > to elements in the vector, instead of an iterator. [Skipped because we define the term "iterator" differently: I mean fat iterators (which can be dereferenced without supplying containers; while Matthew Heaney means "something based on pointers".]