March 28 Re: Setting up a final switch from a list | ||||
---|---|---|---|---|
| ||||
Posted in reply to Salih Dincer | On Thursday, March 28, 2024 4:21:03 PM MDT Salih Dincer via Digitalmars-d- learn wrote: > How can we add all members of an enum type to a list without duplicating code? As the documentation for EnumMembers explains, you can use std.meta.NoDuplicates to strip out duplicates if you want to do something like generate a switch statement from the list of enum members. https://dlang.org/phobos/std_traits.html#EnumMembers - Jonathan M Davis |
March 29 Re: Setting up a final switch from a list | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Friday, 29 March 2024 at 00:37:21 UTC, Jonathan M Davis wrote:
> On Thursday, March 28, 2024 4:21:03 PM MDT Salih Dincer via Digitalmars-d- learn wrote:
>> How can we add all members of an enum type to a list without duplicating code?
>
> As the documentation for EnumMembers explains, you can use std.meta.NoDuplicates to strip out duplicates if you want to do something like generate a switch statement from the list of enum members.
>
> https://dlang.org/phobos/std_traits.html#EnumMembers
>
> - Jonathan M Davis
I guess this falls into metaprogramming. Maybe we should expect this possibility from IDEs because I've seen something like this in VScode. All enum members were added automatically.
SDB@79
|
Copyright © 1999-2021 by the D Language Foundation