delete an element from an array

Stewart Gordon smjg_1998 at yahoo.com
Sun Oct 24 09:39:10 PDT 2010


On 24/10/2010 12:24, Adam Cigánek wrote:
> remove removes element at a given offset. I want to remove element
> with a given value. This is example shows it better:
<snip>

Your new example doesn't show it better, it's the only one you've given 
that shows it at all.  What you had originally was

   auto a = [1, 2, 3, 4, 5, 6];
   auto b = delete(a, 4);

   assert([1, 2, 3, 4, 6] == b);

which shows the removal of the element at index 4, not the element with 
value 4.

But there are further questions to be answered:

- What do you want it to do if the value isn't in the array?  Just 
return the original array, return a copy of the original array, or throw 
an exception?

- What do you want it to do if the value is in the array more than once? 
  Remove the first, remove the last, remove all of them, or pick one at 
random?

Stewart.


More information about the Digitalmars-d-learn mailing list