#include using namespace std; int main() { std::string str = "Salut"; std::vector v; // uses the push_back(const T&) overload, which means // we'll incur the cost of copying str v.push_back(str); std::cout << "After copy, str is " << std::quoted(str) << '\n'; // uses the rvalue reference push_back(T&&) overload, // which means no strings will be copied; instead, the contents // of str will be moved into the vector. This is less // expensive, but also means str might now be empty. v.push_back(std::move(str)); cout << "After move, str is " << std::quoted(str) << '\n'; cout << "After move, str size is " << str.size() << endl; std::cout << "The contents of the vector are { " << std::quoted(v[0]) << ", " << std::quoted(v[1]) << " }\n"; } // Possible output: // After copy, str is "Salut" // After move, str is "" // The contents of the vector are { "Salut", "Salut" }