Merging one Array with Another
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 2 04:57:41 PDT 2015
On Saturday, 2 May 2015 at 11:16:30 UTC, Meta wrote:
> Probably the latter is slower than the former, at the very
> least because the latter requires memory allocation whereas the
> former does not.
Ahh!,
auto x = [11, 3, 2, 4, 5, 1];
auto y = [0, 3, 10, 2, 4, 5, 1];
auto z = x.chain(y).sort; // sort them in place
assert(x == [0, 1, 1, 2, 2, 3]);
assert(y == [3, 4, 4, 5, 5, 10, 11]);
is very cool, provided that y is allowed to mutate. Now I
understand why chain is useful.
A reallocation will however be needed in the final assignment
though. But no temporary!
More information about the Digitalmars-d-learn
mailing list