HeadUnshared in core.atomic

Sean Kelly via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 12 17:08:28 PDT 2014


On Thursday, 12 June 2014 at 05:29:39 UTC, Mike Franklin wrote:
> Hello,
>
> I was recently exposed to this template in core.atomic:
>
> private
> {
>     template HeadUnshared(T)
>     {
>         static if( is( T U : shared(U*) ) )
>             alias shared(U)* HeadUnshared;
>         else
>             alias T HeadUnshared;
>     }
> }
>
> Could someone please explain/elaborate on what this is doing, 
> and why it's necessary and used so often in core.atomic?

This is used to generate the return type when the return value is
a copy of the input.  This is of particular importance for
operations like atomicLoad, whose purpose is to atomically obtain
a local copy of a shared value.


More information about the Digitalmars-d-learn mailing list