RFC: scope and borrowing

Manu via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 24 13:38:30 PDT 2014


On 24 September 2014 17:50, Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 9/23/2014 4:19 AM, Manu via Digitalmars-d wrote:
>>>
>>> BTW, ref (as you know) is part of the type in C++. However, I can vouch
>>> for
>>> it being a special case everywhere in C++, and is a horrifying quagmire
>>> of
>>> strange edge cases. That's why it's not part of the type in D.
>>
>>
>> I've never had any problems with ref in C++. D presents the horrible
>> quagmire
>> of edge cases in my experience, some of which I've presented, but I've had
>> many more issues in the past. Can you give me some examples of the
>> problems
>> in C++ you set out to avoid?
>
>
> Q: Given a T&, and type deduction, when do you get the T and when do you get
> the T& ?
>
> A: It's different for every situation. Nobody can remember or enumerate the
> cases. Maybe Scott Meyers.

Scott Myers presented on this in extraordinary detail. By my
recollection (without referring to his talk), it was different in
*one* case, not every case. It's a binary situation, so it can't
possibly be different in 'every case', there are only 2 cases, and one
of them is the common case.

I suggest if the idea were explored in D, we would see if it works
where type deduction always gives what you expect (ie, gives ref(T)
for ref(T)). Unlike C++, we have an extensive suite of tools like
PointerTarget!T, Unqual!T, isPointer!T and friends; we can use those
tools explicitly in the places where we want T from deduction yielding
ref(T). I suspect we can avoid the C++ deduction hack given the
presence of these tools.

And if it proves that the C++ edge case is necessary (I don't think it
will), then so be it. I've never had problems with it, and always
found it intuitive in 20 years, whereas D's current setup is
immeasurably more complex than C++'s edge case, and causes me the
greatest source of pain in the language.


More information about the Digitalmars-d mailing list