C++ ReSharper reformat of comma initializer for Eigen matrix

I am using ReSharper 2017.1.2 and am having trouble finding the settings that will get this code to reformat in a desirable way.  I am using Eigen (http://eigen.tuxfamily.org) in C++ to do matrix math, and ReSharper likes to add extra spaces before the commas in the comma initializer. It also does not properly indent the lines.

Currently I get this when applying a reformat:

Matrix3d tilt_mat;
tilt_mat << 1 , 0 , 0 , // notice the spaces before the commas
0 , cos(tilt) , sin(tilt) , // notice the not-aligned indent
0 , -sin(tilt) , cos(tilt);

 

But what I would like to get is this:

Matrix3d tilt_mat;
tilt_mat << 1, 0, 0,
0, cos(tilt), sin(tilt),
0, -sin(tilt), cos(tilt);

 

Is there a setting to help with this that I am missing?  I have every setting labeled "Before comma in *" under C++ > Formatting Style > Spaces unchecked.  My suspicion is that ReSharper is treating the commas as a binary operator.

I realize this syntax is kind of goofy, but it is the only way to initialize a matrix in Eigen.  I'm not entirely sure how the Eigen folks created the comma initializer construct.  I wasn't aware you could even write code for a comma operator in C++.

4 comments

Hello Kyle,

You are correct, R++ is confused because the comma is an overloaded operator, we'll fix this (https://youtrack.jetbrains.com/issue/RSCPP-19669). As for the indentation, I'm not sure what kind of setting we need to introduce to make it possible, but we'll think about this.

Thanks for the issue report!

0

Actually we have the "Indentation and Alignment | Chained binary expressions" setting, which, should it have worked, would have given the required indentation. We'll investigate why it fails on this snippet. Thanks again!

0

Yes I have the Chained binary expressions setting checked.

 

Side note:

There are also times when it is nice to align all the cells of a matrix initialization.  I'm not sure how you would discern this situation, but maybe you can give that some thought too.  Like this:

Matrix3d tilt_mat;
tilt_mat << 1, 0, 0,
0, cos(tilt), sin(tilt),
0, -sin(tilt), cos(tilt);

 

I would probably want this in C# too.  Something like this:

Matrix3x3 tilt_mat = new Matrix3x3(1,               0,              0,
0, Math.Cos(tilt), Math.Sin(tilt),
0, -Math.Sin(tilt), Math.Cos(tilt));

This is just a "would be nice to have", not something I actually expect to be possible.

0

Please sign in to leave a comment.