Use members of a Named Enum without using Enum name?
QuizzicalFella via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Aug 15 08:37:41 PDT 2015
I have a named enum that I'd like to keep named, that I'd like to
use as a type, but every time I use a member I'd rather not write
out the enum name. I have a situation like the following:
enum PolygonT : byte { TRIANGLE, RECTANGLE, STAR }
void someFunc(PolygonT shape) { //some stuff }
I'd like to be able to call someFunc(TRIANGLE) rather than
someFunc(PolygonT.TRIANGLE). Being clear but not being too long
is my aim. Writing the type makes it too verbose and I have lazy
fingers...
I don't mind if adding another enum with members of the same name
like this:
enum CelestialBodiesT : byte { MOON, SUN, BLACK_HOLE, STAR }
...would force me to call someFunc(PolygonT.STAR) by the
compiler, but for the case where there's no ambiguity, I don't
want to write out the type of the enum...
I know I can add in an 'alias this' for classes and structs, but
I think I only get one and if it's an enum I'm using all over the
place I don't want to 'alias this' it everywhere...
Is there a way I can do this while retaining type safety? (can I
be lazy and protected at the same time?)
More information about the Digitalmars-d-learn
mailing list