On Sunday, 14 June 2020 at 15:44:04 UTC, Ali Çehreli wrote:
On 6/14/20 7:43 AM, Denis wrote:> @Kagamin:
>
> On Sunday, 14 June 2020 at 07:16:18 UTC, Kagamin wrote:
>> parameters[param]=Parameter();
>
> I did not realize that you can use a type on the RHS of an
assignment,

Note that it's not just the type but with parenthesis after it. For example, Foo() default-constructs an object of Foo.

Got it.

> There does not appear to be a way to loop over the elements
of an enum,

There is std.traits.EnumMembers:

import std.traits;

enum Foo { abc, xyz }

void main() {
  foreach (foo; EnumMembers!Foo) {
    // ...
  }
}

Excellent. Because all of the keys are immutable strings and are known at compile time, enum seems like it should be well suited for the job. I will try this too.

On a side note: I am working my way through your book, Ali. It really is very helpful for learning D, and for pointing out things that are not always clear from reading the documentation alone. I will admit, however, that I am not able to absorb all of the more subtle aspects yet. So this is an iterative process (read some, write code, re-read and read some more, write code, ...)

Thank you for your help.

Reply via email to