mercredi 23 septembre 2020

Are move semantics implied immediately before an rvalue is destroyed?

In the following function,

void SetObject(Object object) 
{
    m_Object = object;
}

The SetObject would receive a copy of object which is an rvalue that is assigned to m_Object and immediately goes out of scope. Would move semantics would be implied so that a second copy of object isn't unnecessarily created--or are moved semantics implied? Seems like they should be, though I'm likely missing something. In other words, do I need to write this as

void SetObject(Object object) 
{
    m_Object = std::move(object);
}

Aucun commentaire:

Enregistrer un commentaire