August 2019

17 Smaller but Handy C++17 Features--Bartlomiej Filipek

It's not all about the big things.

17 Smaller but Handy C++17 Features

by Bartlomiej Filipek

From the article:

When you see an article about new C++ features, most of the time you’ll see a description of major elements. Looking at C++17, there are a lot of posts (including articles from this blog) about structured bindings, filesystem, parallel algorithms, if constexpr, std::optional, std::variant… and other prominent C++17 additions.

But how about those smaller parts? Library or language improvements that didn’t require decades to standardise or violent “battles” at the ISO meetings.

In this article, I’ll show you 17 smaller C++17 things that will improve your code...

Combining Ranges and Smart Output Iterators--Jonathan Boccara

And the next one.

Combining Ranges and Smart Output Iterators

by Jonathan Boccara

From the article:

In our current stage of development of smart output iterators, we have:

  • some iterators, such as filter, transform, unzip or demux,
  • the possibility to combine them: filter(pred) >>= transform(f) >>= unzip(back_inserter(output1), back_inserter(output2))
  • their usage as the output iterator of an STL algorithm:
std::copy(begin(inputs), end(inputs), transform(f) >>= back_inserter(outputs));

What we’re going to work on today is removing the call to std::copy to have a pipeline made of output iterators only. And once we get such a pipeline, we will plug it to ranges, in order to benefit from the expressiveness of both ranges and smart output iterators, in the same expression...

Quick Q: When to use virtual destructors?

Quick A: When you might delete polymorphically.

Recently on SO:

When to use virtual destructors?

Virtual destructors are useful when you might potentially delete an instance of a derived class through a pointer to base class:

class Base
    // some virtual methods

class Derived : public Base
        // Do some important cleanup

Here, you'll notice that I didn't declare Base's destructor to be virtual. Now, let's have a look at the following snippet:

Base *b = new Derived();
// use b
delete b; // Here's the problem!

Since Base's destructor is not virtual and b is a Base* pointing to a Derived object, delete b has undefined behaviour...

ReSharper C++ 2019.2 has arrived with improved C++20 support, new code analysis checks, and more

Welcome ReSharper C++ 2019.2 release!

ReSharper C++ 2019.2: Faster indexing, improved C++20 support, new code analysis checks, and better Unreal Engine support

by Anastasia Kazakova

The new update brings:

  • 15-25% faster indexing on typical solutions like LLVM or Unreal Engine.
  • More sophisticated support for Unreal Engine (built-in documentation for reflection specifiers, RPC support in refactorings, specific UE4 code analysis checks).
  • More C++20 support (char8_t and conditional explicit support, pack expansion in lambda init-capture, default constructible and assignable stateless lambdas, and more).
  • Updates to built-in code analysis (new checks to catch unmatched preprocessor directive and redundant final function specifier in a final class).
  • Updates to code completion, navigation, and code formatter.
  • New code hints.

C++ Core Guidelines: Supporting Sections--Rainer Grimm

Table of contents.

C++ Core Guidelines: Supporting Sections

by Rainer Grimm

From the article:

Let's recapitulate. In the last two years, I have written about 100 posts to the C++ Core Guidelines. Why? The document answers:  "This document is a set of guidelines for using C++ well. The aim of this document is to help people to use modern C++ effectively.". But my story does not end here. The guidelines have a supporting section...

Presenter Interviews: Kate Gregory--Kevin Carpenter

Discover the person presenting at CppCon.

Presenter Interviews: Kate Gregory

by Kevin Carpenter

From the article:

In this week’s presenter interview, Kevin Carpenter welcomes back Kate Gregory to preview her upcoming talk Naming is Hard: Let’s Do Better. Kate’s talk will discuss how bad we as C++ developers can be when it comes to naming things and how we could improve.

Quick Q: Where and why do I have to put the “template” and “typename” keywords?

Quick A: to help the compiler understand what the programmer wants.

Recently on SO:

Where and why do I have to put the “template” and “typename” keywords?

In order to parse a C++ program, the compiler needs to know whether certain names are types or not. The following example demonstrates that:

t * f;

How should this be parsed? For many languages a compiler doesn't need to know the meaning of a name in order to parse and basically know what action a line of code does...

Getting Started with the PVS-Studio Static Analyzer for C++ Development under Linux

There are different ways to install PVS-Studio under Linux, depending on your distro type. The most convenient and preferred method is to use the repository, since it allows auto-updating the analyzer upon releasing new versions.

Getting Started with the PVS-Studio Static Analyzer for C++ Development under Linux

by Yuri Minaev

From the article:

Besides strace, you can base the analysis on the compile_commands.json (JSON Compilation Database) file. Many build systems have built-in means of exporting compilation commands, or you could use the BEAR utility to do this. Here's the command to launch the analysis in this case: pvs-studio-analyzer analyze –f /path/to/compile_commands.json