August 02

On Friday, 1 August 2025 at 10:36:37 UTC, Nick Treleaven wrote:

>

On Friday, 1 August 2025 at 10:08:09 UTC, Nick Treleaven wrote:
Sorry, wrong code above.

    T a, b;
    alias seq = AliasSeq!(a, b);
    // auto (x, y) = seq;
    auto x = seq[0];
    auto y = seq[1];
>

a[0] and a[1] are not moved by the lowered code.

So obviously a and b are lvalues and shouldn't be moved, sorry. Other cases:

import std;

struct S
{
    int i;
    this(ref S s) { writeln("copy", s.i); }
}

void main()
{
    writeln("rvalue");
    auto a = tuple(S(1))[0]; // copy, not move!
    writeln("lvalue");
    auto t = tuple(S(2));
    writeln("index");
    auto b = t[0]; // copy, OK
    writeln("seq");
    auto c = AliasSeq!(S(3))[0]; // move, OK
}

So the DIP should move when unpacking into c. For a, I think we would need tuple literals to avoid a copy.

1 2
Next ›   Last »