enum inheritance?

Ary Manzana ary at esperanto.org.ar
Sun Aug 14 14:47:18 PDT 2011


On 8/13/11 9:42 PM, Simen Kjaeraas wrote:
> On Sun, 14 Aug 2011 01:15:29 +0200, mimocrocodil <4denizzz at gmail.com>
> wrote:
>
>> Hi!
>>
>> I am want to extend available enum to provide more items to them.
>>
>> How I can do this job without manual copying of exsisting enum items?
>
> If what you want is a new enum that contains the values of an existing
> enum,
> with some additions, this code will do it:
>
>
> string EnumDefAsString(T)() if (is(T == enum)) {
> string result = "";
> foreach (e; __traits(allMembers, T)) {
> result ~= e ~ " = T." ~ e ~ ",";
> }
> return result;
> }
>
> template ExtendEnum(T, string s) if (is(T == enum) &&
> is(typeof({mixin("enum a{"~s~"}");}))) {
> mixin("enum ExtendEnum {" ~
> EnumDefAsString!T() ~ s ~
> "}");
> }

Has D considered introducing string interpolation? That looks very hard 
to read...


More information about the Digitalmars-d-learn mailing list