vendredi 9 janvier 2015

Returning compare_exchange_weak() result by reference?

I have the following code:



struct X{
explicit X(int b) : a(b);
int a;
}

struct Y{

X& peek(X a){
return X(g.load());
}

X& pop() const{
int val = 0;
return X(g.exchange(val));
}

X g;
}


and I am getting errors regarding invalid initialization of non-const reference of type X from an rvalue.


whilst I am trying to do:



Y something;
..
X& x = something.pop();


I would like to perform the compare and swap, but I want to return the resultant memory by reference, not making a copy?


Aucun commentaire:

Enregistrer un commentaire