Код: Выделить всё
void f(std::string) { ... }
void f_c(const std::string) { ... }
void g()
{
f(std::string("Hello world!")); // moved, isn't it?
f("Hello world!"); // moved, isn't it?
f_c(std::string("Hello world!")); // moved, isn't it?
f_c("Hello world!"); // moved, isn't it?
}
Иногда пользователи пытались заставить семантику перемещения с помощью функции std :: move :
Код: Выделить всё
std::string return_by_value_1()
{
std::string result("result");
return std::move(result); // Is this moved or not?
}
std::string return_by_value_2()
{
return std::move(std::string("result")); // Is this moved or not?
}
Подробнее здесь: https://stackoverflow.com/questions/284 ... o-be-moved
Мобильная версия