Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically insert parenthesis for method calls in C++

If I want to call a function/method in C++ my normal way is to type the first letters of the name and investigate the IntelliSense suggestions. If I choose one, the name will be inserted, but it would be great if also the parenthesis could be inserted. Of course the caret should be placed in the middle of the new parenthesis. I am using Visual Studio 2015 and ReSharper. Is there a setting in VS or R# about this?

eg

std::string s; 
s.em 

the result after the use of IntelliSense should be

std::string s; 
s.empty(_CARET_);
like image 830
Applik Avatar asked Oct 16 '22 17:10

Applik


2 Answers

I don't think that having the cursor between parentheses for empty function makes sense since empty one has no parameters. But at the same time, having the cursor between parentheses for any function which has parameters is definitely handy. So, ReSharper C++ provides exactly this:

  1. in case a function has no parameters

    • type s.e;
    • hit Tab to complete empty from the completion popup;
    • as a result, you will get s.empty()_cursor_ and you can continue typing whatever you like after closing parenthesis.
  2. in case a function has parameters (e.g. append)

    • type s.a;
    • hit Tab to complete append from the completion popup;
    • as a result, you will get s.append(_cursor_) and you can specify parameters.

Well, as you may see, ReSharper C++ locates the cursor depending on a function's signature.

like image 127
Alexander Kurakin Avatar answered Oct 21 '22 01:10

Alexander Kurakin


In VS2017 you can do the following to achieve the desired result:

  • s
  • .
  • e
  • Shift+(
like image 39
Killzone Kid Avatar answered Oct 21 '22 01:10

Killzone Kid