Implicit enum conversions are a stupid PITA

bearophile bearophileHUGS at lycos.com
Sun Mar 28 15:54:20 PDT 2010


Andrei Alexandrescu:
> What I think this is lacking is the ability to 
> predefine flags that are a combination of other flags. For example, some 
> file open flags could define DEFAULT_READ as READ|SHARED. I'm not sure 
> how to express that.

It's not an enum, it's a struct, that contains a single value (for example an uint).
The construct defines at compile-time a property for each given name.
Then the assign operator tests that the input can be any of the possible ORs of the flags, otherwise asserts in not release mode.
So I think it can be done. But it will come out a good amount of CTFE code.

Bye,
bearophile



More information about the Digitalmars-d mailing list