What about this...

Bjoern nanali at nospam-wanadoo.fr
Tue Jan 15 02:22:07 PST 2008


Aarti_pl schrieb:
> 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)

Sorry untested and just an idea :(
What happens when you use :
T pattern(T)(out T t) {return t;}
instead of
T pattern(T)() {return T.init;}

Bjoern


More information about the Digitalmars-d-learn mailing list