How to cast `shared` away reliably

Paul Backus snarwin at gmail.com
Wed Feb 11 15:02:28 UTC 2026


On Wednesday, 11 February 2026 at 12:38:37 UTC, Arafel wrote:
>> Only explict shared is removed.
>
>> static assert(is(Unshared!(shared(int[])) == shared(int)[]));
>
> How can I know what _implicit_ shared there are? Is there a 
> rationale for them, or somewhere in the spec where they are 
> mentioned?
>
> Or it is how it is, and that's all there is to it?

All type qualifiers in D (`const`, `immutable`, `shared`) are 
transitive, which means that a type qualifier applied to the "top 
level" of a type will also be applied recursively to each part of 
the type. So, a `const(int[])` is the same as a 
`const(const(int)[])`, and likewise for `shared`, `immutable`, or 
any combination thereof.

This is documented in the language spec's page on type qualifiers:

> Type qualifiers modify a type by applying a _TypeCtor_. 
> _TypeCtors_ are: `const`, `immutable`, `shared`, and `inout`. 
> Each applies transitively to all subtypes.

Source: https://dlang.org/spec/const3.html


More information about the Digitalmars-d mailing list