January 09, 2018 Re: Is old style compile-time foreach redundant? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Wed, Jan 10, 2018 at 12:18:46AM +0100, Timon Gehr via Digitalmars-d-learn wrote: > On 09.01.2018 22:04, H. S. Teoh wrote: > > if (0 == 3) {} > > // all subsequent iterations deleted > > > > because the static break is unconditionally compiled (it has nothing to do with the runtime branch). You'd have to use static if to make it conditionally-compiled and thus not instantly aborting the loop. > > > > Such semantics would be logically consistent, but unfortunately rather counterintuitive at first glance. > > I think "if (0 == 3) { static break; }" should be a compile-time error. That's also a possible solution, perhaps a better solution than what I described. Make it so that static break/continue cannot be nested inside runtime conditionals. That should exclude all of the pathological cases, hopefully. T -- The diminished 7th chord is the most flexible and fear-instilling chord. Use it often, use it unsparingly, to subdue your listeners into submission! |
January 10, 2018 Re: Is old style compile-time foreach redundant? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Tuesday, 9 January 2018 at 23:27:42 UTC, H. S. Teoh wrote: > On Wed, Jan 10, 2018 at 12:18:46AM +0100, Timon Gehr via Digitalmars-d-learn wrote: >> On 09.01.2018 22:04, H. S. Teoh wrote: >> > [...] >> >> I think "if (0 == 3) { static break; }" should be a compile-time error. > > That's also a possible solution, perhaps a better solution than what I described. Make it so that static break/continue cannot be nested inside runtime conditionals. That should exclude all of the pathological cases, hopefully. > > > T FWIW I recently bumped into a problem where `static break` would be _really_ useful: https://github.com/dlang/dmd/pull/7577#discussion_r159175229 |
January 12, 2018 Re: Is old style compile-time foreach redundant? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Sunday, 7 January 2018 at 02:17:02 UTC, Stefan Koch wrote: > On Sunday, 7 January 2018 at 01:08:44 UTC, H. S. Teoh wrote: >> On Sun, Jan 07, 2018 at 12:55:27AM +0000, Stefan Koch via Digitalmars-d-learn wrote: >>> On Saturday, 6 January 2018 at 23:25:58 UTC, Ali Çehreli wrote: >>> > Is 'static foreach' sufficient for all needs or is there any value for regular foreach over compile-time sequences? >> [...] >>> No it's not. >>> When you can use the old style do so. Since it puts less stress on the >>> compiler in the general case. >> >> Really? Based on a recent post by Jonathan Davis, the new static foreach actually runs faster in certain use cases. >> >> >> T > > That might be true. > If you are hitting some constant factor, however the big-o for static foreach is worse then for tuple foreach. FWIW there isn't any measurable performance penalty / difference. We moved to use static foreach on Phobos recently: https://github.com/dlang/phobos/pull/5989 |
Copyright © 1999-2021 by the D Language Foundation