Accessing types by context

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 29 06:41:51 PDT 2016


On 29/06/16 05:11, Hiemlick Hiemlicker wrote:
> 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.

Swift has this feature (the enum member needs to be prefix with a dot). 
This has been brought up before and Walter doesn't like it. It will 
complicate the language, especially function overloading:

enum Foo { A }
enum Bar { A }

void foo(Foo);
void foo(Bar);

foo(A); // ambiguity

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list