On 11/09/2014 10:59 AM, tcak wrote:

> When I want to create a system where data types should match
> each other automatically,

'alias this' can do that but unfortunately, the current compiler supports only one 'alias this' in a user-defined type. I think that limitation will be gone with 2.067.

Although the following functions return rvalues, 'alias this' can use member variables as well:

    alias myMemberVariable this;

import std.stdio;

struct A
{
    B asB()
    {
        writeln(__FUNCTION__);
        return B();
    }

    alias asB this;
}

struct B
{
    A asA()
    {
        writeln(__FUNCTION__);
        return A();
    }

    alias asA this;
}

void main()
{
    A a;
    B b;

    b = a;
    a = b;
}

Ali

Reply via email to