Is there library to do in place modification of dynamic arrays?

Nick Treleaven nick at geany.org
Fri Dec 19 14:21:37 UTC 2025


On Friday, 19 December 2025 at 13:23:29 UTC, Brother Bill wrote:
> On Friday, 19 December 2025 at 12:31:29 UTC, Nick Treleaven 
> wrote:
>> https://dlang.org/phobos/std_algorithm_mutation.html#remove
>
> This code has wrong result.  What am I doing wrong?
> ```
> int[] array = [10, 20, 30, 40];
> array = array.remove([1, 3]);  // Expect 20, 40 to be removed.  
> Expect array to be: [10, 30]
> writeln(array);                // [10, 40]
> ```
>
> Is this a feature or a bug?  This is not what I expected.

You're using the deprecated overload, passing an array. Why are 
you using that?

```
arrremove.d(5): Deprecation: template 
`std.algorithm.mutation.remove(SwapStrategy s = 
SwapStrategy.stable, Range, Offset...)(Range range, Offset 
offset) if (Offset.length >= 1 && 
!allSatisfy!(isValidIntegralTuple, Offset))` is deprecated - Use 
of non-integral tuples is deprecated. Use remove(tuple(start, 
end).
```

Instead use:
```d
array = array.remove(1, 3);  // Expect 20, 40 to be removed.  
Expect array to be: [10, 30]
```
https://dlang.org/phobos/std_algorithm_mutation.html#remove-multiple


More information about the Digitalmars-d-learn mailing list