0

For example, I want my array looks like this

std::vector<std::vector<std::vector<int>>> input = {
        {
            {1, 3, 5, 7}, 
            {10, 11, 16, 20}, 
            {23, 30, 34, 60}
        }, 
        {
            {1, 3, 5, 7}, 
            {10, 11, 16, 20}, 
            {23, 30, 34, 60}
        }
    };

But with clang-format, it makes it less readable

std::vector<std::vector<std::vector<int>>> input = {{{1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 60}}, {{1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 60}}};

After checking the clang-format document (verison 20), I'm using 18 AlignArrayOfStructures: Left makes it better but it is still not what I'm trying to achieve.

std::vector<std::vector<std::vector<int>>> input = {
        {{1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 60}},
        {{1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 60}}
    };

My current clang-format configuration file,

BreakBeforeBraces: Custom
BraceWrapping:
  AfterClass:      true
  SplitEmptyFunction: false
  AfterControlStatement: true
  AfterFunction:   true
  AfterNamespace:  true
  AfterObjCDeclaration: true
  AfterStruct:     true
  AfterUnion:      true
  BeforeCatch:     true
  BeforeElse:      true
  IndentBraces:    false
  AfterCaseLabel:  true
InsertNewlineAtEOF: true
IncludeBlocks: Merge
#Clang11?: IndentCaseBlocks: true
IndentCaseLabels: true
#Clang11: IndentExternBlock: true
IndentPPDirectives: None
IndentWidth: 4
AllowShortFunctionsOnASingleLine: Empty
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PenaltyBreakAssignment: 16
PenaltyBreakBeforeFirstCallParameter: 2
PenaltyBreakString: 64
PenaltyExcessCharacter: 0
PenaltyReturnTypeOnItsOwnLine: 0
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
IncludeCategories:
  - Regex: '"*PlatformIO.h"'
    Priority: -5
  - Regex: '"*TextIOTypes.h"'
    Priority: -4
  - Regex: '<[Ww]indows.h>'
    Priority: -3
  - Regex: '<*\/.h>'
    Priority: -2
  - Regex: '"*\/.h"'
    Priority: 1

SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
UseCRLF: false
UseTab: Never
IndentAccessModifiers: true
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: AcrossEmptyLinesAndComments
ColumnLimit: 80
RemoveBracesLLVM: false
RemoveEmptyLinesInUnwrappedLines: true
RemoveSemicolon: true
3
  • I am not an expert in this, but which of the ClangFormatStyleOptions did you try ? Commented Nov 3, 2024 at 15:16
  • @Luuk I'm not sure about your question. If you are asking about my configuration, I left it below the post. If you mean the pre-defined style, I don't use any. Commented Nov 3, 2024 at 15:30
  • Add a newline between those {{, like is done here: stackoverflow.com/a/70782265/724039 Commented Nov 3, 2024 at 15:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.