What is the replacement for deprecated array removal

Steven Schveighoffer schveiguy at gmail.com
Mon Nov 18 20:37:50 UTC 2019


On 11/18/19 3:01 PM, kerdemdemir wrote:
>      int[] removeList;
>      for ( int i = 0; i < tempMap[0].length; i++ )
>      {
>          if ( i%2 == 0 )
>              removeList ~=i;
>      }
>      writeln(removeList); (prints 0,2,4)
>      tempMap[1].remove(0,2,4);
>      tempMap[2].remove(removeList);
>      tempMap[3].remove(tuple(0,1),tuple(2,3),tuple(4,5) );
> 
> Even weirder(at least for me)
> 
> int[] removeList is [0,2,4]
> 
> And .remove returns different results for .remove(0,2,4); and 
> ..remove(removeList)
> 
> Is there anyway to convert int[] to a sequence like 0,2,4
> 
> Erdem

If I follow the code correctly, it's treating your array as a tuple of 
pos/len to remove.

So it looks like your code is equivalent to

remove(tuple(0, 2));

Which is probably not what you want.

This probably explains why it's being deprecated, it's too confusing to 
the compiler.

And looking at git blame goes back to this PR: 
https://github.com/dlang/phobos/pull/6154

-Steve


More information about the Digitalmars-d-learn mailing list