简体   繁体   中英

clang-format for Eigen matrix initialization

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?

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

Did you try this?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM