Allow static methods and fields for enum?

Daniel Kozák via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 26 03:57:01 PST 2017


V Thu, 26 Jan 2017 06:32:10 +0000
Profile Anaysis via Digitalmars-d <digitalmars-d at puremagic.com> napsáno:

> Why not make enum a comparable type to structs and classes?
> 
> They are static so they can't contain any mutable fields but 
> surely they can contain methods? And especially they should be 
> able to contain static methods!?
> 

struct EnumWithMethods
{
    @disable this();
    static enum Senum
    {
        one,
        two,
        three,
    }

    alias Senum this;

    static getOne()
    {
        return this.one;
    }
}

void main()
{
    import std.stdio;

    auto x = EnumWithMethods.one;
    auto y = EnumWithMethods.getOne();
    writeln(x);
    writeln(y);
}




More information about the Digitalmars-d mailing list