Patterns for functions in template parameters

Max Samukha via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 24 10:07:59 PDT 2014


On Friday, 24 October 2014 at 14:13:10 UTC, ketmar via 
Digitalmars-d-learn wrote:

> sorry if this is not what you mean, template magic sometimes 
> scares me
> and i'm loosing my mind. ;-)

What I meant was your example with the delegate parameter moved 
to the template list:

template Foo(T delegate(U) a, T, U) {}
Foo!((int x) => true); // T == bool, U == int


Or generalized to functions (and maybe "functors" in the 
unfortunate C++ sense):

template Foo(T(U) a, T, U) {}


Apparently, D doesn't allow type variables in value parameters at 
all.















More information about the Digitalmars-d-learn mailing list