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(), [&evenCount](int n) {
cout << n;
if (n % 2 == 0) {
cout << " is even " << endl;
++evenCount;
}
else {
cout << " is odd " << endl;
}
});
// ...
// This code is MSDN example
// ...
for_each(v.begin(), v.end(), [&evenCount] (int n) {
cout << n;
if (n % 2 == 0) {
cout << " is even " << endl;
++evenCount;
} else {
cout << " is odd " << 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?
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