Thread overview
How do you get T from shared(T) ?
Sep 28, 2014
Marco Leise
Sep 28, 2014
tcak
Sep 28, 2014
Marco Leise
Sep 30, 2014
John Colvin
Oct 01, 2014
Marco Leise
September 28, 2014
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

September 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;
September 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:
> > 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;

No, I mean for `shared void*`, too. But I special cased for one level of pointer indirection now, so it works.

-- 
Marco

September 30, 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****));
}
October 01, 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:
> > 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