Binding rvalues to ref [WAS: I close BIP27. I won't be pursuing BIPs anymore]

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 19 11:15:25 PDT 2016


On Wednesday, October 19, 2016 12:48:54 Andrei Alexandrescu via Digitalmars-d 
wrote:
> On 10/19/2016 11:38 AM, Jonathan M Davis via Digitalmars-d wrote:
> > On Wednesday, October 19, 2016 07:55:19 Andrei Alexandrescu via
> > Digitalmars-d>
> > wrote:
> >> This was C++'s big un' that led to many complications. If the overload
> >> weren't ambiguous, a large part of rvalue references would have been
> >> unneeded. (Universal references would still have been necessary for
> >> perfect forwarding, but that's not the bulk.)
> >>
> >> In order to avoid such issues, we steered clear off binding rvalues to
> >> ref parameters in the D language. As I mentioned to Ethan, I do agree a
> >> careful definition may be able to avoid the fallout that happened in
> >> C++. It would be a fair amount of work.
> >
> > The other big problem is that D's const is so much more restrictive than
> > C++'s that even if const ref accepted rvalues, a large portion of the
> > time,
> > it would be too restrictive to be useful.
>
> That's why if we allow binding rvalues to references, we'd allow it
> regardless of const. -- Andrei

Which then causes the problem that it becomes much less clear whether ref is
supposed to be modifying its argument or is just trying to avoid copying it
- though good documentation can mitigate that problem.

- Jonathan M Davis



More information about the Digitalmars-d mailing list