有人可以确认从该函数出来的字符串是否实际上会被移动到成员变量中?
class Foo {
private:
const std::string m_complex_str;
std::string create_complex_str() {
return std::string("some huge string");
}
public:
Foo() : m_complex_str(std::move(create_complex_str())) { }
};
这是正确的方法吗?
也许大多数编译器会在没有移动功能的情况下为我做这件事?