How do I copy struct having immutable pointer member when enabled DIP1000?

outlandkarasu outland.karasu at gmail.com
Mon Aug 31 07:11:15 UTC 2020


On Monday, 31 August 2020 at 05:46:45 UTC, ag0aep6g wrote:
> `ref` kind of implies `scope` [1]. You don't need to type it 
> out. When you do type out `scope ref const(Price)`, the `scope` 
> actually doesn't apply to the `ref` but to the pointers in 
> `Price` (whereas the `scope` in `scope const(Price)[]` applies 
> to the pointer of the array).
>
> So you don't need `scope` on the `price` parameter because 
> you're taking it as a `ref`. You would need `scope` if you were 
> taking it as a pointer (`scope const(Price)* price`).
>
> By the way, semantically there isn't any reason to take `price` 
> as either `ref` or pointer. You can just as well take it by 
> value, since you're making a copy of it anyway with `minPrice = 
> price` (and you also make a copy earlier with `foreach (price; 
> prices)`).

Thank you for your advice.
I understand that I had abused `scope` parameter.

> I don't think this is in Bugzilla yet. Please file an issue. Or 
> let me know if you want me to do it.

I have filed issue about `ref` parameter address check.
https://issues.dlang.org/show_bug.cgi?id=21212


More information about the Digitalmars-d-learn mailing list