由于 RVO 是标准保证,因此通常具有容器返回功能,例如:
std::function<MyClass> get_elements() {
...
}
在这种情况下,我看到了两种类型的范围 - 用于迭代返回值(x 值):
for (auto const &e : get_elements()) // 1. Binding each element to a const reference
for (auto &&e : get_elements()) // 2. Binding each element to an r-value reference
两者中的一个是首选/鼓励的还是它们有什么不同?