Thread overview | |||||
---|---|---|---|---|---|
|
April 06, 2014 How to obtain a list of all the elements of an enum? | ||||
---|---|---|---|---|
| ||||
If I have an enum: enum x {A : 1, B : 2, C : 100}; How can I get a list of all of its elements? x.get_list() (returns [A, B, C]) |
April 06, 2014 Re: How to obtain a list of all the elements of an enum? | ||||
---|---|---|---|---|
| ||||
Posted in reply to dnspies | On Sunday, 6 April 2014 at 02:18:57 UTC, dnspies wrote: > If I have an enum: > > enum x {A : 1, B : 2, C : 100}; > > How can I get a list of all of its elements? > > x.get_list() (returns [A, B, C]) I believe this is what you're looking for: http://stackoverflow.com/questions/22577000/how-to-iterate-over-enums |
April 06, 2014 Re: How to obtain a list of all the elements of an enum? | ||||
---|---|---|---|---|
| ||||
Posted in reply to dnspies | On Sunday, 6 April 2014 at 02:18:57 UTC, dnspies wrote: > If I have an enum: > > enum x {A : 1, B : 2, C : 100}; > > How can I get a list of all of its elements? > > x.get_list() (returns [A, B, C]) EnumMembers (http://dlang.org/phobos/std_traits.html#EnumMembers) should do what you need. It will give you a compile-time tuple of all the members of your tuple. Depending on what you are doing, you may or may not want to place them into an array "[EnumMembers!x]". |
Copyright © 1999-2021 by the D Language Foundation