digitalmars.D - Limited and easy template argument deduction
- Russ Lewis (25/25) Feb 11 2005 I have an idea for how you could do template parameter deduction (to
- Walter (2/2) Feb 11 2005 While your idea is a good one and will work, if D gets implicit argument
- Norbert Nemec (2/4) Feb 12 2005 Hopefully, this 'if' is not too far away from a 'when'... :-)
- Russ Lewis (8/10) Feb 14 2005 Having watched D grow, I'm not surprised. :) However, is it fair to
- Matthias Becker (1/3) Feb 14 2005 Do you already have any ideas?
I have an idea for how you could do template parameter deduction (to make it easy to call template functions) that would not require any compiler complexity. Let's define a special case. If your: * function name matches the name of the template * argument count in the function is greater than or equal to the parameter count of the template * the first n arguments of the function take exactly the template parameters, in order Then the template's parameters are assumed to be typeof() the various arguments. For example, the code below would be legal: template foo(T1,T2) void foo(T1 dg1,T2 dg2, int val3) { writefln("val1 = ", dg1()); writefln("val2 = ", dg2()); writefln("val3 = ", val3); } void main() { int func1() { return 1; }; int func2() { return 2.0; }; foo(&func1, &func2, 100); } The call in main() would be equivalent to this line: foo!(typeof(&func1),typeof(&func2))(&func1, &func2, 100); This wouldn't require hardly any compiler complexity, and yet would make D's templates far easier to use.
Feb 11 2005
While your idea is a good one and will work, if D gets implicit argument deduction, it will be better than C++'s instead of limited <g>.
Feb 11 2005
Walter wrote:While your idea is a good one and will work, if D gets implicit argument deduction, it will be better than C++'s instead of limited <g>.Hopefully, this 'if' is not too far away from a 'when'... :-)
Feb 12 2005
Walter wrote:While your idea is a good one and will work, if D gets implicit argument deduction, it will be better than C++'s instead of limited <g>.Having watched D grow, I'm not surprised. :) However, is it fair to assume that the special case I described will at least be a subset of the final design? If so, IMHO, it would be good to implement at least this little bit now because it would be easy to do but would have substantial positive impact. If, however, you're not yet certain that the final design would work like this subset, then I understand holding off.
Feb 14 2005
While your idea is a good one and will work, if D gets implicit argument deduction, it will be better than C++'s instead of limited <g>.Do you already have any ideas?
Feb 14 2005