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
I'm guessing you mean std.array.array: http://dlang.org/phobos/std_array.html#array
Comment #2 by initrd.gz — 2015-10-16T01:57:25Z
Same thing; std.range imports std.array.array
Comment #3 by razvan.nitu1305 — 2017-08-16T10:25:27Z
Comment #4 by github-bugzilla — 2017-09-14T00:15:34Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/eadf51a841388ead61788483d9e5a0266b0c1479 Fix Issue 15096 - std.array.array cannot be instantiated for pointers to ranges https://github.com/dlang/phobos/commit/ffee71058ec2daf699215b90dd9a851e8fb7467c 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 <[email protected]>
Comment #5 by github-bugzilla — 2017-10-16T09:57:17Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/eadf51a841388ead61788483d9e5a0266b0c1479 Fix Issue 15096 - std.array.array cannot be instantiated for pointers to ranges https://github.com/dlang/phobos/commit/ffee71058ec2daf699215b90dd9a851e8fb7467c Merge pull request #5693 from RazvanN7/Issue_15096