【发布时间】:2014-05-07 20:37:26
【问题描述】:
考虑下面的代码:
Bar my_f()
{
Foo f{args,to,create,foo};
Bar b{std::move(f),other,args}; //Is move here unnecessary?
// code that does not use f;
return b;
}
编译器是否需要检查{code that does not use f} 并自动将f 移动到b?
【问题讨论】:
-
编译器不太可能移动
f。只要遵循 as-if 规则,它可能会做一些更高效、更容易实现的事情。某处有重复。 -
无法保证编译器会这样做......我怀疑编译器会自动这样做,因为它会破坏范围规则。