Initializing an associative array of struct

Ali Çehreli acehreli at yahoo.com
Sun Jun 14 15:44:04 UTC 2020


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.

 > 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) {
     // ...
   }
}

Ali



More information about the Digitalmars-d-learn mailing list