cas and pointers

Stanislav Blinov stanislav.blinov at gmail.com
Mon Oct 31 09:06:41 PDT 2011


I've been looking into cas recently and I came to wonder why it doesn't 
provide actual support for pointers.

The current declaration of cas looks roughly like this:

bool cas(shared(T)* here, const V1 ifThis, const V2 writeThis) if 
(__traits(compiles,mixin("*here = writeThis")))

which, with transitive const, means that if T, V1 and V2 are, say, X*, 
then this declaration would be equivalent to

bool cas(shared(X*)* here, const(X*) ifThis, const(X*) writeThis) if 
(__traits(compiles,mixin("*here = writeThis")))

and as such, __traits(compiles) here will obviously return false, as you 
cannot assign const pointer to a non-const one. For example, you would 
not be able to compile even examples from Andrei's book.

I wonder if there is some overwhelming reason why this is so, or is it 
just that current implementation lacks specialization for pointers?


More information about the Digitalmars-d mailing list