ReSharper 2018.2 Help

Code Templates in C++

All ReSharper's code template features are also supported in C++. You can find the detailed information on these features in the corresponding topics of the Code Templates section.

Live Templates

Live/Surround templates can be used for generating code in existing files and (if there is the $SELECTION$ parameter in the template body) for surrounding code fragments with template code, such as try...catch statement.
Each live template is identified by a Shortcut — a short string of characters, e.g. foreach — that you can type right in the editor to invoke the template.

ReSharper provides plenty of predefined live templates. You can also create custom live templates in the dedicated editor or right from existing source code .

File Templates

File templates are used to create one or more new files with predefined code, such as a type declaration, unit test, etc. File templates have no shortcuts, they are identified by their descriptions. See Creating Files from Templates \ and Creating Multi-File Templates for details.

A file template can create more than one file when you apply the template. This may be helpful when related data is saved in different files.

There are predefined templates for class and struct. You can also create new file and multi-file templates.

Postfix Templates

Postfix templates help you transform expressions that you have already typed without jumping backwards — just type a dot after an expression and pick a template from the completion list.

Below is the list of postfix templates available in C++.

Shortcut

Description

Example

.beg..end

Produces iterators from range

sort(range.begin(), range.end())

.cbeg..cend

Produces iterators from range

is_sorted(range.cbegin(), range.cend())

.const_cast

Surrounds expression with const_cast

const_cast<SomeType &>(expr)

.do

Iterating until boolean expression becomes 'false'

do { } while (expr);

.dynamic_cast

Surrounds expression with dynamic_cast

dynamic_cast<SomeType &>(expr)

.else

Checks boolean expression to be 'false'

if (!expr)

.foreach

Iterates over range

foreach (auto && x in range)

.if

Checks boolean expression to be 'true'

if (expr)

.make_shared

Constructs an object and wraps it in a std::shared_ptr

std::make_shared<SomeType>()

.make_unique

Constructs an object and wraps it in a std::unique_ptr

std::make_unique<SomeType>()

.new

Produces instantiation expression for type

new SomeType()

.reinterpret_cast

Surrounds expression with reinterpret_cast

reinterpret_cast<SomeType &>(expr)

.return

Returns expression from current function

return expr;

.static_cast

Surrounds expression with static_cast

static_cast<SomeType>(expr)

.switch

Produces switch over integral/enum type

switch (expr)

.var

Introduces variable for expression

auto x = expr;

.while

Iterating while boolean expression is 'true'

while (expr)

Last modified: 28 November 2018