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=unavailable autolearn_force=no version=3.4.4 Path: buffer1.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!goblin2!goblin.stu.neva.ru!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Deleting elements from a Vector Date: Mon, 20 Apr 2015 12:13:30 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="fa9c30c20a5c60fcbf7b9fa05d266b35"; logging-data="19283"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195Izt72L/PL76OwNXo7WJ7r5VjhychCoU=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (darwin) Cancel-Lock: sha1:mF8tfPKNN4YikpOcAwAjuxb79mc= sha1:AW+goDalWxEVt3QG8T4kMpkaT3c= Xref: number.nntp.giganews.com comp.lang.ada:192862 Date: 2015-04-20T12:13:30+01:00 List-Id: Georg Bauhaus writes: > On 20.04.15 09:56, Simon Wright wrote: > >>>> Is there a proper idiom for doing this job? Should I maybe go over the >>>> Vector in reverse order and use the version of Delete that uses the >>>> index? >>> >>> Indeed that seems safer. Note also RM A.18.2(240/2..243/2) for the >>> definition and properties of an "ambiguous" cursor. This also suggests >>> traversing the vector in reverse index order. >> >> Like this: >> >> for J in reverse 1 .. V.Last_Index loop >> if V (J) < 0 then >> Put_Line ("deleting element " & Integer'Image (V (J))); >> V.Delete (J); >> else >> Put_Line ("skipping element " & Integer'Image (V (J))); >> end if; >> end loop; > > +1; also, as this entails sliding, copying to a new vector and > dumping the old seems another option that prevents any tampering. Profiling needed! Thanks for the idea ...