const in functions

Ali Çehreli acehreli at yahoo.com
Mon Mar 13 15:39:23 UTC 2023


On 3/13/23 08:17, Salih Dincer wrote:

 > In this case, using `ref` will increase performance while reducing the
 > number of copies.

I am not sure about that. Unless there is an expensive copy 
construction, most objects are simple data copies.

To use 'ref' or not should be guided through semantics. Luckily, we have 
the -preview=in command line switch that removes the cost of copying 
from the equation:

   https://dlang.org/spec/function.html#in-params

Just marking the input parameters 'in' should be sufficient in most cases.

Ali



More information about the Digitalmars-d-learn mailing list