template instantiation --- having trouble therewith
John Colvin
john.loughran.colvin at gmail.com
Tue Sep 3 03:38:11 PDT 2013
On Tuesday, 3 September 2013 at 03:49:52 UTC, Carl Sturtivant
wrote:
>
> template Dptr( T, U...) {
> alias T delegate( U args) Dptr;
> }
>
> Dptr!(T,U) muddle( T, U...)( Dptr!(T,U) f) {
> return f; //or make another delegate in real code
> }
>
>
> unittest {
> import std.stdio;
> int x = 3;
> int scale( int s) { return x * s; }
> Dptr!(int,int) f = muddle( &scale);
> writeln( f(7));
> }
> ============================================
>
> The above technique seemed natural to me, but I get this
> message from dmd:
>
> p1.d(15): Error: template p1.muddle does not match any function
> template declaration. Candidates are:
> p1.d(7): p1.muddle(T, U...)(Dptr!(T, U) f)
> p1.d(15): Error: template p1.muddle(T, U...)(Dptr!(T, U) f)
> cannot deduce template function from argument types !()(int
> delegate(int))
>
> and if I use muddle!(int,int) instead it doesn't help. This is
> likely a misunderstanding on my part --- please show me how to
> sort this out.
I'm confused as to what you're trying to do... your example code
is equivalent to
import std.stdio;
int x = 3;
int scale( int s) { return x * s; }
auto f = &scale;
writeln( f(7) );
More information about the Digitalmars-d-learn
mailing list