www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17129] New: class-nested alias of free function can't be

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

          Issue ID: 17129
           Summary: class-nested alias of free function can't be called
                    from const-methods
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dlang supradigital.org

The following code fails with this compiler message:

main.d(11): Error: template main.C.filter!((a) => a != 0).filter cannot deduce
function from argument types !()(int[]) const, candidates are:
/usr/include/dmd/phobos/std/algorithm/iteration.d(1057):       
main.C.filter!((a) => a != 0).filter(Range)(Range range) if
(isInputRange!(Unqual!Range))



import std.algorithm;

alias filterZeros2 = filter!(a=>a!=0);

class C
{
    alias filterZeros = filter!(a=>a!=0);

    void doCount ( ) const
    {
        filterZeros([1,2,3]).count;  // fails
        filterZeros2([1,2,3]).count; // works
    }

    void doCount ( )
    {
        filterZeros([1,2,3]).count; // works
        filterZeros2([1,2,3]).count; // works
    }
}

void main() {}

--
Jan 30