Re: Removing multiple elements from array

2013-12-21 Thread Ali Çehreli
On 12/21/2013 05:39 PM, aldanor wrote: > On Saturday, 21 December 2013 at 21:49:01 UTC, MrSmith wrote: >> just use foreach_reverse > > Wow, I never knew it is a keyword, thank you! I feel guilty for omitting in knowingly but we've been hearing that it would be deprecated. I don't think it will

Re: Removing multiple elements from array

2013-12-21 Thread aldanor
On Saturday, 21 December 2013 at 21:49:01 UTC, MrSmith wrote: On Saturday, 21 December 2013 at 00:47:04 UTC, aldanor wrote: Is there an efficient method to remove elements with multiple (compile-time-unknown) indices from an array? I currently do something like if (!index.empt

Re: Removing multiple elements from array

2013-12-21 Thread MrSmith
On Saturday, 21 December 2013 at 00:47:04 UTC, aldanor wrote: Is there an efficient method to remove elements with multiple (compile-time-unknown) indices from an array? I currently do something like if (!index.empty) foreach (i; index.sort.reverse)

Re: Removing multiple elements from array

2013-12-21 Thread aldanor
On Saturday, 21 December 2013 at 02:52:00 UTC, bearophile wrote: Do not forget to add the () after the sort, otherwise you call the deprecated, buggy and slow built-in sort. reverse is another deprecated built-in, so use "retro". The first "if" is not much useful, trying to sort an empty arra

Re: Removing multiple elements from array

2013-12-21 Thread aldanor
On Saturday, 21 December 2013 at 03:22:22 UTC, H. S. Teoh wrote: Unfortunately, while std.algorithm.remove does provide a way to do this if the number of indices to remove are known beforehand, it doesn't seem to be able to remove a dynamic list of indices. Probably an enhancement request shou

Re: Removing multiple elements from array

2013-12-20 Thread H. S. Teoh
On Fri, Dec 20, 2013 at 07:13:59PM -0800, H. S. Teoh wrote: > On Fri, Dec 20, 2013 at 07:01:17PM -0800, Ali Çehreli wrote: > > On 12/20/2013 06:17 PM, aldanor wrote: > > >On Saturday, 21 December 2013 at 01:42:04 UTC, Ali Çehreli wrote: > > > > > >>That's probably a bug, right? The indexes would pr

Re: Removing multiple elements from array

2013-12-20 Thread H. S. Teoh
On Fri, Dec 20, 2013 at 07:01:17PM -0800, Ali Çehreli wrote: > On 12/20/2013 06:17 PM, aldanor wrote: > >On Saturday, 21 December 2013 at 01:42:04 UTC, Ali Çehreli wrote: > > > >>That's probably a bug, right? The indexes would probably become off as > >>the array gets shorter. > > > >Note the .reve

Re: Removing multiple elements from array

2013-12-20 Thread Ali Çehreli
On 12/20/2013 06:17 PM, aldanor wrote: On Saturday, 21 December 2013 at 01:42:04 UTC, Ali Çehreli wrote: That's probably a bug, right? The indexes would probably become off as the array gets shorter. Note the .reverse there? Yes, I missed that part. :) Which makes sure indices don't get o

Re: Removing multiple elements from array

2013-12-20 Thread bearophile
aldanor: Is there an efficient method to remove elements with multiple (compile-time-unknown) indices from an array? I currently do something like if (!index.empty) foreach (i; index.sort.reverse) a = a.remove(i); ... wh

Re: Removing multiple elements from array

2013-12-20 Thread aldanor
On Saturday, 21 December 2013 at 01:42:04 UTC, Ali Çehreli wrote: That's probably a bug, right? The indexes would probably become off as the array gets shorter. Note the .reverse there? Which makes sure indices don't get off. Still, that's probably an inefficient way of doing this...

Re: Removing multiple elements from array

2013-12-20 Thread Ali Çehreli
On 12/20/2013 04:47 PM, aldanor wrote: > Is there an efficient method to remove elements with multiple > (compile-time-unknown) indices from an array? I currently do something like > > if (!index.empty) > foreach (i; index.sort.reverse) > a = a.remove(i);