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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: Deleting elements from a Vector Date: Mon, 20 Apr 2015 10:39:07 +0200 Organization: A noiseless patient Spider Message-ID: References: Reply-To: nonlegitur@futureapps.de Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 20 Apr 2015 08:38:07 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="b96887e80893c84a90c3007226ca0d1c"; logging-data="17597"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18FcAZrTRqUBv3VG508XsAAgyQyRXv2ANs=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: Cancel-Lock: sha1:kGRnrBOnnzO0sNn4y8WFipNq78E= Xref: news.eternal-september.org comp.lang.ada:25555 Date: 2015-04-20T10:39:07+02:00 List-Id: 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.