lundi 30 mars 2020

Pass argument to function as r-value reference vs const l-value reference

Let's consider the following functions:

void processString1(const string & str) { /** **/}
void processString2(string && str) { /** **/}

processString1("Hello");
processString2("Hello");

As I assume, processString1 will invoke copy constructor and processString2 a move constructor of string. What is more efficient?

Aucun commentaire:

Enregistrer un commentaire