Rebooting the __metada/__mutable discussion

Paul Backus snarwin at gmail.com
Mon Apr 11 14:44:18 UTC 2022


On Monday, 11 April 2022 at 11:46:42 UTC, Alexandru Ermicioi 
wrote:
> On Sunday, 10 April 2022 at 23:12:03 UTC, rikki cattermole 
> wrote:
>>
>> On 11/04/2022 3:04 AM, Alexandru Ermicioi wrote:
>>> Isn't better then to try and find design patterns or rules 
>>> for use with mutable RC structures?
>>
>> Yes.
>>
>> But if the compiler allows RC to become const and not allow RC 
>> to occur, that is a bad situation to be in...
>
> This seems like a couple of edge cases and bugs that need to be 
> rectified, in order to have proper safe mutable only RC 
> structs. You should be able to disallow implicit cast to const 
> of struct if it is desired to do so.

There's no issue here. You just write the copy constructor of 
RC!T to require a mutable source and destination object, and the 
compiler will refuse to copy a const(RC!T). (You can still pass 
by `const ref`, of course.)

> Regarding const rc use, I think there can be a limited access 
> to the payload, if you somehow prohibit taking the address of 
> the payload or it's sub-elements. Perhaps instead of returning 
> payload itself from rc struct, maybe it can be wrapped into a 
> wrapper, that prevents any take of address when a field is 
> accessed from payload, or payload itself.

You can limit access by passing a `scope` reference to the 
payload to a callback function, as described in this comment:

https://github.com/dlang/phobos/pull/8368#issuecomment-1024917439


More information about the Digitalmars-d mailing list