cas function issue

Adrian Mercieca amercieca-remove-this at gmail.com
Thu Dec 29 00:01:51 PST 2011


Hi folks,

I've got this very simple program, for which I keep getting compiler errors at the 'cas' function call.

import
	std.stdio,
	core.atomic;

class Int
{
public:
	this(int v) {
		this._v = v;
	}

private:
	int _v;
}


void main()
{
	shared(Int) a = new shared(Int)(10);
	shared(Int) b = new shared(Int)(20);
	shared(Int*) p = &a;

	if ( cas(p, a, b) ) {
		writeln("Swap OK");
	}
}

The errors are:

Error: template core.atomic.cas(T,V1,V2) if (__traits(compiles,mixin("*here = writeThis"))) does not match any
function template declaration

Error: template core.atomic.cas(T,V1,V2) if (__traits(compiles,mixin("*here = writeThis"))) cannot deduce template
function from argument types !()(shared(Int*),shared(Int),shared(Int))

Is it not possible to compare and swap object references in the cas function call?
Would someone kindly tell me as to what I am doing wrong?

Thanks.
- Adrian.


More information about the Digitalmars-d-learn mailing list