On Saturday, 21 August 2021 at 06:58:47 UTC, Ali Çehreli wrote:
On 8/20/21 11:19 PM, Tejas wrote:
[...]
Yes. 'static foreach' does not introduce scope, which can be
pretty useful. For example, one can define functions at module
scope.
The subtle differences between 'static foreach' and
'(compile-time) foreach' can be surprising. For example, I
don't understand why I can't use
foreach (i; 0 .. members.length) {
enum ident = __traits(identifier, members[i]);
// ...
}
Error: variable `i` cannot be read at compile time.
I think it should be. :) members.length is compile-time; so,
'i' should be compile time.
And then, why can't 'static foreach' iterate over 'members'?
static foreach (member; members) {{
// ...
}}
Error: value of `this` is not known at compile time
Hm? Well, I am happy that there is always a path through. :)
Ali
Maybe it has something to do with that compile-time vs
compile-time thing by quickfur on the dlang wiki.
I was more impressed that you found that hack in the first place