malio:

> Okay, thanks bearophile. But I currently doesn't exactly understand what's 
> the difference between "ref" and "const ref"/"immutable ref". If "ref" is 
> syntactic
> sugar for pointers only (like your first example), does it also create a copy 
> of the parameters which are marked as "ref"? I thought that pointers (and in
> this context also "ref") avoid the creation of costly copies?!?

"ref" just passes a reference to something, so it doesn't perform copies.

"const ref" or "immutable ref" just means that you can't change the value (with 
the usual semantic differences between const and immutable, that are both 
transitive).

For the programmer that reads your code, "ref" means the function you have 
written will usually modify the given argument, while "const ref" means it will 
not modify it.

Bye,
bearophile

Reply via email to