What about this...

Aarti_pl aarti at interia.pl
Tue Jan 15 01:13:31 PST 2008


Any comments on this? Probably error, but maybe someone wants to add 
something...

--------

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();

BR
Marcin Kuszczak
(aarti_pl)


More information about the Digitalmars-d-learn mailing list