[Issue 1789] New: Template overloading doesn't work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 17 01:45:53 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1789

           Summary: Template overloading doesn't work
           Product: D
           Version: 1.025
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: aarti at interia.pl


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


-- 



More information about the Digitalmars-d-bugs mailing list