DIP 1016 should use expression lowering, not statement lowering
Steven Schveighoffer
schveiguy at gmail.com
Thu Jan 31 02:29:47 UTC 2019
On 1/30/19 9:20 PM, Steven Schveighoffer wrote:
> Essentially, nothing is different from existing semantics today, when
> rvalues are used and provides reference semantics (yes, it's possible,
> see tempCString). They live until the end of the statement. It's how
> this has to be. It can't be expression based.
I came up with this idea based on tempCString, but it doesn't work:
struct RV(T)
{
T theThing;
ref T getIt() { return theThing; }
alias getIt this;
}
auto rv(T)(T t)
{
import std.algorithm : move;
return RV!T(move(t));
}
Of course, we'd need to suppress destructors here potentially.
I tried to use it:
import std.stdio;
void foo(ref int i) {writeln("i is ", i);}
void main()
{
foo(1.rv);
}
But it fails:
Error: function testrvalue.foo(ref int i) is not callable using argument
types (RV!int)
cannot pass rvalue argument rv(1) of type RV!int to parameter
ref int i
If I manually execute the alias this, it works:
foo(1.rv.getIt)
So I don't get why it doesn't work. But if that was fixed, could be a
potential workaround without requiring a DIP.
-Steve
More information about the Digitalmars-d-announce
mailing list