How do you get T from shared(T) ?
Marco Leise via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Oct 1 15:26:19 PDT 2014
Am Tue, 30 Sep 2014 14:48:03 +0000
schrieb "John Colvin" <john.loughran.colvin at gmail.com>:
> On Sunday, 28 September 2014 at 09:11:07 UTC, Marco Leise wrote:
> > For head-unshared there is `static if (is(T U : shared U))`.
> > But how do you get the unshared type for anything from `shared
> > void*` to `shared uint` ?
>
> template UnShared(T, bool removeAll = false)
> {
> static if(is(T : shared U, U))
> {
> static if(is(U : shared(V)*, V))
> {
> alias UnShared = UnShared!(V, true)*;
> }
> else
> {
> alias UnShared = U;
> }
> }
> else
> {
> static if(removeAll && is(T : U*, U))
> {
> alias UnShared = UnShared!(U, true)*;
> }
> else
> {
> alias UnShared = T;
> }
> }
> }
>
> unittest
> {
> static assert(is(UnShared!(shared int) == int));
> static assert(is(UnShared!(shared void*) == void*));
> static assert(is(UnShared!(shared(int**)*) ==
> shared(int**)*));
> static assert(is(UnShared!(shared(int**)**, true) ==
> int****));
> }
Ah, thanks. That does the trick!
--
Marco
More information about the Digitalmars-d-learn
mailing list