Use members of a Named Enum without using Enum name?
    Adam D. Ruppe via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sat Aug 15 08:53:22 PDT 2015
    
    
  
On Saturday, 15 August 2015 at 15:37:42 UTC, QuizzicalFella wrote:
> I'd like to be able to call someFunc(TRIANGLE) rather than 
> someFunc(PolygonT.TRIANGLE).
Two options come to mind:
alias TRIANGLE = PolygonT.TRIANGLE;
// etc
Or at the usage site:
with(PolygonT) {
    someFunc(TRIANGLE);
}
> 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...
That'll work as long as the two enums are defined in separate 
modules, then only import the one you need to use at the time. 
Otherwise, they will conflict and it will force you to write it 
out long form again.
    
    
More information about the Digitalmars-d-learn
mailing list