rvalues -> ref (yup... again!)

kinke noone at nowhere.com
Sat Mar 24 16:20:33 UTC 2018


On Saturday, 24 March 2018 at 15:36:14 UTC, Timon Gehr wrote:
> On 24.03.2018 15:56, kinke wrote:
>> I agree, but restricting it to const ref would be enough for 
>> almost all of my use cases. The MS C++ compiler just emits a 
>> warning when binding an rvalue to a mutable ref ('nonstandard 
>> extension used'), I'd find that absolutely viable for D too.
>> ...
>
> A warning is not viable. (There's no good way to fix it.)

As long as specific warnings cannot be suppressed via pragmas, 
one would need to predeclare the lvalue to get rid of it; fine 
IMHO for the, as I expect, very rare use cases.

> There is no difference between escaping refs to an rvalue and 
> escaping refs to a short-lived lvalue, as the callee has no 
> idea where the address is coming from anyway. According to 
> Walter, ref parameters are not supposed to be escaped, and 
> @safe will enforce it.

Alright, the less keywords overhead, the better. :)

> You can add additional overloads on the D side. (This can even 
> be automated using a string mixin.)

Right I can, but I don't want to add 7 overloads for a C++ 
function taking 3 params by const ref. Even if autogenerated by 
some tool or fancy mixins, the code's legibility would suffer a 
lot. D's syntax is IMO one of its strongest selling points, and 
that shouldn't degrade when it comes to C(++) interop.


More information about the Digitalmars-d mailing list