On 8/20/21 11:19 PM, Tejas wrote:
On Saturday, 21 August 2021 at 06:03:33 UTC, Ali Çehreli wrote:
On 8/20/21 10:37 PM, Alexandru Ermicioi wrote:
[...]

Cool! Much better. :)

I could not do

[...]

Did you use that double curly bracket in `static foreach` so that you don't get error for declaring stuff inside `static foreach` ?

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


Reply via email to