Example from d-idioms is incorrect

Justin Whear via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 30 15:01:43 PDT 2015


On Thu, 30 Apr 2015 21:30:34 +0000, TheGag96 wrote:
> Was the behavior of the remove() function changed recently? Thanks guys.

I believe remove has always worked this way.  What you're seeing is 
explained by this note in the documentation for remove:

> The original array has remained of the same length because all
> functions in std.algorithm only change content, not topology. The value 
> 8 is repeated because std.algorithm.move was invoked to move elements 
> around and on integers move simply copies the source to the 
> destination. To replace a with the effect of the removal, simply assign 
> a = remove(a, 1). The slice will be rebound to the shorter array and 
> the operation completes with maximal efficiency.


More information about the Digitalmars-d-learn mailing list