enum inheritance
JS
js.mdnq at gmail.com
Mon Jul 15 06:01:04 PDT 2013
On Monday, 15 July 2013 at 11:00:59 UTC, Dicebot wrote:
> On Monday, 15 July 2013 at 04:24:59 UTC, JS wrote:
>> ...
>
> I think closest solution you can get is having bunch of private
> enum definitions and combining them into single public one via
> compile-time reflection. Something like
> "mixin(generateEnum!(Red, Green, blue))".
That might solve the partitioning problem and solve part of the
hierarchical problem but won't allow submember access, e.g.,
colors.red.redorange. It seems like a good start though.
I imagine one could potentially build up a set of nested struct
with immutable members representing the enums:
final immutable struct Colors
{
final immutable struct Red
{
private immutable int _Red = 10000;
immutable int RedOrange = 10001;
alias _Red this; // obviously doesn't work
}
final immutable struct Green
{
immutable int Green = 20000;
}
}
but with the glitch on the alias(Colors.Red doesn't work)...
which sort of throws a kink in the solution making more than a
2-deep nest useless.
More information about the Digitalmars-d-learn
mailing list