Enum literals, good? bad? what do you think?
Walter Bright
newshound2 at digitalmars.com
Wed Jul 21 06:19:20 UTC 2021
On 7/20/2021 8:10 PM, Mathias LANG wrote:
> struct Foo
> {
> enum Bar { A, B, }
>
> void func () {
> assert(A == 0); // Should it work ?
If you want anonymous enums, use:
enum { A, B }
> assert(.A == 0); // Or should it be this ?
Then you'd have no way to access a module scope symbol with the same name.
> // The above currently refers to the `struct A`.
> }
> }
>
> struct A {}
> ```
>
> The only time I had found enums to be too verbose is in switch statements.
> As mentioned previously, `switch (value) with `(EnumType)` helps.
Yup.
> I think we should make it the default (essentially `case`s should be in a `with
> (typeof(value))` scope), and that would alleviate most of the pain.
Sorry, I'm not understanding the pain.
More information about the Digitalmars-d
mailing list