std::vector<MyClass> vec;
for (auto &x : vec)
{
  // x is a reference to an item of vec
  // We can change vec's items by changing x 
}要么
for (auto x : vec)
{
  // Value of x is copied from an item of vec
  // We can not change vec's items by changing x
}好。
当我们不需要更改vec项目时,IMO,示例建议使用第二个版本(按值)。为什么他们不建议const参考的内容(至少我没有发现任何直接建议):
for (auto const &x : vec) // <-- see const keyword
{
  // x is a reference to an const item of vec
  // We can not change vec's items by changing x 
}好不好 它不是在每次迭代中都避免了冗余副本const吗?
const auto &x等同于您的第三选择。