Enum inheritance
Matthias Walter
walter at mail.math.uni-magdeburg.de
Wed Aug 15 11:13:09 PDT 2007
Witold Baryluk Wrote:
> Dnia Wed, 15 Aug 2007 13:12:57 -0400
> Matthias Walter <walter at mail.math.uni-magdeburg.de> napisa³/a:
>
> > For my current project, I would be happy to have some kind of enum
> > inheritance, is it on the plan for future changes to D?
> >
> > Syntactically, it should only be an extension to the specification of
> > an enum base type via
> >
> > enum Name : Base { Symbols, ... }
> >
> > Why not allow other enums as a Base to import their symbols? As long
> > as one does not think about multiple inheritance (or enum-interfaces
> > <g>), this shouldn't be problem?! Or is it already implemented and I
> > missed something?
> >
> > best regards
> > Matthias
>
> import std.stdio;
> import std.traits;
>
> string Ehelper(string[] es) {
> char[] r;
> for (int i = 0; i < es.length; i++) {
> if (i) r ~= ", ";
> r ~= es[i];
> }
> return r;
> }
> template EE(E0a, E0b) {
> const EE = "enum E3 { "~Ehelper(__traits(allMembers, E0a)) ~ ",
> " ~ Ehelper(__traits(allMembers, E0b)) ~ " }"; }
>
> enum E1 {
> A, B, C
> }
>
> enum E2 {
> E, F, G
> }
>
> mixin(EE!(E1, E2));
>
> void main(char[][] args) {
> writefln(E3.A);
> writefln(E3.F);
> }
Can I do the following conversion with your code?
E2 bla = E2.E;
E3 foo = bla;
best regards
Matthias
More information about the Digitalmars-d
mailing list