D - functions, delegates and templates
- Carlos Santander B. (33/33) Mar 05 2003 I have never used delegates in my life. Now I'm trying to start with D. ...
I have never used delegates in my life. Now I'm trying to start with D. I
think this should be legal:
template gen (T) {
T max (T a,T b) {
return (a>b?a:b);
}
bit comp(T a,T b,T delegate (T,T) f) { /*************/
return a==f(a,b);
}
}
instance gen(int) intGen;
instance gen(real) realGen;
instance gen(char[]) strGen;
void main() {
int a=45,b=32;
real c=-12.3,d=2.4;
char[] e='hola',f='chao';
intGen.comp(a,b,intGen.max);
realGen.comp(c,d,realGen.max);
strGen.comp(e,f,strGen.max);
}
If I change delegate for function in the comp function, it doesn't work
either. Both ways, I get non-matching arguments. Is the code correct or am I
missing something?
The workaround that I've tried was to declare as a function, and also
declare 3 function pointers in main pointing to each max function, but I
think there must be another way to do it.
-------------------------
Carlos Santander
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 2003-02-25
Mar 05 2003








"Carlos Santander B." <carlos8294 msn.com>