www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - passing a parrameter read-only ref?

reply Martin <martin.brzenska googlemail.com> writes:
Hi,
i would like to create a function which takes the first parameter 
as a reference to a struct - but assure the calle that the 
reference is read-only. Can this be done?

If i am not mistaken, then the "in" Parameter Storage Class is 
what i want(?). But the documentation states that this feature 
should not be used.

For context: I want to write struct-methods outside the struct 
(like in golang).
Sep 13 2020
parent Paul Backus <snarwin gmail.com> writes:
On Sunday, 13 September 2020 at 13:35:15 UTC, Martin wrote:
 Hi,
 i would like to create a function which takes the first 
 parameter as a reference to a struct - but assure the calle 
 that the reference is read-only. Can this be done?
Yes, you can do this with `ref const`.
Sep 13 2020