J
Jan Bielawski
I was reading up on the new C++0x features and have a question:
Is there a way to overload on the rvalue-ness of the invoking object
itself? In other words, distinguish between:
// contrived example
X x;
x.foo();
and:
X f();
f().foo();
A less contrived example would be a member X:
perator+() which would
distinguish between the first and the second invocation in the line
below:
X x, y, z;
X xx = x + y + z
So the first + sign would resolve to <lvalue>.operator+(y), and the
second + sign would resolve to <rvalue>.operator+(z)
(where the second one is presumably moving instead of copying).
Is this available? Is it at all useful? It's as if there was a "&&"
qualifier (or whatever it's called) analogous to "const" in method
declaration:
X X:
perator+(const X& rhs) {...} // as usual
X X:
perator+(const X& rhs) && {...} // the one invoked on
rvalue
X X:
perator+(const X& rhs) const {...} // the one invoked on
const
Does this even make any sense?
Is there a way to overload on the rvalue-ness of the invoking object
itself? In other words, distinguish between:
// contrived example
X x;
x.foo();
and:
X f();
f().foo();
A less contrived example would be a member X:
distinguish between the first and the second invocation in the line
below:
X x, y, z;
X xx = x + y + z
So the first + sign would resolve to <lvalue>.operator+(y), and the
second + sign would resolve to <rvalue>.operator+(z)
(where the second one is presumably moving instead of copying).
Is this available? Is it at all useful? It's as if there was a "&&"
qualifier (or whatever it's called) analogous to "const" in method
declaration:
X X:
X X:
rvalue
X X:
const
Does this even make any sense?