Skip to content

Commit

Permalink
Merge pull request #5693 from RazvanN7/Issue_15096
Browse files Browse the repository at this point in the history
Fix Issue 15096 - std.array.array cannot be instantiated for pointers to ranges
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
  • Loading branch information
dlang-bot committed Sep 14, 2017
2 parents fc46850 + 4bbfc43 commit ffee710
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions std/array.d
Expand Up @@ -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
{
Expand All @@ -157,6 +164,26 @@ if (isIterable!Range && !isNarrowString!Range && !isInfinite!Range)
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
{
import std.algorithm.comparison : equal;
Expand Down

0 comments on commit ffee710

Please sign in to comment.