Well, there are many times I'd rather have 'this' passed by value for efficiency!

Const ref would fit the bill nicely, if it didn't affect the type.

What would be interesting is if there was a way to say "this won't change in this function", and then the compiler could choose to pass by ref or value depending on which was more efficient, while still enforcing the property that the value doesn't change.

Hm.. could there be a library solution?

-Steve


From: Sean Kelly <sean@invisibleduck.org>
To: Steve Schveighoffer <schveiguy@yahoo.com>; Discuss the dmd beta releases for D <dmd-beta@puremagic.com>
Sent: Monday, April 16, 2012 2:31 PM
Subject: Re: [dmd-beta] rvalue references

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.