The liabilities of binding rvalues to ref

Jonathan M Davis jmdavisProg at gmx.com
Thu May 9 12:21:12 PDT 2013


On Thursday, May 09, 2013 14:23:11 Steven Schveighoffer wrote:
> I think first we have to prove that auto ref is worth the extra cognitive
> load. Every overload style we add has a large multiplicative effect on
> boilerplate.
> 
> As I said before, I'd be ok with any solution, as long as we can bind
> rvalues to some form of ref.

We already have it with templated functions. For the most part, there would be 
no real difference from the caller's perspective between auto ref with a 
templated function and auto ref with a non-templated functions. You just use 
auto ref (or auto ref const if you can use const) whenever you want a 
parameter to accept both rvalues and lvalues, and whether the function is 
templated or not doesn't really matter.

The only times that it would matter are when you actually care about 
forwarding the refness of the argument (which the templated functon will do 
but not the non-templated one) or when you don't want the extra template bloat 
of the templated auto ref (though it might be possible for the compiler to use 
the non-templated solution for auto ref when it can determine that ref 
forwarding isn't being used). Using auto ref in this manner is exactly what it 
was originally intended for and exactly what TDPL describes. So, I don't think 
that the difference between templated auto ref and non-templated auto ref will 
add much cognitive load, and we've already added the cognitive load of having 
auto ref by having it with templated functions.

- Jonathan M Davis


More information about the Digitalmars-d mailing list