Accessing types by context

Hiemlick Hiemlicker via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 28 20:11:52 PDT 2016


Suppose one has void test(myEnum e)

enum myEnum
{
A,B,C
}

It would be very cool if we could do

test(A) instead of test(myEnum.A).

by context, the compiler can look first in the scope for 
something named A then look in the enum itself and prepend myEnum 
internally.


For flags, it would make it much easier to combine them:

test(A | B & C)

instead of

test(myEnum.A | myEnum.B & myEnum.C).

Similarly for comparisions of enums with objects:

if (object == A)

instead of

if (object == myEnum.A)

only if object is of type myEnum and A is not defined.

Seems logical? Is it possible in D to achieve something like this?

This could be extended to classes and structs but might create 
too much confusions.

For enums, I don't see any reason why it wouldn't work well.

Just a thought. Prefixing the same id to everything gets tiring 
after a while.





More information about the Digitalmars-d mailing list