P
Paul Brettschneider
Hello,
C++0x introduces the concept of rvalue-references (described for example
here: http://www.artima.com/cppsource/rvalue.html) and, if I got this
right, an rvalue-reference is an invitation to mutilate the referenced
object since it is a temporary which will not be used anymore. Which
enables us to implement (amongst other things) move semantics.
But, inside a function which gets an rvalue-reference it is treated like a
normal reference, which makes sense since you don't want your object
destroyed after accessing it once.
std::move() will turn a normal (lvalue-)reference into an rvalue-reference.
Therefore the idiomatic rvalue-copy-constructor and
rvalue-assignment-operator will look like this:
class Test : public Base {
Object a;
public:
Test(Test &&t)
: Base(std::move(t))
, a(std::move(t.a))
{ };
Test &operator=(Test &&t)
{
Base:perator=(std::move(t));
a = std::move(t.a);
return *this;
}
};
So my question is: will the rvalue-copy-constructor and the
rvalue-copy-operator be automaticall generated or will we have to write it
on our own?
Thanks!
C++0x introduces the concept of rvalue-references (described for example
here: http://www.artima.com/cppsource/rvalue.html) and, if I got this
right, an rvalue-reference is an invitation to mutilate the referenced
object since it is a temporary which will not be used anymore. Which
enables us to implement (amongst other things) move semantics.
But, inside a function which gets an rvalue-reference it is treated like a
normal reference, which makes sense since you don't want your object
destroyed after accessing it once.
std::move() will turn a normal (lvalue-)reference into an rvalue-reference.
Therefore the idiomatic rvalue-copy-constructor and
rvalue-assignment-operator will look like this:
class Test : public Base {
Object a;
public:
Test(Test &&t)
: Base(std::move(t))
, a(std::move(t.a))
{ };
Test &operator=(Test &&t)
{
Base:perator=(std::move(t));
a = std::move(t.a);
return *this;
}
};
So my question is: will the rvalue-copy-constructor and the
rvalue-copy-operator be automaticall generated or will we have to write it
on our own?
Thanks!