On Monday, 24 June 2013 at 01:22:12 UTC, cal wrote:
What is going on here?

import std.stdio, std.typecons;

struct S
{
    int x;
    Tuple!(S) foo() { return tuple(this); }
}

void main()
{
    S s;
    s.x = 8;
    writeln((s.foo()));     //output: Tuple!(S)(S(8))
    writeln((s.foo())[0]);  //output: S(0)
}

import std.stdio, std.typecons;

struct S
{
    int x;
    int y;
    int z;

    auto foo() { return tuple(this.tupleof); }
}

void main()
{
    S s;
    s.x = 8;
    s.y = 9;
    s.z = 10;
writeln((s.foo())); //output: Tuple!(int, int, int)(8, 9, 10)

    writeln(s.foo()[2]);  //output: 10
}

Is this what you expected?
I would explain what's going on but I'd be wrong.

Reply via email to