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****));
}