mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
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:
commit
ffee71058e
1 changed files with 27 additions and 0 deletions
27
std/array.d
27
std/array.d
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue