在lambda表达式内部使用if语句时缩进不正确。

huangapple go评论54阅读模式
英文:

Incorrect indentation when using an if statement inside a lambda expression

问题

我使用VS2022,粘贴以下示例中的代码会写成:即使您按Ctrl + K + F进行排序,它也会按如下方式排序。

// 这是我的VS2022代码
// ...

for_each(v.begin(), v.end(), [&evenCount](int n) {
  cout << n;
  if (n % 2 == 0) {
    cout << " 是偶数 " << endl;
    ++evenCount; 
  } else {
    cout << " 是奇数 " << endl;
  }
});

// ...
// 这是MSDN示例代码
// ...

for_each(v.begin(), v.end(), [&evenCount] (int n) {
  cout << n;
  if (n % 2 == 0) {
     cout << " 是偶数 " << endl;
     ++evenCount;
  } else {
     cout << " 是奇数 " << endl;
  }
});

// ...

如果我在lambda表达式内部使用if语句,自动缩进不正确。不规则。

我的VS2022设置有问题吗?

英文:

I'm using VS2022, and pasting the code from the following example will write: Even if you press Ctrl + K + F to sort all, it will be sorted like below.

// This code is my VS2022
// ...

for_each(v.begin(), v.end(), [&amp;evenCount](int n) {
  cout &lt;&lt; n;
if (n % 2 == 0) {
  cout &lt;&lt; &quot; is even &quot; &lt;&lt; endl;
  ++evenCount; 
}
else {
  cout &lt;&lt; &quot; is odd &quot; &lt;&lt; endl;
}
  });

// ...
// This code is MSDN example
// ...

for_each(v.begin(), v.end(), [&amp;evenCount] (int n) {
  cout &lt;&lt; n;
  if (n % 2 == 0) {
     cout &lt;&lt; &quot; is even &quot; &lt;&lt; endl;
     ++evenCount;
  } else {
     cout &lt;&lt; &quot; is odd &quot; &lt;&lt; endl;
  }
});

// ...

If I use an if statement inside a lambda expression, automatic indentation is not correct. Not regular.

Is something wrong with my VS2022 settings?

答案1

得分: 1

相似的问题已在开发者社区上报告。尝试使用 VS2022 版本 17.5 预览 5.0。

链接: https://developercommunity.visualstudio.com/t/auto-indentaion-not-working-in-the-lambd/10201118

英文:

Similar problems hava been reported on Developer Community. Try VS2022 version 17.5 preview 5.0.

Link: https://developercommunity.visualstudio.com/t/auto-indentaion-not-working-in-the-lambd/10201118

huangapple
  • 本文由 发表于 2023年2月10日 14:02:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75407453.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定