digitalmars.D.learn - How do you get T from shared(T) ?
- Marco Leise (5/5) Sep 28 2014 For head-unshared there is `static if (is(T U : shared U))`.
- tcak (3/6) Sep 28 2014 shared int a;
- Marco Leise (6/14) Sep 28 2014 No, I mean for `shared void*`, too. But I special cased for
- John Colvin (35/38) Sep 30 2014 template UnShared(T, bool removeAll = false)
- Marco Leise (5/45) Oct 01 2014 Ah, thanks. That does the trick!
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` ? -- Marco
Sep 28 2014
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` ?shared int a; int b = cast()a;
Sep 28 2014
Am Sun, 28 Sep 2014 14:07:22 +0000 schrieb "tcak" <tcak gmail.com>:On Sunday, 28 September 2014 at 09:11:07 UTC, Marco Leise wrote:No, I mean for `shared void*`, too. But I special cased for one level of pointer indirection now, so it works. -- MarcoFor 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` ?shared int a; int b = cast()a;
Sep 28 2014
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****)); }
Sep 30 2014
Am Tue, 30 Sep 2014 14:48:03 +0000 schrieb "John Colvin" <john.loughran.colvin gmail.com>:On Sunday, 28 September 2014 at 09:11:07 UTC, Marco Leise wrote:Ah, thanks. That does the trick! -- MarcoFor 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****)); }
Oct 01 2014