alias to fully qualified enum in scope where enum is expected

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 6 00:23:30 PDT 2014


On 6/08/2014 6:11 p.m., Timothee Cour via Digitalmars-d-learn wrote:
> Is there a simple way to to do this?
>
> enum A{
> a1,
> a2
> }
>
> void fun(A a){...}
> void test(){
>   fun(A.a1); //works
>   fun(a1); //I'd like a1 to work, but just where an A is expected to
> avoid polluting namespace.
> }

The magic of with statements!

enum A {
  	a1,
	a2
}

void func(A a){}
void main(){
	func(A.a1);
	with(A) {
		func(a1);
	}
}



More information about the Digitalmars-d-learn mailing list