[dmd-beta] rvalue references

Andrei Alexandrescu andrei at erdani.com
Mon Apr 16 14:48:20 PDT 2012


On 4/16/12 4:21 PM, Michel Fortin wrote:
> Did you notice the "ref struct" proposal I made a while ago on the
> newsgroup? Basically you attach a flag to a struct declaration that'd
> cause that struct to be automatically passed by ref when used as a
> function argument. It's crude, but it'd be much less verbose than
> writing 'ref' or 'auto ref' everywhere.

Walter convinced me a while ago that transparent pass by ref is 
problematic. Consider:

struct S @pass_by_ref(true)
{
    ...
}

void fun(T)(T a, T b)
{
    ...
}

Inside fun, code is free to assume that &a != &b with quite important 
consequences. If calling fun(s, s) ends up aliasing the two names to the 
same thing, it will fail in difficult to figure ways.


Andrei


More information about the dmd-beta mailing list