Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
February 11, 2005 Limited and easy template argument deduction | ||||
---|---|---|---|---|
| ||||
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. |
February 12, 2005 Re: Limited and easy template argument deduction | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | 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>. |
February 12, 2005 Re: Limited and easy template argument deduction | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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'... :-)
|
February 14, 2005 Re: Limited and easy template argument deduction | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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.
|
February 14, 2005 Re: Limited and easy template argument deduction | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | >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?
|
Copyright © 1999-2021 by the D Language Foundation