How to cast `shared` away reliably

Nick Treleaven nick at geany.org
Wed Feb 11 11:44:14 UTC 2026


On Wednesday, 11 February 2026 at 02:02:20 UTC, Arafel wrote:
> ```d
> template ReallyUnshared(S) {
>     static if (is(S == shared(K[V]), K,V)) {
>         alias ReallyUnshared = K[V]; // Why is `K` not shared 
> here? Who knows...

Due to pattern matching, it seems correct. But see also 
https://github.com/dlang/dmd/issues/22182. I did work on a fix 
for that but haven't got it 100% yet.

>     } else static if (is(S == shared(T[]), T)) { // Same here
>         alias ReallyUnshared = T[];
>     // } else static if (is(S == shared(T[n]), T,n)) { // You'd 
> expect this to work, but it doesn't
>     //     alias ReallyUnshared = T[n]; // Don't ask me why

You need to declare `alias n` or `size_t n` to match a static 
array, `n` is not a type.




More information about the Digitalmars-d mailing list