The liabilities of binding rvalues to ref
Jonathan M Davis
jmdavisProg at gmx.com
Thu May 9 14:06:49 PDT 2013
On Thursday, May 09, 2013 21:39:14 Rob T wrote:
> So, if I understand correctly, auto ref for templates will end up
> doing exactly the same thing as auto ref for non-template
> functions? That would be perfect, otherwise it'll be terribly
> confusing.
auto ref on templates would be essentially unchanged from what it is now (the
fact that it forwards the refness of its arguments is actually very useful for
some situations, and we don't want to lose that). However, what we might be
able to do as an optimization would be to make it so that auto ref on
templates acts the same as auto ref on non-templated functions when the
compiler is able to determine that there's no real semantic difference - i.e.
when the fact that the refness is being forwarded is irrelevant.
So, with a function like
auto foo(T)(auto ref T t)
{
return t;
}
the non-templated solution could be used, whereas in a function like
auto ref foo(T)(auto ref T t)
{
return t;
}
or
auto foo(T)(auto ref T t)
{
return anotherFuncWhichTakesByAutoRef(t);
}
the compiler would have to use the normal templated solution, because the
refness of the arguments would have an effect on the code.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list