www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15096] New: std.range.array cannot be instantiated for


          Issue ID: 15096
           Summary: std.range.array cannot be instantiated for pointers to
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: initrd.gz gmail.com

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);


    $ rdmd -main ~/test.d
    /home/col/test.d(14): Error: template std.array.array cannot deduce
function from argument types !()(MyRange*), candidates are:
std.array.array(Range)(Range r) if (isIterable!Range && !isNarrowString!Range
&& !isInfinite!Range)
std.array.array(String)(String str) if (isNarrowString!String)
    /home/col/test.d(14):        while evaluating pragma(msg, (new
    Failed: ["dmd", "-main", "-v", "-o-", "/home/col/test.d", "-I/home/col"]

Sep 21 2015