Configure code generation

Hello and sorry for the generic title but I could not come up with anything useful. Currently I have a few troubles which are easily illustrated with the following code:

Snippet

namespace A::B::C
{
    class Simple
    {
    public:
        Simple(const int& a);
private:
      int m_A;
    };
}

 

Let's use Context Action to generate a function definition in a separate cpp file. That's what I've got:

A::B::C::Simple::Simple(const int & a)
{
}

And I have 2 problems with this code:

1. Irrespective of whether I have using namespace A::B::C in the cpp or not I have this long unnecessary appendage of the namespaces in the function (ctor here) definition.

2. The ampersand symbol is in the position I do not like it to be. I'd like it to be stuck to to the type instead of flying around.

And another example: now I'm trying to initialize my member variable with the ctor argument, I type the name but do not bother to type it fully so I hit Enter letting the system autocomplete it and so I get:

Snippet

A::B::C::Simple::Simple(const int & a):
    m_A()
{
}

 

But I do not want to have "()", I want to have "{}".

So my question/suggestion is: is there any way I can influence the system to generate the code I want instead of some predefined styles. And if there is no way to do it currently I very much suggest you to add it since it is quite annoying to change the style after each function generation.

 

Thanks!

 

 

4 comments
Comment actions Permalink

Hello Evgeniy,

I can't reproduce the issue with redundant qualification. I have test.h 

namespace A::B::C
{
class Simple
{
public:
Simple(const int& a);
void foo();
private:
int m_A;
};
}

And test.cpp:

#include "test.h"

using namespace A::B::C;

void Simple::foo()
{
}

If I generate implementation of Simple::Simple, I do not get the redundant qualification.

To change the placement of the ampersand symbol you need to change formatting settings:

To use uniform unitialization, check the "Use uniform initialization in member initializers" checkbox in ReSharper | Options | Code Editing | C++ | Code style.

0
Comment actions Permalink

Hey Igor, 

Please, check out this video: https://www.screencast.com/t/suDMtzNnuWaZ

I've also checked the spacing setting and it is turned off: https://www.screencast.com/t/4n2kcBex

And I still have the function generated with a whitespace before the ampersand.

Thanks for the uniform initialization tip: it helped! But should not this setting also be somewhere in "Formatting style"?

P.S. I have the latest stable Resharper++ installed.

0
Comment actions Permalink

You are using the Visual Studio action (note the VS icon in the lightbulb). R++'s context action is near the top of the context menu.

Type of initialization is not really a formatting style, because semantics differ between different initialization styles. It's more of a code style setting, which R++ does not have at the moment - we might add it later.

0
Comment actions Permalink

Thank you! I've always thought it is the other way around (bulb from R#/++ and simple icons from MSVS). I will also close the bug in the tracker since it is an MSVS bug.

0

Please sign in to leave a comment.