__gshared as part of alias

Steven Schveighoffer schveiguy at yahoo.com
Wed Jan 17 02:37:07 UTC 2018


On 1/11/18 11:25 PM, Nicholas Wilson wrote:
> Is there a way to make __gshared part of an alias?

No, __gshared is a storage class, not a type constructor, so it has no 
meaning as part of a type:

__gshared int x;
int y;

static assert(is(typeof(x) == typeof(y)));

> as in
> 
> enum AddrSpace : uint
> {
>      Private  = 0,
>      Global   = 1,
>      Shared   = 2,
>      Constant = 3,
>      Generic  = 4,
> }
> 
> struct Variable(AddrSpace as, T)
> {
>      T val;
>      alias val this;
> }
> alias Global(T)   = __gshared Variable!(AddrSpace.Global,   T);

dmd famously doesn't complain about attributes that do nothing, as in 
this case.

-Steve


More information about the Digitalmars-d-learn mailing list