problem with template arguments deduction
Zhenya
zheny at list.ru
Wed May 30 22:45:15 PDT 2012
On Wednesday, 30 May 2012 at 22:19:53 UTC, Philippe Sigaud wrote:
> I don't see anything wrong per se. It's mainly that the
> compiler type
> extraction/deduction is not powerful enough to extract U in
> your case.
> You can help it a bit by using std.traits.ParameterTypeTuple:
>
> module test;
>
> import std.stdio;
> import std.traits;
> import std.typetuple;
>
> template Combination(alias indices,U...)
> {
> static if(is(typeof(indices) : int[]))
> {
> static if(indices.length > 1)
> alias
> TypeTuple!(U[indices[0]],Combination!(indices[1..$],U))
> Combination;
> else static if(indices.length == 1)
> alias U[indices[0]] Combination;
> }
> }
>
> template bind(alias indices)
> {
> static if(is(typeof(indices) : int[]))
> {
> auto bind(D,V...)(D dg, V values) if (is (D d == R
> delegate(U), R, U...) && is(V == Combination!(indices,
> ParameterTypeTuple!D)))
> {
> /* static if(indices.length > 1)
> return
> bind!(update!(indices,indices[0]))(Curry!(indices[0])(dg,values[0]),values[1..$]);
> else static if(indices.length == 1)
> return
> Curry!(indices[0])(dg,values[0]);
> */
>
> }
> }
> }
>
> void main()
> {
> void xyz(int x,int y,int z)
> {
> writeln("x = ",x," y = ",y," z = ",z);
> }
> // auto g = Curry!1(&xyz,cast(int)(1.1));
> // g(2,3);
> alias Combination!([0,1],int,int,int) Arg;
> Arg a;
> writeln(Arg.stringof);
> bind!([0,1])(&xyz,a);
> //readln();
> }
Thank you very much:)
More information about the Digitalmars-d-learn
mailing list