April 02, 2007 cleaner approach of variadic arg deduce, inspired by Jarrett Billingsley | ||||
---|---|---|---|---|
| ||||
the following is trying to deduce the variadic call to a chain of function call. the problem is only appeard on current DMD when deduce the last parameter type double it matches both this(float y,A a...) and this(float y) but actually it should just match this(float y) , and this would result the correct chain of calling. import std.stdio; import std.string; class A { static char[][] output; this(int x,A a...){ output~= format(`int`,x); } /* this(float x, A a...) { }*/ this(int x) { output~= format(`int`,x); } this(float x) { output~= format(`float`,x); } } void func(A a...) { foreach_reverse(k;a.output) { writef(k); } a.output.length = 0; } void main() { func(1,4,2.0); func(1,5,2.0); } |
Copyright © 1999-2021 by the D Language Foundation