Passing anonymous templated functions as template parameters

pineapple via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 15 15:27:38 PDT 2016


Here's a simple code example to illustrate what I expected to 
work and didn't - is this a mistake in my syntax or a limitation 
of the language?

     template SomeTemplate(alias func){
         auto templatefunc(T)(int x){
             return func!T(x);
         }
     }

     // Valid
     auto somefunc(T)(int x){
         return cast(T) x;
     }
     alias fn1 = SomeTemplate!somefunc;

     // Not valid
     alias fn2 = SomeTemplate!(
         (T)(int x){return cast(T) x;}
     );


More information about the Digitalmars-d-learn mailing list