Subtyping of an enum

Anton Fediushin fediushin.anton at yandex.com
Mon Apr 15 10:15:50 UTC 2019


On Monday, 15 April 2019 at 10:00:36 UTC, Alex wrote:
> On Monday, 15 April 2019 at 08:39:24 UTC, Anton Fediushin wrote:
>> [snip]
>
> Otherwise, you could alwas define fun as
>
> ´´´
> void fun(Enum.internal e) {}
> ´´´
>
> but I assume, you want to avoid especially this.
>
> In favor of my first proposition, also speaks the fact, that 
> Enum.foo is somewhat awkward w.r.t. your question, as you treat 
> the internal enum as a static member. Was this intended?

Enum.internal is private to make it inaccessible from any other 
place. All I want is a way to have an enum that I could extend 
with my own methods.

Something to make the following code work:
```
Enum a = Enum.foo;
Enum b = Enum.bar;
assert(a == Enum.foo);
assert(a < b);
assert(a.toString == "FOO");
assert(b.toString == "BAR");
writeln(a); // FOO
writeln(b); // BAR
```




More information about the Digitalmars-d-learn mailing list