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

Manu turkeyman at gmail.com
Sat Mar 24 01:16:30 UTC 2018


On 23 March 2018 at 17:58, Jonathan M Davis via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Friday, March 23, 2018 17:35:11 Manu via Digitalmars-d wrote:
>> > but that by itself isn't
>> > enough if you want it to be clear whether a function is supposed to be
>> > mutating the argument
>>
>> Functions that receive const args make it pretty clear that they don't
>> intend to mutate the arg.
>
> Yes, but with how restrictive const is in D, I have a very hard time
> believing that it's going to work well to start using const ref much even if
> it accepted rvalues.

This is an interesting point, but I don't think it changes the balance
in any way. Thinking of the majority of my anecdotal cases, I don't
think it would be a problem.
Something complex enough for const to be a problem likely doesn't
conform to this pattern.

Further, extern(C++) functions that receive const& args are 'const
ref' regardless of D's const semantics. So for extern(C++), which I
suspect is a high percentage of cases where this issue is significant
(because D doesn't naturally follow C++'s pattern so much anyway),
that point doesn't matter.


More information about the Digitalmars-d mailing list