rvalues -> ref (yup... again!)

Manu turkeyman at gmail.com
Tue Mar 27 02:26:44 UTC 2018


On 26 March 2018 at 19:25, Manu <turkeyman at gmail.com> wrote:
> On 26 March 2018 at 16:21, Rubn via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>> On Monday, 26 March 2018 at 22:48:38 UTC, Walter Bright wrote:
>>>
>>> On 3/26/2018 12:24 PM, Manu wrote:
>>>>
>>>> On 26 March 2018 at 07:40, Atila Neves via Digitalmars-d
>>>>>
>>>>> C++ const T& -> D T
>>>>
>>>>
>>>> Yeah, no... T may be big. Copying a large thing sucks. Memory copying
>>>> is the slowest thing computers can do.
>>>> As an API author, exactly as in C++, you will make a judgement on a
>>>> case-by-case basis on this matter. It may be by-value, it may be by
>>>> const-ref. It depends on a bunch of things, and they are points for
>>>> consideration by the API author, not the user.
>>>
>>>
>>> Copying does suck, I agree. Consider the following:
>>>
>>>     void foo(T t) { foo(t); } <= add this overload
>>>     void foo(ref T t) { ... }
>>>     T aaa();
>>>
>>>     foo(aaa());
>>>
>>> With inlining, I suspect we can get the compiler to not make any extra
>>> copies. It's not that different from NRVO. And as a marvy bonus, no weird
>>> semantic problems (as Atila mentioned).
>>
>>
>> How do you add this overload for the following?
>>
>>
>> void foo(ref T t) { ... }
>>
>> void function(ref int) func = &foo;
>> int aaa();
>>
>> func(aaa()); // err
>
> Exactly.

We're just kicking the can. And the only reason to do so is
ideological, as far as I can tell.
I want to hear an argument against... or any issue that's introduced
by allowing the implicit temporary?


More information about the Digitalmars-d mailing list