Strongly typed enums

Adam D. Ruppe destructionator at gmail.com
Thu Aug 25 18:59:16 PDT 2011


bearophile wrote:
> Why do you suggest to disallow implicit conversions (and use strong
> typing) only if the enum definition doesn't specify a base type?

With a base type, it looks like inheritance, so I expect some
implicit conversions are allowed.

class A : Base {}
Base a = new A(); // allowed

enum ENUM : int {}
int a = ENUM.something; // same deal? i think so


> I think I am not able to do that yet.

You should try - the compiler isn't too hard, and github isn't
bad once you've done it once. So then you'll be able to try
these proposed features and it's easier to get a patch accepted
than to hope Walter does it all.

>  In some cases it's good to replace cast() with a to!.

I use to a lot with enums. It's really convenient how it
goes to and from string based on the member name.

I don't think I've ever actually tried to! with int!


More information about the Digitalmars-d mailing list