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