Bug 15096 – std.array.array cannot be instantiated for pointers to ranges
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-09-21T23:55:34Z
Last change time
2017-10-16T09:57:17Z
Assigned to
No Owner
Creator
Alex Parrill
Comments
Comment #0 by initrd.gz — 2015-09-21T23:55:34Z
std.range.array throws a compiler error when used with a pointer to an input range. This is because `isIterable` returns false for pointers to input ranges.
A possible simple fix: in std.range.array's template constraints, change `isIterable!Range` to `(isIterable!Range || isInputRange!Range)`. Alternatively, make pointers to input ranges iterable.
Test code:
import std.range;
import std.traits;
struct MyRange {
enum front = 123;
enum empty = true;
void popFront() {}
}
pragma(msg, isInputRange!(MyRange));
pragma(msg, isInputRange!(MyRange*));
pragma(msg, isIterable!(MyRange*));
pragma(msg, (new MyRange()).array);
Output:
$ rdmd -main ~/test.d
true
true
false
/home/col/test.d(14): Error: template std.array.array cannot deduce function from argument types !()(MyRange*), candidates are:
/usr/include/dmd/phobos/std/array.d(89): std.array.array(Range)(Range r) if (isIterable!Range && !isNarrowString!Range && !isInfinite!Range)
/usr/include/dmd/phobos/std/array.d(191): std.array.array(String)(String str) if (isNarrowString!String)
/home/col/test.d(14): while evaluating pragma(msg, (new MyRange).array)
Failed: ["dmd", "-main", "-v", "-o-", "/home/col/test.d", "-I/home/col"]
Comment #1 by dlang-bugzilla — 2015-10-15T17:27:13Z