Do I have to pass parameters with ref explicitly?
Elfstone
elfstone at yeah.net
Sun Apr 17 04:56:06 UTC 2022
On Sunday, 17 April 2022 at 04:00:19 UTC, max haughton wrote:
> On Sunday, 17 April 2022 at 03:00:28 UTC, Elfstone wrote:
>> I'm reading some d-sources, and it looks like they pass big
>> structs by value.
>> Such as:
>>
>> Matrix4x4f opBinary(string op)(Matrix4x4f rhs) { ... }
>>
>> I came from a C++ background, and I would have written:
>>
>> Matrix4x4f opBinary(string op)(const ref Matrix4x4f rhs) {
>> ... }
>>
>> I haven't found anything in the docs yet. Will the d-compiler
>> optimize them into virtually the same? Can someone give me a
>> reference?
>
> It's the same as C++.
In C++ I would expect the copy to be optimized away, even when
passed by value. Do you mean d-compilers (optionally?) do the
same optimization too?
More information about the Digitalmars-d-learn
mailing list