i using clang-format (version 3.5) emacs (version 24.5.2). here simple piece of code formatted clang-format in llvm style:
int main() { std::cout << "> "; std::string word; while (std::cin >> word) { std::cout << std::accumulate(word.cbegin(), word.cend(), 0, [](int cur, char ch) { return cur + (ch - '0'); }) << std::endl << "> "; } return 0; } note how aligned body , closing brace of lambda. there logic formatting or it's lack of support lambdas? there configuration parameters of clang-format need set better formatting?
std::accumulate(word.cbegin(), word.cend(), 0, [](int cur, char ch) { return cur + (ch - '0'); })
here have long function call. clean up, take long argument, , split onto own line:
std::accumulate(word.cbegin(), word.cend(), 0, [](int cur, char ch) { return cur + (ch - '0'); }) when this, indent argument line (:
std::accumulate(word.cbegin(), word.cend(), 0, [](int cur, char ch) { return cur + (ch - '0'); }) so far good. have open {. well, means new line
std::accumulate(word.cbegin(), word.cend(), 0, [](int cur, char ch) { return cur + (ch - '0'); }) with indent. base of indent? well, start of std::accumulate. add 4 spaces:
std::accumulate(word.cbegin(), word.cend(), 0, [](int cur, char ch) { return cur + (ch - '0'); }) then hit }. new line, backdent:
std::accumulate(word.cbegin(), word.cend(), 0, [](int cur, char ch) { return cur + (ch - '0'); }) finally, embed in middle of larger expression, , mess had above.
the above purely reasonable story, , not based off expertise of clang-format. cannot tell how make better.
Comments
Post a Comment