On Monday, 29 May 2017 at 07:39:40 UTC, Dukc wrote:

But what would be worth a consideration, is that perhaps one should be allowed to pass rvalues as reference with something like this? According to TDPL, ref arguments do not take rvalues to prevent bugs where you accidently copy something before passing it, and that's a good rationale. But shouldn't it still be allowed explicitly?

Explicitly? It is:

import std.stdio;

struct S
{
    int v;
}

void foo(ref S s)
{
    writeln("took S by ref: ", s.v);
}

void foo(S s)
{
    writeln("took rvalue S...");
    foo(s);      // calls ref overload
}

void main()
{
    S s;
    foo(s);      // calls ref overload
    foo(S.init); // calls rvalue overload
}

And for templates we have auto ref.

Reply via email to