lundi 30 septembre 2019

Which one is more efficient the method std::basic_string::append or the operator '+'?

Which one is more efficient in avoiding unnecessary copy the append method or the Operator + in C++11?

std::string salute = "Hello";
std::string message = salute.append("Namaste");

OR

std::string salute = "Hello";
std::string message = salute + "Namaste";

Operator + allocates a new buffer but it also has R-value reference constructor which avoids the copy of the rvalue. On the contrary append doesn't allocate new buffer(Right?) but doesn't have any overloaded function with R-value reference parameter.

Aucun commentaire:

Enregistrer un commentaire