[Issue 15982] std.array.array treats dynamic arrays as input ranges and allocates new memory
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon May 2 05:06:54 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15982
--- Comment #5 from ag0aep6g at gmail.com ---
(In reply to sigod from comment #4)
> I bet no one uses `array()` for duplicating
> arrays.
I don't think betting on these things is a good course of action. The function
is documented to allocate a new array. Changing that is a breaking change.
> Function called `array` for a reason. Because it gives you array where you
> have only an input range. It doesn't make sense to do anything if you
> already have an array. In normal code you will never call `array` for array.
Here's a little generic function that relies on std.array.array's current
behavior:
----
immutable(ElementType!R)[] toImmutableArray(R)(R range)
if (isInputRange!R && !hasIndirections!(ElementType!R))
{
import std.array: array;
import std.exception: assumeUnique;
return assumeUnique(range.array);
}
----
--
More information about the Digitalmars-d-bugs
mailing list