On Tuesday, 23 June 2015 at 01:07:17 UTC, Jonathan M Davis wrote:
No, you can't guarantee that an auto ref parameter won't be mutated, but auto ref clearly indicates that you intend to accept both lvalues and rvalues, meaning that it would be stupid to be writing the function with the idea that you would be passing in an argument which would be mutated. ref on the other hand clearly indicates the intention to mutate the argument.

- Jonathan M Davis

That is why, as a good API designer, you'd express that fact by adding const ontop of it, i.e. const ref.

Only for the few rare cases where you need to account for lazy-caching or similar mutating constructs, you'd be grateful to have the nice escape hatch, plain ref.

Daniel N

Reply via email to