1

When I use clang to format my C++ codes, I ran into a problem:

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

will be automatically formatted into:

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

Two separate '>' will be formatted into a shift >>.

So how should I configure the .clang-format file to avoid this situation?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Thesharing
  • 336
  • 4
  • 15

1 Answers1

6

There is the Standard option that you can use. You want the C++03 option (which would include C++98), as that would format double > in templates to include a white space in between them.

Standard: Cpp03

You can even use Auto instead so that clang-format can auto detect the C++ version used.

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
  • 2
    As an addition, the `Standard` option can also be set to `Auto`, in which case it will be formatted as C++11 if it looks like C++11 code, and C++03 otherwise. `Cpp03` (or equivalently, `C++03`) makes more sense in the OP's specific case, but `Auto` could be more appropriate if the OP wants to set it globally. –  Oct 22 '17 at 09:43
  • @hvd Isn't `Auto` the default? So assuming that OP didn't not know about "Standard", `Auto` didn't work correctly? – Rakete1111 Oct 22 '17 at 09:45
  • No, the default is `Cpp11`, at least according to my system's `clang-format -dump-config` output. –  Oct 22 '17 at 09:47
  • @hvd Ahh. Thanks for the info! :) – Rakete1111 Oct 22 '17 at 09:47