On Friday, 1 February 2013 at 01:53:05 UTC, TommiT wrote:
On Friday, 1 February 2013 at 00:59:47 UTC, Zach the Mystic wrote:
writeln(foo.n); // uses alias this to call __mightAsWellBeOpGet

No it won't. It will print "n()".

And that exactly (passing to a templated parameter) is the insurmountable problem in using a variable to represent a property.

On Friday, 1 February 2013 at 01:53:05 UTC, TommiT wrote:
And that exactly (passing to a templated parameter) is the insurmountable problem in using a variable to represent a property.

And here's another example of why it is as big of a problem as I make it sound to be:

import std.concurrency;

struct Array
{
    int _len;

    length struct // Using Zach's syntax
    {
        @property get() { return _len; }
        alias this = get;
        void opAssign(int rhs) { _len = rhs; }
    }
}

void func(T)(T t)
{
    auto v = t;
    v = 10;
}

void main()
{
    Array arr;
    spawn(&func!int, arr.length);
    arr.length = 20; // And here we have a data-race.
                     // Good luck trying to find these
                     // kinds of bugs.
}

Reply via email to