With a fully compatible C ++ 0x compiler, your class will have an implicit move constructor that moves elements, as well as an implicit copy constructor. In this example, the implicit move constructor will be used.
MSVC2010 , , . , , , :
class MoveTest
{
public:
std::vector<int> m_things;
MoveTest()
{}
MoveTest(MoveTest&& other):
m_things(std::move(other.m_things))
{}
MoveTest(MoveTest const& other):
m_things(other.m_things)
{}
MoveTest& operator=(MoveTest&& other)
{
MoveTest temp(std::move(other));
std::swap(*this,temp);
return *this;
}
MoveTest& operator=(MoveTest const& other)
{
if(&other!=this)
{
MoveTest temp(other);
std::swap(*this,temp);
}
return *this;
}
};