comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <bauhaus@futureapps.invalid>
Subject: Re: Deleting elements from a Vector
Date: Mon, 20 Apr 2015 10:39:07 +0200
Date: 2015-04-20T10:39:07+02:00	[thread overview]
Message-ID: <mh2dtf$h5t$1@dont-email.me> (raw)
In-Reply-To: <lyy4ln44hl.fsf@pushface.org>

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.

  reply	other threads:[~2015-04-20  8:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-19 20:27 Deleting elements from a Vector Simon Wright
2015-04-19 21:07 ` Jeffrey Carter
2015-04-19 21:12 ` Niklas Holsti
2015-04-20  7:56   ` Simon Wright
2015-04-20  8:39     ` Georg Bauhaus [this message]
2015-04-20 11:13       ` Simon Wright
2015-04-20  7:36 ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox