[eigen] correct use of rvalue referenes |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: Eigen <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] correct use of rvalue referenes
- From: Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>
- Date: Fri, 27 Aug 2010 08:06:26 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=8tuG8nP7douOmqZYspaaY9UcbKwYYp2rphNuiPPsuDo=; b=NxmrPEqyM7KIT/TNeSyMzAdu/WlfSbjMh0qIYR5tqiPEP+lbhk+wnkA5hhY0Teo97V Ui+gQok86twTI43wtBjc00RBq0O0MZOhtB0Tni6Bm6fEj0oe/9XMSJxJmeY/DtxQhhn+ TLQ7nzXsUGcFgldMxE9utj88HenNXxBe7KFpU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=Vgwc660r1OKmpJ+BwJ1XmObCPOhKslEZpcSy8UPLTQHVTKBe+sECUS5pboGF+xnouR v3kvKRxAKTCjwg63X2zKGnP00qrnZovzGNbYFClOh/jMokln3lS8lqYZWtIyp5YwyUfK hi0wyCnIn8DnB4e22jaudR9fGrj8U5UTT+gro=
Well, I have to admit that I did something seriously wrong the last
time and that MSVC's implementation is absolutely correct!
Only rvalue reference can be converted to rvalue references and here
'd' is an lvalue. The correct implementation would be to use
std::move.
On Wed, Aug 4, 2010 at 12:04 PM, Hauke Heibel
<hauke.heibel@xxxxxxxxxxxxxx> wrote:
> struct Base {};
> struct Derived : public Base {};
> void buggy(Base&& b) {}
>
> int main()
> {
> Derived d;
> buggy(d);
> }
The main should look like this:
int main()
{
Derived d;
buggy(std::move(d)); // convert the lvalue to an rvalue
buggy(Derived()); // work with a real rvalue
}
Regards,
Hauke