digitalmars.D.learn - How to cast away shared?
- Ruby The Roobster (1/1) Aug 03 2022 Any way to 'cast away' shared for an unknown type T?
- Paul Backus (10/11) Aug 03 2022 There's actually an `Unshared` template for this in `std.traits`,
- Ruby The Roobster (2/13) Aug 03 2022 Thank you. This really helped.
Any way to 'cast away' shared for an unknown type T?
Aug 03 2022
On Wednesday, 3 August 2022 at 12:50:17 UTC, Ruby The Roobster wrote:Any way to 'cast away' shared for an unknown type T?There's actually an `Unshared` template for this in `std.traits`, but for some reason it's `private`, so you can't use it directly. Fortunately, it's only two lines: ```d alias Unshared(T) = T; alias Unshared(T: shared U, U) = U; ``` Once you have this, you can write `cast(Unshared!T)`.
Aug 03 2022
On Wednesday, 3 August 2022 at 13:00:05 UTC, Paul Backus wrote:On Wednesday, 3 August 2022 at 12:50:17 UTC, Ruby The Roobster wrote:Thank you. This really helped.Any way to 'cast away' shared for an unknown type T?There's actually an `Unshared` template for this in `std.traits`, but for some reason it's `private`, so you can't use it directly. Fortunately, it's only two lines: ```d alias Unshared(T) = T; alias Unshared(T: shared U, U) = U; ``` Once you have this, you can write `cast(Unshared!T)`.
Aug 03 2022