News and problems about foreach loops

2012-11-03 Thread bearophile
(This post is not crystal clear because unfortunately now I don't have a lot of time to make it better, but I think it's acceptable.) In DMD 2.061 there will be some interesting changes, one of them regards the foreach loops. Foreach loops are everywhere in D code, it's one of the most used

Re: News and problems about foreach loops

2012-11-03 Thread Peter Alexander
On Saturday, 3 November 2012 at 14:04:45 UTC, bearophile wrote: A third solution is use idioms, and do not change D. It means that on default the programmer puts always a const in foreach. This avoids most bugs caused by fake Case3, and you don't use it in the uncommon true Cases3. There

Re: News and problems about foreach loops

2012-11-03 Thread Andrej Mitrovic
On 11/3/12, bearophile bearophileh...@lycos.com wrote: Now you can omit the type, this is very handy: struct Foo { int x; } void main() { auto data = [Foo(10), Foo(20), Foo(30)]; foreach (const f; data) {} } That's really cool that we have this now. But this error message needs

Re: News and problems about foreach loops

2012-11-03 Thread Andrej Mitrovic
On 11/3/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: It should be something like cannot modify const member x. In fact the error is already read but the else statement is not taken in Expression::checkModifiable: if (var var-storage_class STCctorinit) // goes here {

Re: News and problems about foreach loops

2012-11-03 Thread bearophile
Peter Alexander: I'm not a fan of introducing new keywords or introducing breaking changes in D code (even though I don't use Case3). I think this might just be something we have to live with, Using a custom property is maybe acceptable (this @copy doesn't need to be a built-in, probably