I'm just curious about the new std :: move () function, which has just been added to the latest C ++ standard.
Having finished reading the article about this and found out that the definition of function
namespace std {
template <class T>
inline typename remove_reference<T>::type&& move(T&& x)
{
return x;
}
}
There seems to be no difference between calling std :: move and using casting.
For instance,
class NPC{
int m_number1;
int m_number2;
public:
NPC() : m_number1(1), m_number2(2) {
cout << "NPC Constructor called!" << endl;
}
NPC(NPC&& _npc) : m_number1(_npc.m_number1), m_number2(_npc.m_number2) {
_npc.m_number1 = 0;
_npc.m_number2 = 0;
cout << "NPC Move Constructor called!" << endl;
}
};
int main() {
NPC n1;
NPC n2 = std::move(n1);
cout << "----------------" << endl;
NPC n3;
NPC n4 = (NPC&&)n3;
return 0;
}
Is it right to think that in principle there is no difference? Well, I'm pretty much sure that I'm right, but I also know that being too confident always causes unpleasant consequences.
Thanks in advance!
source
share