在 C++/CLI“for each"中使用 clang-format [英] Using clang-format with C++/CLI "for each"
问题描述
我目前尝试使用 clang-format(9.0.0 版)格式化 C++/CLI 代码.我无法弄清楚如何处理 for each
语句.
I currently try to format C++/CLI code using clang-format (version 9.0.0). I cannot figure how to handle for each
statements.
之前:
for each (auto i in I)
{
}
之后(例如,在 Visual Studio 中按 CTRL-K/CTRL-D):
After (say, CTRL-K/CTRL-D in Visual Studio):
for
each (auto i in I)
{
}
我阅读了此处这个:
...您可能想要更改 ForEachMacros 以添加for each"
...you might want to change ForEachMacros to add "for each"
我试过了:
ForEachMacros:
- for each
- foreach
- Q_FOREACH
- BOOST_FOREACH
然后这个:
ForEachMacros:
- 'for each'
还有这个:
- "for each"
甚至这个:
- "for\s+each"
没有任何效果.有没有办法让它工作?在文档中,它写到它 (ForEachMacros
) 是一个宏向量......所以我不知道如何创建一个带有空格字符的宏!
Nothing works. Is there a way to make it works? In the doc, it is written that it (ForEachMacros
) is a vector of macros... so I don't see how a can create a macro with a space character inside!
有人可以帮我解决这个问题吗?
Can someone help me with this problem?
谢谢!
推荐答案
您可以通过定义自己的宏来解决该问题,例如#define FOR_EACH for each
,并使用该宏代替 for each
.例如.FOR_EACH(auto i in I)
.
现在 clang-format 将忽略它.
You can work around the issue by defining your own macro, e.g. #define FOR_EACH for each
, and use that macro instead of for each
. E.g. FOR_EACH(auto i in I)
.
Now clang-format will ignore it.
您可以将它添加到您的 .clang-format
文件中,ForEachMacros: ['FOR_EACH']
,因此它被作为循环处理而不是函数调用格式化.修复编译不需要.
You can add it to your .clang-format
file, ForEachMacros: ['FOR_EACH']
, so it is handled as a loop instead of a function call for formatting. Not required for fixing compilation though.
这篇关于在 C++/CLI“for each"中使用 clang-format的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!