You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置clang-format:lambda作为函数参数时仅在体前换行

clang-format 14.0 配置实现Lambda作为函数参数时的特定换行格式

要实现Lambda作为函数参数时,仅在Lambda签名与体的大括号前换行(而非整个Lambda换行到函数参数外),可以通过调整以下配置参数实现:

BreakBeforeBraces: Custom
BraceWrapping:
  BeforeLambdaBody: true
  AfterFunction: true
AllowAllArgumentsOnNextLine: false
LambdaBodyIndentation: Signature
AllowShortLambdasOnASingleLine: false

配置说明:

  • AllowAllArgumentsOnNextLine: false:阻止clang-format将整个Lambda参数换行到函数调用括号的下一行,确保call([]()部分保持在同一行。
  • BraceWrapping/BeforeLambdaBody: true:强制Lambda体的大括号前换行,满足格式要求。
  • LambdaBodyIndentation: Signature:让Lambda体的缩进与Lambda签名对齐,匹配期望的缩进效果。

应用该配置后,代码会被格式化为:

call([]()
     {
       return 0; 
     })

内容的提问来源于stack exchange,提问作者Simon Kraemer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 05:48:22