如何避免 clang-format 将两个单独的'>'格式化为一个班次?

How to avoid clang-format to format two separate '>' into a shift?

当我使用 clang 格式化我的 C++ 代码时,我 运行 遇到了一个问题:

priority_queue<int, vector<int>, greater<int> > q;

会自动格式化为:

priority_queue<int, vector<int>, greater<int>> q;

两个单独的 '>' 将被格式化为一个 shift >>.

那么我应该如何配置.clang-format文件来避免这种情况呢?

您可以使用标准选项。您需要 C++03 选项(包括 C++98),因为这会在模板中格式化双 > 以在它们之间包含一个白色 space。

Standard: Cpp03

您甚至可以使用 Auto,这样 clang-format 就可以自动检测所使用的 C++ 版本。