[Issue 15096] New: std.range.array cannot be instantiated for pointers to ranges

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Sep 21 16:55:34 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15096

          Issue ID: 15096
           Summary: std.range.array cannot be instantiated for pointers to
                    ranges
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: initrd.gz at 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);

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"]

--


More information about the Digitalmars-d-bugs mailing list