英文:
How to indent lambdas in complex assignment expressions by 4 spaces
问题
I have an assignment expression like this (formatted by clang-format):
auto typeParams = node->typeParams | std::views::transform([&](auto p) {
return m_irCtx.make(IRGenericType(p));
});
I would like to have it formatted like this:
auto typeParams = node->typeParams | std::views::transform([&](auto p) {
return m_irCtx.make(IRGenericType(p));
});
Which .clang-format option controls how lambdas are indented relative to the parent scope? How can I achieve this?
EDIT: Setting LambdaBodyIndentation
to OuterScope
does not change anything.
英文:
I have an assignment expression like this (formatted by clang-format):
auto typeParams = node->typeParams | std::views::transform([&](auto p) {
return m_irCtx.make(IRGenericType(p));
});
I would like to have it formatted like this:
auto typeParams = node->typeParams | std::views::transform([&](auto p) {
return m_irCtx.make(IRGenericType(p));
});
Which .clang-format option controls how lambdas are indented relative to the parent scope? How can I achieve this?
EDIT: Setting LambdaBodyIndentation
to OuterScope
does not change anything
答案1
得分: 1
这种特殊情况(如果它是唯一的情况或仅有少数情况之一),我会手动格式化:
// clang-format off
auto typeParams = node->typeParams | std::views::transform([&](auto p) {
return m_irCtx.make(IRGenericType(p));
});
// clang-format on
是的,这有点作弊。如果clang-format的输出符合您的要求,它会工作得相当不错,但您无法配置它执行任何其他操作。在这些情况下,您可以关闭自动化并手动进行操作。
查看相关代码,我认为右括号和圆括号应至少缩进一个级别。不过,我也不确定。如果您希望它保持这种格式,那就按照这种方式编写代码,不要让clang-format修改它。
英文:
In this specific case (and if it's the only case or only one of a few) I'd just format by hand:
// clang-format off
auto typeParams = node->typeParams | std::views::transform([&](auto p) {
return m_irCtx.make(IRGenericType(p));
});
// clang-format on
Yes, that's cheating. Clang-format works reasonably well if you're happy with what it does but you cannot configure it to do anything. In these cases, you're welcome to switch the automation off and do it manually.
Looking at the code in question, I'd say that the closing brace and parenthesis should be indented by at least one level. However, what do I know. If you want it like this, write it like this and don't let clang-format touch it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论