[dmd-beta] D 2.059 beta 4

Jonathan M Davis jmdavisProg at gmx.com
Mon Apr 9 21:06:52 PDT 2012


On Monday, April 09, 2012 20:55:16 Walter Bright wrote:
> On 4/9/2012 7:44 PM, Jonathan M Davis wrote:
> > On Monday, April 09, 2012 19:40:43 Walter Bright wrote:
> >> On 4/9/2012 7:32 PM, Nick Sabalausky wrote:
> >>> Although, if there really is good merit to struct lits not veing
> >>> lvalues,
> >>> then maybe all we need is to wait until "auto ref" is usable for
> >>> non-templates? (If that would even be possible...?)
> >> 
> >> Not possible, as the binary ABI would be different.
> > 
> > It was my understanding that the auto ref was supposed to work with non-
> > templated functions - at least what Andrei proposed was - but that you
> > misunderstood that and made it only work with templates. And as long as it
> > only works with templates, it's usefulness is very limited. opEquals would
> > be a _prime_ case for where it would be useful.
> 
> How could that possibly work for the same function, considering that the
> code for each would be quite different, including the calling code?

I don't know. When it came up semi-recently in the newsgroup, Timon had a 
suggestion, but I don't recall what it was.

Heck, it could simply duplicate the function outright. That's what we're going 
to be forced to do with pretty much every single const ref function anyway. It 
may be that making const ref take temporaries really is a bad idea, but 
without that, it's very nearly useless IMHO. Certainly, any time that you use 
it, you have to declare a version which doesn't take a ref or the function 
will only work with lvalues, which is almost always overly restrictive. So, 
having auto ref simply duplicate the function would still be a big step 
forward. For example

void func(auto ref S s)

could become

void func(ref S s)
void func(S s)

and

void func(const auto ref S s)

could become

void func(const ref S s)
void func(const S s)

The non-ref version could then call the ref version and avoid having to 
duplicate the entire function body. It's what we're going to have to be doing 
by hand for const ref functions anyway.

Having to duplicate pretty much every single function which takes a const ref 
- opEquals and opCmp being very prominent among them - is a definite problem. 
That's the problem that auto ref was intended to solve, and as long as it only 
works with templated functions, it really doesn't solve the problem.

- Jonathan M Davis


More information about the dmd-beta mailing list