

//
// constructor
//

[E | Enum?(E)]
inline overload E() = E(0);



//
// convert to/from integers
//

[E,I | Enum?(E) and Integer?(I)]
inline overload I(a:E) = I(enumToInt(a));

[E | Enum?(E)]
inline overload Int(a:E) = enumToInt(a);

[E,I | Enum?(E) and Integer?(I)]
inline overload E(a:I) = intToEnum(E, Int(a));

[E | Enum?(E)]
inline overload E(a:Int) = intToEnum(E, a);



//
// equals?, lesser?
//

[E | Enum?(E)]
inline overload equals?(a:E, b:E) = (enumToInt(a) == enumToInt(b));

[E | Enum?(E)]
inline overload lesser?(a:E, b:E) = (enumToInt(a) < enumToInt(b));



//
// enumName
//

[E | Enum?(E)]
enumName(x:E) {
    alias n = EnumMemberCount(E);
    ..for (i in staticIntegers(static n)) {
        if (x == E(unwrapStatic(i)))
            return EnumMemberName(E, i);
    }
    return "unknown enum value";
}
