Re: this by rvalue
Jan Bielawski wrote:
Is there a way to overload on the rvalue-ness of the invoking object
itself?
SG wrote:
Yes. That's where "ref qualifiers" come in:
class X {
public:
void foo() &;
void foo() &&;
};
Is this available?
Good question. Is there any compiler already supporting ref qualifiers for
member functions?
I do think so, yes. Have a look at the examples from a paper by Daveed
Vandevoorde and Bronek Kozicki, Extending Move Semantics To *this,
www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1821.htm
The first example shows how an lvalue ref qualifier can be used to avoid
accidentally taking the address of an rvalue, or assigning to an rvalue:
struct S {
S* operator &() &;
S& operator=(S const&) &;
};
The second example shows how an rvalue ref qualifier allows move semantics
for the data of an rvalue object:
class X {
std::vector<char> data_;
public:
// ...
std::vector<char> const & data() const & { return data_; }
std::vector<char> && data() && { return data_; }
};
(Both examples are from the paper.)
Actually I did a proposal to add lvalue ref qualifiers to assignment
operators in the Standard Library. Written together with Daniel Kruegler:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2819.html
Hopefully, it will be discussed during the next meeting of the std
committee...
Kind regards, Niels
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center