如何使用clang-format控制三元运算符的缩进
How to control indent of ternary operator using clang-format?
如何控制clang-format中三元运算符的缩进?我想要有普通延拓独立,例如
int foobar = bar ? a
: b;
我得到了运算符
的对齐int foobar = bar ? a
: b;
我已经有AlignOperands: false什么好主意吗?
(完整选项:style='{BasedOnStyle: LLVM, TabWidth: 4, IndentWidth: 4, ContinuationIndentWidth: 8, UseTab: Always, alignafteropen括号:false, BreakBeforeBinaryOperators: All, AlwaysBreakTemplateDeclarations: true, AlignOperands: false, ColumnLimit: 120}')
我相信如果合并https://reviews.llvm.org/D50078会解决这个问题。
如果你想更花哨,我可以推荐这段代码。
int a = 10;
int b = 20;
bool flag = true;
int c =
flag ?
a
: b;
std::cout << c << "n";
或者你可以这样做,你的选择:
当多个三元操作符链接时,例如if/else-if/else if/……/else序列,clang-format将继续对齐冒号使用问号,这增加了每个的缩进条件:
int a = condition1 ? result1
: condition2 ? result2
: condition3 ? result3
: result4;
此补丁检测情况(例如,在false分支中使用条件)在这种情况下,为了避免缩进:
int a = condition1 ? result1
: condition2 ? result2
: condition3 ? result3
: result4;
当BreakBeforeTernaryOperators为false时,其格式如下:
int a = condition1 ? result1 :
condition2 ? result2 :
conditino3 ? result3 :
result4;
相关文章:
- 三元运算符和 if constexpr
- 在 c++ 中三元运算符中不允许继续(关键字)吗?
- 三元运算符在返回语句中给出意外的结果
- 递归中三元运算符的奇怪行为
- 错误:三元运算符无法在对象中正常工作"cout"
- 是否允许三元运算符在C++中计算两个操作数?
- 有条件地选择带有 decltype() 和三元运算符的类型
- 三元运算符在C++中的意外行为
- 有没有办法将 for 循环结果返回到像三元运算符这样的函数中?
- 变量值,在三元运算符之后
- 是否可以在C++中使用三元运算符在 if 语句中选择比较运算符?
- c++中的增量和三元运算符优先级
- C++中三元运算符的意外行为
- 用于返回开关的三元运算符
- 替换模板元编程中的三元运算符
- 三元运算符 '?:' 在 4.9.0 之前的 GCC 版本中推断出不正确的类型?
- 在 std::map 上使用三元运算符和 std::更大的附加参数
- "Do nothing"在三元运算符的其他部分?
- 如何确定三元运算符的返回类型?
- 无法使用三元运算符有条件地分配"istream &"?