[dmd-beta] rvalue references
Michel Fortin
michel.fortin at michelf.com
Mon Apr 16 14:21:43 PDT 2012
Le 2012-04-16 à 14:31, Sean Kelly a écrit :
> On Apr 16, 2012, at 6:32 AM, Steve Schveighoffer wrote:
>>
>> Regardless of the solution, I think we need to designate two different situations:
>>
>> 1. I want to pass this by reference because it's more efficient
>> 2. I want to pass this by reference because I want to change it
>
> Ideally, no one should ever specify "ref" simply for efficiency. The programmer should choose semantics for logical reasons, and leave optimization up to the compiler. That may still not be practical however.
The compiler can't decide by itself because there is not enough context, it also pose some problems for having a stable ABI. That said, I agree that having to add ref (or auto-ref) everywhere for efficiency isn't very appealing.
Did you notice the "ref struct" proposal I made a while ago on the newsgroup? Basically you attach a flag to a struct declaration that'd cause that struct to be automatically passed by ref when used as a function argument. It's crude, but it'd be much less verbose than writing 'ref' or 'auto ref' everywhere.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the dmd-beta
mailing list