Skip to content

Commit

Permalink
Fix Issue 15096 - std.array.array cannot be instantiated for pointers…
Browse files Browse the repository at this point in the history
… to ranges
  • Loading branch information
RazvanN7 committed Aug 16, 2017
1 parent e99cf38 commit eadf51a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions std/array.d
Expand Up @@ -139,6 +139,13 @@ if (isIterable!Range && !isNarrowString!Range && !isInfinite!Range)
}
}

///
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,18 @@ 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() {}
}

static assert(__traits(compiles, (new MyRange).array));
}

@system unittest
{
import std.algorithm.comparison : equal;
Expand Down

0 comments on commit eadf51a

Please sign in to comment.