Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
January 06, 2007 [Issue 798] New: Template function overloading problems | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=798 Summary: Template function overloading problems Product: D Version: 1.00 Platform: Other OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: aarti@interia.pl class Test { static void func(T)(T v) {} // static void func() {} //Error! Solution: static void func()() {} // static void func(int i, float f) {} //Error! Solution: static void func()(int i, float f) {} static void opCall(T)(T t) {} static void opCall()() {} //Below line in fact conflicts with opCall()() as commenting it solves problem - no workaround known //static void opCall()(int i, float f) {} } void main() { } -- |
January 06, 2007 Re: [Issue 798] New: Template function overloading problems | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | d-bugmail@puremagic.com wrote: > http://d.puremagic.com/issues/show_bug.cgi?id=798 > > Summary: Template function overloading problems > Product: D > Version: 1.00 > Platform: Other > OS/Version: Linux > Status: NEW > Severity: normal > Priority: P2 > Component: DMD > AssignedTo: bugzilla@digitalmars.com > ReportedBy: aarti@interia.pl > > > class Test { > static void func(T)(T v) {} > // static void func() {} //Error! Solution: static void > func()() {} > // static void func(int i, float f) {} //Error! Solution: static void > func()(int i, float f) {} > > static void opCall(T)(T t) {} > static void opCall()() {} > //Below line in fact conflicts with opCall()() as commenting it solves > problem - no workaround known > //static void opCall()(int i, float f) {} > > } > > void main() { > } > > > -- By mistake I left only static functions in example, but the problem occurs for every function. -- Regards Marcin Kuszczak (Aarti_pl) ------------------------------------- Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl) Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/ ------------------------------------- |
January 06, 2007 Re: [Issue 798] New: Template function overloading problems | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | Template functions cannot be overloaded with normal functions. This is by design. d-bugmail@puremagic.com wrote: > > class Test { > static void func(T)(T v) {} > // static void func() {} //Error! Solution: static void > func()() {} > // static void func(int i, float f) {} //Error! Solution: static void > func()(int i, float f) {} static void func(T)(T v) {} static void func()() {} static void func(T1=void, T2=void)() {} > static void opCall(T)(T t) {} > static void opCall()() {} > //Below line in fact conflicts with opCall()() as commenting it solves > problem - no workaround known > //static void opCall()(int i, float f) {} Same as above. Templates with the same name and same number of templates parameters cannot be overloaded unless one is a specialization of the other. ie. static void func(T, U)(T v1, U v2) {} static void func(T, U)(T v1, U v2, int v3) {} Doesn't work. But: static void func(T, U)(T v1, U v2) {} static void func(T, U : double)(T v1, U v2, int v3) {} Works. The way around this problem is to add dummy template parameters to alter the template parameter count to avoid unwanted collisions: static void func(T, U)(T v1, U v2) {} static void func(T, U, V=void)(T v1, U v2, int v3) {} In the above, V is unused and serves only to change the name mangling of the second template function. Sean |
January 06, 2007 Re: [Issue 798] New: Template function overloading problems | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Sean Kelly wrote: > Template functions cannot be overloaded with normal functions. This is by design. Maybe it should be reported as enhancement? It's quite unnatural thing... Additionally I was thinking that maybe all functions should be mangled with return type... In such a situation it would be possible to overload functions by return type and overloading template functions with normal functions would be no more problem... PS. If I am wrong about some of these issues just tell me. I am not trying to play expert here - just reporting some awkward (IMHO) behaviour of compiler.... -- Regards Marcin Kuszczak (Aarti_pl) ------------------------------------- Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl) Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/ ------------------------------------- |
February 03, 2007 [Issue 798] Template function overloading problems | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=798 bugzilla@digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #4 from bugzilla@digitalmars.com 2007-02-02 22:35 ------- Sean's comments are correct. It is by design. -- |
Copyright © 1999-2021 by the D Language Foundation