Patterns for functions in template parameters

Max Samukha via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Oct 23 11:28:04 PDT 2014


On Thursday, 23 October 2014 at 11:25:01 UTC, Kagamin wrote:
> Maybe, argument deduction?
>
> template Foo(T: T[U], U)
> {
>     ...
> }
>
> Foo!(int[long])  // instantiates Foo with T set to int, U set 
> to long

Yes, but for a value template parameter.

template Foo(int[long] a);
{
}
Foo!([1: 2]); // ok, this passes.


Now I'd like to loosen the template so it accepts AAs of any type:

template Foo(T[U] a /* forall T, U */)
{
}


And then unary functions of any type:

template Foo(T a(U) /* forall T, U */)
{
}


In other words, to move the run-time parameter below to the 
template parameter list:

void foo(T, U)(T delegate(U) a)
{
}


Or in other other words (for any "callables"):

template Foo(alias a) if (isCallable!a && ParameterTypes!a.length 
== 1)
{
     alias T = ReturnType!a;
     alias U = ParameterTypes!a[0];
}


I vaguely remember some syntax tweaks were introduced, presumably 
for that effect. Trying to find out what they were exactly. I 
might have dreamt it as well.









More information about the Digitalmars-d-learn mailing list