digitalmars.D - template arguments deduction
- Maagar (16/16) May 19 2004 Right now D does not support template argument deduction, so its interes...
- Daniel Horn (10/34) May 19 2004 you could alias it for all your types
- Genki Takiuchi (21/58) May 19 2004 Hi.
- Norbert Nemec (5/9) May 20 2004 Personally, I believe that can is worth opening. Expression templates in...
- hellcatv hotmail.com (5/14) May 20 2004 the most useful place is clearly operator overloading
Right now D does not support template argument deduction, so its interesting if this feature is planned at all? In C++ compiler can guess types and automatically instantiate template, it would be very nice to have this feature in D. example (c++): template <typename T> void foo(T arg) { } .. f(5); f(5.0); f('c'); while in D it would be something like: TFoo!(int).f(5); TFoo!(float).f(5.0); TFoo!(char).f('c');
May 19 2004
you could alias it for all your types alias TFoo(int) foo; alias TFoo(float) foo; alias TFoo(char) foo; but then you're back to C++ template instantiation madness I agree it makes userland code a bit messy to have the !() everywhere when you wish the compiler would instantiate it for you-- but it is also a big can of worms with respect to overload resolution and so forth I suspect Maagar wrote:Right now D does not support template argument deduction, so its interesting if this feature is planned at all? In C++ compiler can guess types and automatically instantiate template, it would be very nice to have this feature in D. example (c++): template <typename T> void foo(T arg) { } .. f(5); f(5.0); f('c'); while in D it would be something like: TFoo!(int).f(5); TFoo!(float).f(5.0); TFoo!(char).f('c');
May 19 2004
Hi. If compiler found the code like this: Foo!(arg1); Foo!(arg1, arg2); it is easy to interpret automatically like this: Foo!(typeof(arg1)).Foo(arg1); Foo!(typeof(arg1), typeof(arg2)).Foo(arg1, arg2); So, how about introducing new statement for template functions like this? // template function definition template(T1, T2) void func(T1 arg1, T2 arg2){ ... } // this is automatically interpreted as: // template func(T1, T2) { // void func(T1 arg1, T2 arg2) { ... } // } // call template function func!(arg1, arg2); // this is automatically interpreted as: // func!(typeof(arg1), typeof(arg2)).func(arg1, arg2); thank you. Daniel Horn wrote:you could alias it for all your types alias TFoo(int) foo; alias TFoo(float) foo; alias TFoo(char) foo; but then you're back to C++ template instantiation madness I agree it makes userland code a bit messy to have the !() everywhere when you wish the compiler would instantiate it for you-- but it is also a big can of worms with respect to overload resolution and so forth I suspect Maagar wrote:Right now D does not support template argument deduction, so its interesting if this feature is planned at all? In C++ compiler can guess types and automatically instantiate template, it would be very nice to have this feature in D. example (c++): template <typename T> void foo(T arg) { } .. f(5); f(5.0); f('c'); while in D it would be something like: TFoo!(int).f(5); TFoo!(float).f(5.0); TFoo!(char).f('c');
May 19 2004
Daniel Horn wrote:I agree it makes userland code a bit messy to have the !() everywhere when you wish the compiler would instantiate it for you-- but it is also a big can of worms with respect to overload resolution and so forth I suspectPersonally, I believe that can is worth opening. Expression templates in C++ absolutely depend on this feature, and there are many other places where it is far more than a minor syntax nuissance to type the !() stuff before every call.
May 20 2004
the most useful place is clearly operator overloading because there's no way you can do a*!(typeof(b)) b (that's not valid syntax even) In article <c8hmdr$29ko$1 digitaldaemon.com>, Norbert Nemec says...Daniel Horn wrote:I agree it makes userland code a bit messy to have the !() everywhere when you wish the compiler would instantiate it for you-- but it is also a big can of worms with respect to overload resolution and so forth I suspectPersonally, I believe that can is worth opening. Expression templates in C++ absolutely depend on this feature, and there are many other places where it is far more than a minor syntax nuissance to type the !() stuff before every call.
May 20 2004