On Wednesday, 9 July 2014 at 15:39:50 UTC, David Nadlinger wrote:
On Wednesday, 9 July 2014 at 14:57:01 UTC, Andrew Edwards wrote:
My concern is that this shouldn't compile in the first place. What is xyz?, Is it a free function? Is it a member variable or function? In my mind it is neither of the two so why does it compile?

Oh, but that's precisely the point of opDispatch. ;) It offers a mechanism to respond to any members that are not found. See the spec for an example: http://dlang.org/operatoroverloading.html#Dispatch

David

Exactly. opDispatch catches calls to missing methods and acts based on method name which it gets as a string at compile time. In this case, the idea is this:

        auto v1 = Vec!4(4, 5, 6, 7);
        auto v2 = v1.xyz;   // => Vec!3(4, 5, 6);
        auto v3 = v1.wx;    // => Vec!2(7, 4);
        auto v4 = v1.wxx1;  // => Vec!4(7, 4, 4, 1);

Reply via email to