ReSharper 2017.2 Help

Predefined Surround Templates for C++

ReSharper | Templates Explorer | Surround Templates | C++

This topic lists all predefined surround templates for C++ in ReSharper 2017.2. For more information about surround templates, see Surrounding Code Fragments with Templates

TemplateDetails
()

Surround the selection with parentheses

Scope C++ expressions, C# 2.0+ expressions

Body

($SELECTION$$END$)

Parameters

  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
{}

Surround the selection with braces

Scope C++ statements, C# 2.0+

Body

{ $SELECTION$$END$ }

Parameters

  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
forr

Code snippet for common 'for' loop pattern with integer index and reversed iteration order

Scope C++ statements

Body

for (int $INDEX$ = $MAX$ - 1; $INDEX$ >= 0 ; --$INDEX$) { $SELECTION$$END$ }

Parameters

  • INDEX - Suggests non-used name which can be used for an index variable at the evaluation point. (suggestIndexVariable)
  • MAX - no macro
  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
foreach

Code snippet for 'range-based for' loop

Scope C++ statements

Body

for ($TYPE$ $VARIABLE$ : $COLLECTION$) { $SELECTION$$END$ }

Parameters

  • COLLECTION - Show basic code completion list at the point where the variable is evaluated (complete)
  • TYPE - Show smart code completion list at the point where the variable is evaluated (completeSmart)
  • VARIABLE - When exectuted in variable declaration (where variable name should stand), suggests name for the variable. (suggestVariableName)
  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
do

Code snippet for do-while loop

Scope C++ statements

Body

do { $SELECTION$$END$ } while ($EXPR$);

Parameters

  • EXPR - Evaluates to the specified constant value. (constant)
  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
fori

Code snippet for common 'for' loop pattern with integer index

Scope C++ statements

Body

for (int $INDEX$ = 0; $INDEX$ < $UPPER$; ++$INDEX$) { $SELECTION$$END$ }

Parameters

  • INDEX - Suggests non-used name which can be used for an index variable at the evaluation point. (suggestIndexVariable)
  • UPPER - no macro
  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
if

Code snippet for 'if' statement

Scope C++ statements

Body

if ($EXPR$) { $SELECTION$$END$ }

Parameters

  • EXPR - Evaluates to the specified constant value. (constant)
  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
try

Code snippet for try...catch statement

Scope C++ statements

Body

try { $SELECTION$$END$ } catch ($EXCEPTION$) {}

Parameters

  • EXCEPTION - Evaluates to the specified constant value. (constant)
  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
while

Code snippet for 'while' statement

Scope C++ statements

Body

while ($EXPR$) { $SELECTION$$END$ }

Parameters

  • EXPR - Evaluates to the specified constant value. (constant)
  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
static_cast

Surround the selected expression with static_cast

Scope C++ expressions

Body

static_cast<$TYPE$>($SELECTION$)

Parameters

  • TYPE - Guess type expected at this point (guessExpectedType)
  • SELECTION - The text selected by the user before invoking the template.
struct

Surround selected declarations with struct

Scope C++ type-member declarations, C++ class declarations

Body

struct $NAME$ { $SELECTION$ };

Parameters

  • NAME - no macro
  • SELECTION - The text selected by the user before invoking the template.
dynamic_cast

Surround the selected expression with dynamic_cast

Scope C++ expressions

Body

dynamic_cast<$TYPE$>($SELECTION$)

Parameters

  • TYPE - Guess type expected at this point (guessExpectedType)
  • SELECTION - The text selected by the user before invoking the template.
namespace

Add a namespace to the selected code

Scope C++ namespace declarations, C++ top-level declarations

Body

namespace { $SELECTION$$END$ }

Parameters

  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
#if...#endif

Code snippet for #if...#endif preprocessor directive

Scope C++

Body

#if $END$ $SELECTION$ #endif

Parameters

  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
const_cast

Surround the selected expression with const_cast

Scope C++ expressions

Body

const_cast<$TYPE$>($SELECTION$)

Parameters

  • TYPE - Guess type expected at this point (guessExpectedType)
  • SELECTION - The text selected by the user before invoking the template.
reinterpret_cast

Surround the selected expression with reinterpret_cast

Scope C++ expressions

Body

reinterpret_cast<$TYPE$>($SELECTION$)

Parameters

  • TYPE - Guess type expected at this point (guessExpectedType)
  • SELECTION - The text selected by the user before invoking the template.
cast

Cast the selection to a specific type

Scope C++ expressions

Body

(($TYPE$) $SELECTION$)

Parameters

  • TYPE - Guess type expected at this point (guessExpectedType)
  • SELECTION - The text selected by the user before invoking the template.
namespace ...

namespace ...

Scope C++ namespace declarations, C++ top-level declarations

Body

namespace $NAME$ { $SELECTION$$END$ }

Parameters

  • NAME - Evaluates to the specified constant value. (constant)
  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
class

Add a class to the selected code

Scope C++ class declarations, C++ type-member declarations

Body

class $NAME$ { $SELECTION$ };

Parameters

  • NAME - no macro
  • SELECTION - The text selected by the user before invoking the template.
incg

Surround selection with an include guard

Scope C++

Body

#ifndef $FILENAME$_H #define $FILENAME$_H $SELECTION$ #endif // $FILENAME$_H

Parameters

  • FILENAME - Evaluates current file name without extension (getFileNameWithoutExtension)
  • DATE - Evaluates file creation date and time (getCreationTime)
  • SELECTION - The text selected by the user before invoking the template.
if...else

Put the selection into an if statement block and add an else block

Scope C++ statements

Body

if ($COND$) { $SELECTION$ } else { $END$ }

Parameters

  • COND - Suggests variables of the specified type. (variableOfType)
  • SELECTION - The text selected by the user before invoking the template.
  • END - The caret position after the template is applied.
Last modified: 11 December 2017