On Friday, April 26, 2013 23:21:49 Diggory wrote: > > You're just asking for bugs if you allow ref to accept rvalues. > > We've had problems like this before when some literals were > > treated as lvalues. The behavior of a function which takes its > > argument by ref and the behavior of one which takes its > > argument by auto ref are fundamentally different. > > The only purpose of rvalue references is to allow the callee to > mutate the value... Otherwise you would just use a const ref.
Except that const ref doesn't accept rvalues, and D's const is _far_ more restrictive than C++'s const, so requiring that a parameter be const in order to not care whether it's given an rvalue or lvalue but still pass it efficiently would be a major negative. auto ref doesn't require or imply const, and it shouldn't. Granted, it should be logically const, but that can't be guaranteed by the type system without guaranteeing physical constness, which is often too strong a requirement. So, it would be a big mistake to make it so that constness had anything to do with our solution for passing arguments efficiently without caring about refness. - Jonathan M Davis