Merge pull request #5693 from RazvanN7/Issue_15096

Fix Issue 15096 - std.array.array cannot be instantiated for pointers to ranges
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
This commit is contained in:
The Dlang Bot 2017-09-14 02:15:30 +02:00 committed by GitHub
commit ffee71058e

View file

@ -139,6 +139,13 @@ if (isIterable!Range && !isNarrowString!Range && !isInfinite!Range)
} }
} }
/// ditto
ForeachType!(PointerTarget!Range)[] array(Range)(Range r)
if (isPointer!Range && isIterable!(PointerTarget!Range) && !isNarrowString!Range && !isInfinite!Range)
{
return array(*r);
}
/// ///
@safe pure nothrow unittest @safe pure nothrow unittest
{ {
@ -157,6 +164,26 @@ if (isIterable!Range && !isNarrowString!Range && !isInfinite!Range)
assert(equal(a, [Foo(1), Foo(2), Foo(3), Foo(4), Foo(5)])); assert(equal(a, [Foo(1), Foo(2), Foo(3), Foo(4), Foo(5)]));
} }
@safe pure nothrow unittest
{
struct MyRange
{
enum front = 123;
enum empty = true;
void popFront() {}
}
auto arr = (new MyRange).array;
assert(arr.empty);
}
@system pure nothrow unittest
{
immutable int[] a = [1, 2, 3, 4];
auto b = (&a).array;
assert(b == a);
}
@system unittest @system unittest
{ {
import std.algorithm.comparison : equal; import std.algorithm.comparison : equal;