9

To inialize for example Eigen::Matrix3i we can use syntax:

Eigen::Matrix3i T;
T << 1, 0, 0,
     0, 2, 0,
     0, 0, 3;

However, when using clang-format (3.6 in my case) with Google style this nice initialization turns into:

Eigen::Matrix3i T;
T << 1, 0, 0, 0, 2, 0, 0, 0, 3;

Is there an easy way to avoid this? Is there a way to tell clang-format to skip something like this?

niosus
  • 738
  • 8
  • 22

2 Answers2

7

It looks like your only option is to use a rather ugly clang-format switching syntax:

Eigen::Matrix3i T;
// clang-format off
T << 1, 0, 0,
     0, 2, 0,
     0, 0, 3;
// clang-format on
yuyoyuppe
  • 1,582
  • 2
  • 20
  • 33
  • 7
    Uglifying the code so the prettifier doesn't uglify it seems to be sort of invalidating the point though. – Cubic Apr 13 '16 at 11:09
  • Ugh. Well, this is a solution, but yeah, I agree with @Cubic here. I will leave the question open for some time in case somebody comes up with something else. If this does not happen, I will accept this as an answer. – niosus Apr 13 '16 at 11:23
  • @Cubic yeah, I agree too, but this solution could be viable if you're forced to use two coding styles(e.g. for checkout and commits) and in similar situations – yuyoyuppe Apr 13 '16 at 11:26
2

Did you try this?

Eigen::Matrix3i T;
T << 1, 0, 0, //
     0, 2, 0, //
     0, 0, 3; //
Joan Solà
  • 123
  • 6