gpt4 book ai didi

c++ - 每行一个 Clang 格式数组初始值设定项

转载 作者:行者123 更新时间:2023-12-05 05:55:04 24 4
gpt4 key购买 nike

Clang 格式,给定一个带有初始值设定项的结构数组,每行放置两个项目:

sym keywords[] = {
{0, 0, "C"}, {0, 0, "T"},
{0, 0, "V"}, {0, 0, "ax"},
{0, 0, "bool"}, {0, 0, "break"},
...
{0, 0, "val"}, {0, 0, "vector"},
{0, 0, "version"}, {0, 0, "void"},
{0, 0, "while"},
};

我怎样才能让它每行只放一个项目?

clang-format, array initialisers是我能找到的最接近这个问题的讨论,但是所提出的解决方案都没有任何效果; Cpp11BracedListStyle: false 做同样的事情,除了大括号之间有额外的空格,正如你在上面看到的,确保最后一个项目后有一个逗号,没有帮助。

最佳答案

我不完全确定,但是将 ArrayInitializerAlignmentStyle 设置为 left 可能会实现该结果。此选项是在 clang-format 版本 13 中添加的。

至少我当前的设置会将您的代码变成:

sym keywords[] = {
{0, 0, "C" },
{0, 0, "T" },
{0, 0, "V" },
{0, 0, "ax" },
{0, 0, "bool" },
{0, 0, "break" },
{0, 0, "val" },
{0, 0, "vector" },
{0, 0, "version"},
{0, 0, "void" },
{0, 0, "while" },
};

如果我删除该设置,我会得到类似于您的结果。

我当前的设置,在其他位置可能不符合您的预期:

---
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
BreakBeforeBraces: Allman
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
ColumnLimit: 120
EmptyLineBeforeAccessModifier: Always
FixNamespaceComments: true
IncludeBlocks: Regroup
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 4
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
PackConstructorInitializers: NextLine
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 10
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 10
PenaltyBreakString: 10
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 10
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
ReflowComments: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpacesInCStyleCastParentheses: false
Standard: Latest
TabWidth: 4
UseTab: Never

关于c++ - 每行一个 Clang 格式数组初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69537052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com