On Tuesday, October 18, 2016 20:15:18 ag0aep6g via Digitalmars-d wrote:
> First, so that people get a nice prepared answer for why D is different.
> I can't confidently spell out why D doesn't allow passing an rvalues in
> a const ref parameter, and I suspect that only Andrei really can.
He's explained it several times, but I confess that I've never really
understood the reasoning. I know C++ well but not at the level of detail
that seems to be required to understand what the exact problem is.
Though as much as folks like passing rvalues to const ref in C++, isn't that
generally considered to be bad practice now with C++11/14, because it
doesn't play nicely with move constructors? Or at least, there are many
cases where you would have used const ref previously that now you shouldn't,
because it forces a copy for lvalues in some cases, whereas just passing by
value would allow a move to be made? If that's the case, I'm not sure that
the fact that we don't allow const ref to take rvalues is as big a deal as
it would first seem to a C++98 programmer (though it's obviously still
- Jonathan M Davis