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

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

Incorrect indentation when using an if statement inside a lambda expression

问题

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

  1. // 这是我的VS2022代码
  2. // ...
  3. for_each(v.begin(), v.end(), [&evenCount](int n) {
  4. cout << n;
  5. if (n % 2 == 0) {
  6. cout << " 是偶数 " << endl;
  7. ++evenCount;
  8. } else {
  9. cout << " 是奇数 " << endl;
  10. }
  11. });
  12. // ...
  1. // 这是MSDN示例代码
  2. // ...
  3. for_each(v.begin(), v.end(), [&evenCount] (int n) {
  4. cout << n;
  5. if (n % 2 == 0) {
  6. cout << " 是偶数 " << endl;
  7. ++evenCount;
  8. } else {
  9. cout << " 是奇数 " << endl;
  10. }
  11. });
  12. // ...

如果我在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.

  1. // This code is my VS2022
  2. // ...
  3. for_each(v.begin(), v.end(), [&amp;evenCount](int n) {
  4. cout &lt;&lt; n;
  5. if (n % 2 == 0) {
  6. cout &lt;&lt; &quot; is even &quot; &lt;&lt; endl;
  7. ++evenCount;
  8. }
  9. else {
  10. cout &lt;&lt; &quot; is odd &quot; &lt;&lt; endl;
  11. }
  12. });
  13. // ...
  1. // This code is MSDN example
  2. // ...
  3. for_each(v.begin(), v.end(), [&amp;evenCount] (int n) {
  4. cout &lt;&lt; n;
  5. if (n % 2 == 0) {
  6. cout &lt;&lt; &quot; is even &quot; &lt;&lt; endl;
  7. ++evenCount;
  8. } else {
  9. cout &lt;&lt; &quot; is odd &quot; &lt;&lt; endl;
  10. }
  11. });
  12. // ...

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:

确定