Unwrap and remove statements
For C++, this refactoring safely unwraps if...else
, for
, while
, do...while
and try...catch
control statements, or accurately removes enclosing parts of the nested statements.
Besides C++, the Unwrap/Remove action is available for:
Objective-C/C++
Python
JavaScript: if ...else, for, while, and do...while control structures.
Place the caret at the expression you want to unwrap or remove.
Choose Code | Unwrap/Remove from the main menu or press CtrlShiftDelete. CLion shows a popup with all the actions that are available in the current context. Statements to be kept after unwrapping are displayed on the blue background, statements to be removed are displayed on the grey background.
Click the desired action or select it using the up and down arrow keys and press Enter.
Examples in different languages showing statements unwrapping:

Before | After |
---|---|
|
|
Before | After |
---|---|
|
|
Before | After |
---|---|
|
|
Thanks for your feedback!