cas and pointers
Sean Kelly
sean at invisibleduck.org
Mon Oct 31 10:07:31 PDT 2011
writeThis really shouldn't be const, it should be shared. The problem was that making writeThis a shared pass by value param implied a synchronized load for writeThis, which is undesirable for cas. So I left the declaration of cas as specified in TDPL and thought I'd figure this out later.
Sent from my iPhone
On Oct 31, 2011, at 9:06 AM, Stanislav Blinov <stanislav.blinov at gmail.com> wrote:
> 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