The liabilities of binding rvalues to ref

Rob T alanb at ucora.com
Thu May 9 13:07:57 PDT 2013


On Thursday, 9 May 2013 at 19:43:25 UTC, Andrei Alexandrescu 
wrote:
> On 5/9/13 3:39 PM, 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.
>
> There would be clear restrictions on non-template functions, 
> e.g. a non-template cannot return auto ref.
>
> Andrei

OK I can understand that auto ref on return for a template 
function is something different, so disallowing auto ref on a 
regular function makes perfect sense to me.

You can also create template functions with auto ref params that 
behave exactly like a non-template counter part by not specifying 
ref on the return, so it seems consistent and a sound solution 
from that perspective.

D is a complex language, so stuff like this does take some 
getting used to, but it is very powerful and flexible, no two 
ways around it.





More information about the Digitalmars-d mailing list