On Tuesday, 27 May 2014 at 18:54:05 UTC, H. S. Teoh via Digitalmars-d wrote:
Honestly, I don't see the need even for alpha-renaming -- I can't imagine a use case where you'd want to do something like that. I think
straight up hashing of the function body is Good Enough(tm).


T

Hashing the function body is not enough - you must also consider the closure!

    template Template(alias func){
        bool Template=func();
    }

    void foo(){
        int a;
writeln(Template!(()=>is(typeof(a) : char))); //prints "false"
    }

    void bar(){
        char a;
writeln(Template!(()=>is(typeof(a) : char))); //prints "true"
    }

If two delegates must have exactly the same scope, the usefulness of the hashing will be quite limited, but in many cases the same lambda can be declared in different scopes and still be the same. It all depends on how the lambda uses the closure - and checking this will be quite hard to implement...

Reply via email to