Partially instantiating templates?

Magnus Lie Hetland magnus at hetland.org
Tue Feb 1 07:13:23 PST 2011


On 2011-02-01 16:00:16 +0100, Magnus Lie Hetland said:

>   import std.functional, std.stdio;
>   int f(int x) {return x;}
>   void main() {
>       alias unaryFun!("f(a)") g;
>       writeln(g(3));
>   }

Just to be clear -- I realize I could just have used unaryFun!f here 
(or just f, for that matter). The usage case was actually currying. I 
used "f(x,a)" as a compile-time argument to the kind of template that 
we discussed earlier. And the reason I tried that was that this didn't 
work either:

  import std.functional, std.stdio;
  int f(int x, int y) {return x;}
  void main() {
      alias unaryFun!(curry(f, 2)) g;
      writeln(g(3));
  }

At that point, the only thing that worked was using a lambda. And, as I 
pointed out, with the nested templates, that didn't work either.

Seems like the language (or the stdlib) is resisting my efforts at 
every turn here. Perhaps I should just write out those for-loops 
redundantly, rather than using templates ;)

-- 
Magnus Lie Hetland
http://hetland.org



More information about the Digitalmars-d-learn mailing list