digitalmars.D.learn - overloading function with function templates
- mstrlu (33/33) Dec 27 2007 Hello,
- Bill Baxter (7/10) Dec 27 2007 I couldn't find it written down anywhere in the docs, but it is
- Jarrett Billingsley (6/9) Dec 27 2007 You can't do it. Yet. ;)
- BCS (5/11) Dec 27 2007 IIRC you can overload a template with some template args and a template ...
Hello, I just discovered that its not possible to write a function template with the same identifier as an existing function ( even though the function arguments are different ): import std.stdio; void test(int x)( int y ){ writefln( "tmpl:", x, " val:", y); } int test(){ return 15; } int main(){ writefln( test() ); test!(2)(3); return 0; } with gdc 0.24 or dmd 1.023 I get "template_test.d(8): function template_test.test conflicts with template template_test.test(int x) at template_test.d(4)" in c++ this doesn't seem to be a problem: #include <iostream> using namespace std; template < int x > void test( int y ){ cout << "tmpl:" << x << " val:" << y << endl; } int test(){ return 15; } int main(){ cout << test() << endl; test<2>( 3 ); } works fine. Isn't it possible to resolve the function templates before checking for ambiguous identifiers in D? Is there something in the documetation on this subject that I did miss? thank you
Dec 27 2007
mstrlu wrote:Hello, I just discovered that its not possible to write a function template with the same identifier as an existing function ( even though the function arguments are different ):I couldn't find it written down anywhere in the docs, but it is definitely a well-known limitation of D templates. Another major one is that implicit instantiation is an all-or-nothing business. If you specify any template parameter you must specify them all. And finally you can't overload across modules. Yet. --bb
Dec 27 2007
"Bill Baxter" <dnewsgroup billbaxter.com> wrote in message news:fl1har$ihp$1 digitalmars.com...I couldn't find it written down anywhere in the docs, but it is definitely a well-known limitation of D templates.You can't do it. Yet. ;) Remember this is something else that was mentioned in the D con slides for D2.And finally you can't overload across modules. Yet.I thought overload sets were already implemented in the D2 compiler?
Dec 27 2007
Reply to mstrlu,Hello, I just discovered that its not possible to write a function template with the same identifier as an existing function ( even though the function arguments are different ): import std.stdio;IIRC you can overload a template with some template args and a template with no args int Foo(T)(T arg){...} int Foo()(int a, int b){...}
Dec 27 2007