On Saturday, 3 September 2022 at 14:37:16 UTC, Steven Schveighoffer wrote:
On 9/2/22 3:15 PM, cc wrote:

Tried casting away shared as a workaround but I assume that will cause some kind of TLS catastrophe.


I think it will be fine, but you may have an issue. You are returning a non-shared `VAL`, but your class is `shared`, which means `table`, and all the `VAL` and `KEY` inside must also be `shared`.

If you cast away `shared` you have to put it back upon return.

TLS should not be involved here at all, so there is no problem there.

-Steve

Alright, so this is safe then?
```d
alias VAL[KEY] T;
auto require(KEY key) {
        auto unsharedT = cast(T) table;
        auto r = unsharedT.require(key);
        table = cast(shared) unsharedT;
        return cast(shared) r;
}
```
Was a bit surprised to see mutating `unsharedT` left `table` unchanged and needed reassigning.

Reply via email to