Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 28, 2005 Properties as template value parameters | ||||
---|---|---|---|---|
| ||||
Seems to be an order-of-evaluation bug. Fails to compile on DMD 0.140, Windows. -------------- template cat(int n) { const int dog = n; } const char [] bird = "canary"; const int sheep = cat!(bird.length).dog; int main() { return 0; } -------------- bug.d(9): no property 'length' for type 'char[]' ---------------- |
November 28, 2005 Re: Properties as template value parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | "Don Clugston" <dac@nospam.com.au> wrote in message news:dmef15$1nll$1@digitaldaemon.com... > Seems to be an order-of-evaluation bug. > Fails to compile on DMD 0.140, Windows. > > -------------- > template cat(int n) > { > const int dog = n; > } > > const char [] bird = "canary"; > > const int sheep = cat!(bird.length).dog; Works if you cast bird to char[]: const int sheep = cat!((cast(char[])bird).length).dog; printf("%d\n", sheep); // prints '6' > > int main() { return 0; } > -------------- > bug.d(9): no property 'length' for type 'char[]' > ---------------- |
November 28, 2005 Re: Properties as template value parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | John C wrote: > "Don Clugston" <dac@nospam.com.au> wrote in message news:dmef15$1nll$1@digitaldaemon.com... > >>Seems to be an order-of-evaluation bug. >>Fails to compile on DMD 0.140, Windows. >> >>-------------- >>template cat(int n) >>{ >> const int dog = n; >>} >> >>const char [] bird = "canary"; >> >>const int sheep = cat!(bird.length).dog; > > > Works if you cast bird to char[]: > > const int sheep = cat!((cast(char[])bird).length).dog; > > printf("%d\n", sheep); // prints '6' Indeed, many minor changes will let it compile, eg const int sheep = cat!((""~ bird).length).dog; and const int pig = bird.length; const int sheep = cat!(pig).dog; (I got sick of a,b,c in bug reports, from now on I'll use animals :-) Of course insects would be more appropriate). > > >>int main() { return 0; } >>-------------- >>bug.d(9): no property 'length' for type 'char[]' >>---------------- > > > |
December 04, 2005 Re: Properties as template value parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston Attachments: | Don Clugston schrieb am 2005-11-28: > Seems to be an order-of-evaluation bug. > Fails to compile on DMD 0.140, Windows. > > -------------- > template cat(int n) > { > const int dog = n; > } > > const char [] bird = "canary"; > > const int sheep = cat!(bird.length).dog; > > int main() { return 0; } > -------------- > bug.d(9): no property 'length' for type 'char[]' > ---------------- Added to DStress as http://dstress.kuehne.cn/run/t/template_22.d http://dstress.kuehne.cn/run/t/template_class_15.d http://dstress.kuehne.cn/run/t/template_struct_06.d Thomas |
Copyright © 1999-2021 by the D Language Foundation