Bug 1789 – Template overloading doesn't work

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2008-01-17T03:45:00Z
Last change time
2014-02-24T15:32:06Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
aarti

Comments

Comment #0 by aarti — 2008-01-17T03:45:52Z
void pattern(T)(T v) {} T pattern(T)() {return T.init;} void main() { pattern!(int)(5); } --------- Above code results in compile time error: quicktest.d(6): template instance pattern!(int) matches more than one template declaration, pattern(T) and pattern(T) quicktest.d(6): Error: template instance 'pattern!(int)' is not a variable quicktest.d(6): Error: function expected before (), not pattern!(int) of type int --------- As you see it is standard D setter/getter approach with templates. What's more interesting, when we call pattern template function with IFTI it calls proper function: pattern(5); //calls setter but: pattern; // is error BTW: I hope that in DMD 2.0 writefln; will be also allowed. Currently it doesn't work - you have to write writefln(); Ref: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=10766 Similar to: #1193
Comment #1 by bugzilla — 2008-08-29T00:29:41Z
That's the way it is designed to work, overloading of templates with the template arguments overloads based on only the template argument list. You can achieve what you wish with the following: template pattern(T) { void foo(T v) {} T foo() { return T.init; } } alias pattern!(int).foo bar; void main() { pattern!(int).foo(5); pattern!(int).foo = 5; int x = pattern!(int).foo; bar = 5; int y = bar; }