How to use core.atomic.cas with (function) pointers?

Johan Engelen j at j.nl
Tue Jan 22 14:13:23 UTC 2019


The following code compiles:
```
alias T = shared(int)*;

shared T a;
shared T b;
shared T c;

void foo() {
     import core.atomic: cas;
     cas(&a, b, c);
}
```

The type of T has to be a pointer to a shared int (you get a 
template match error for `cas` if `T = int*`), which is annoying 
but I kind-of understand.
However, change b to null (`cas(&a, null, c);`) and things no 
longer work: "Error: template `core.atomic.cas` cannot deduce 
function from argument types"

I have not succeeded to make things work with function pointers 
(neither with nor without `null` as second argument). What am I 
doing wrong if `alias T = void function();` ?

Thanks,
   Johan



More information about the Digitalmars-d-learn mailing list