Can you refer to the name enum as if it were anonymous in D?

I am making a D bridge in the C library, and this came up with C code using typedef'd enums, which it refers to as a constant, but can call it function arguments and the like. Example:

enum someLongNameThatTheCLibraryUses { A, B, } 

Currently, I should refer to it like this:

 someLongNameThatTheCLibraryUses.A; 

But I would prefer:

 A; 

I could do this:

 alias someLongNameThatTheCLibraryUses a; aA; 

But I do not want to do this in the library module, so I would have to do it where it was used, which would be unpleasant.

Is there any way to do this?

+4
source share
1 answer

If you want to introduce type safety with anonymous enumerations, you can create a new separate type using typedef and use it as the base type of the anonymous enumeration. Example:

 typedef int A; enum : A { a1, a2, a3 } typedef int X; enum : X { x1, x2, x3 } void main() { A a; X x; x = a; // Error: cannot implicitly convert expression (a) of type A to X } 
+5
source

All Articles