auto ref is on the docket
Atila Neves via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 29 12:10:05 PDT 2015
On Monday, 29 June 2015 at 17:19:48 UTC, Jonathan M Davis wrote:
> On Sunday, 28 June 2015 at 10:50:10 UTC, Marc Schütz wrote:
>> Thank you Jonathan, I think I (like kinke in his post above)
>> finally understand your stance. So I guess from your POV the
>> following would be an ideal situation (disregarding the need
>> to avoid breaking changes):
>>
>> 1) `auto ref` for non-templates is required to make a function
>> accept rvalue and lvalue refs alike.
>> 2) `auto ref` for templates is changed to mean the same thing
>> as 1).
>> 3) `scope ref` prevents escaping of the reference.
>>
>> Neither of `auto ref` and `scope ref` would imply the other,
>> because you want to treat them as orthogonal. Do I understand
>> you right?
>>
>> The main problems with this is that they aren't in fact
>> orthogonal: `auto ref` without `scope ref` almost only makes
>> sense if you want to deliberately break something.
>> Furthermore, `auto ref` is already taken for something else,
>> and I'm not sure Walter would be too happy if we wanted to
>> change its meaning for templates.
>
> We definitely don't want to lose the current auto ref that we
> have with templates. It's critical for forwarding refness, even
> if we got that ability by accident. IIRC, we don't quite manage
> perfect forwarding with what we have (though off the top of my
> head, I don't recall what we're missing), but without auto ref,
> we definitely don't get there. So, auto ref, as it stands has
> proven to be surprisingly useful completely aside from
> efficiency concerns.
I thought perfect forwarding had everything to do with efficiency
concerns. At least, that's the motivation for in in C++
AFAICT/AFAIR. If not, (since C++ const& can bind to rvalues),
passing by value would be perfectly reasonable.
It seems to me that there's a lot of confusion in this thread. I
think I understand what you're saying but I'm not sure everyone
else does. So correct me if I'm wrong: your stance (which is how
I understand how things should be done in D) is that if a person
wants to bind an rvalue to a ref parameter for performance, they
shouldn't; they should pass it by value since it'll either get
constructed in place or moved, not copied.
Essentially, what this guy said about C++ (not the original I
read, that's now a 404):
http://m.blog.csdn.net/blog/CPP_CHEN/17528669
The reason rvalue references even exist in C++11/14 is because
rvalues can bind to const&. I remember hearing/reading Andrei say
that D doesn't need them precisely because in D, they can't. Pass
by value and you get the C++ behaviour when rvalue references are
used: a move.
Atila
More information about the Digitalmars-d
mailing list