March 2018

Simplify code with ‘if constexpr’ in C++17—Bartlomiej Filipek

With examples.

Simplify code with 'if constexpr' in C++17

by Bartlomiej Filipek

From the article:

Before C++17 we had a few, quite ugly looking, ways to write static if (if that works at compile time) in C++: you could use tag dispatching or SFINAE (for example via std::enable_if). Fortunately, that’s changed, and we can now take benefit of if constexpr!

Let’s see how we can use it and replace some std::enable_if code.

Quick Q: What is a non-trivial constructor in C++?

Quick A: All constructors that you define are not trivial.

Recently on SO:

What is a non-trivial constructor in C++?

In simple words a "trivial" special member function literally means a member function that does its job in a very straightforward manner. The "straightforward manner" means different thing for different kinds of special member functions.

For a default constructor and destructor being "trivial" means literally "do nothing at all". For copy-constructor and copy-assignment operator, being "trivial" means literally "be equivalent to simple raw memory copying" (like copy with memcpy).

If you define a constructor yourself, it is considered non-trivial, even if it doesn't do anything, so a trivial constructor must be implicitly defined by the compiler.

In order for a special member function to satisfy the above requirements, the class must have a very simplistic structure, it must not require any hidden initializations when an object is being created or destroyed, or any hidden additional internal manipulations when it is being copied.

For example, if class has virtual functions, it will require some extra hidden initializations when objects of this class are being created (initialize virtual method table and such), so the constructor for this class will not qualify as trivial.

For another example, if a class has virtual base classes, then each object of this class might contain hidden pointers that point to other parts of the very same object. Such a self-referential object cannot be copied by a simple raw memory copy routine (like memcpy). Extra manipulations will be necessary to properly re-initialize the hidden pointers in the copy. For this reason the copy constructor and copy-assignment operator for this class will not qualify as trivial.

For obvious reasons, this requirement is recursive: all subobjects of the class (bases and non-static members) must also have trivial constructors.

A Foolish Consistency—Jon Kalb

A very interesting article that we should all read.

A Foolish Consistency

by Jon Kalb

From the article:

Ralph Waldo Emerson famously said, “A foolish consistency is the hobgoblin of little minds, adored by little statesmen and philosophers and divines.” I don’t think he was talking about code, but that statement couldn’t be more relevant to software engineers.

I’ve experienced a scenario like this a number of time in my career:

I’m sharing a new approach to writing code that offers some clear improvements to what we’ve been doing. Perhaps it is more readable, more efficient, or safer. But the response that I hear from colleagues is, “But we can’t do that here. We have <some large number> lines of code where we didn’t do it that way, so it wouldn’t be consistent.”

C++17 Features, in easy to understand before/after tables—Tony Van Eerd

Results of a recent survey suggest that many devs have a hard time keeping up with changes between each rev of C++.

C++17 before and after table

by Tony Van Eerd

About the article:

Here's a collection of the major changes between C++14 and C++17, with example code for each - typically showing how it may have been written before C++17, and how it can now be written with the new C++17 feature(s).



C++ Rename Shootout: Visual Studio 2017 vs. ReSharper for C++—Richard Thomson

A comparison of two automatic rename tools for C++ in Visual Studio.

C++ Rename Shootout: Visual Studio 2017 vs. ReSharper for C++

by Richard Thomson

About the post:

Getting help from your development environment for renaming identifiers can be a huge productivity boost. It lets you quickly and easily improve the names of things in your code. In this post, I’ll review two automatic renaming tools for C++ in Visual Studio: Visual Studio 2017 Community Edition 15.5.7 and ReSharper for C++ 2017.3.2.

CopperSpice: Regular Expressions

New video on the CopperSpice YouTube Channel:

Regular Expressions

by Barbara Geller and Ansel Sermersheim

About the video:

This video covers Regular Expressions, what they are and when you might want to use them. We also discuss when to avoid using a regex. We cover existing regex libraries that can be used in C++, briefly examine their pros and cons, and present the CopperSpice regular expression implementation.

Please take a look and remember to subscribe!

Clang 6.0.0 released

LLVM 6.0.0 and Clang 6.0.0 are now available.

Clang 6.0.0 Release Notes

From the announcement:

Clang’s default C++ dialect is now gnu++14 instead of gnu++98. This means Clang will by default accept code using features from C++14 and conforming GNU extensions. Projects incompatible with C++14 can add -std=gnu++98 to their build settings to restore the previous behaviour.

Added support for some features from the C++ standard after C++17 (provisionally known as C++2a but expected to be C++20). This support can be enabled with the -std=c++2a flag. This enables:

  • Support for __VA_OPT__, to allow variadic macros to easily provide different expansions when they are invoked without variadic arguments.
  • Recognition of the <=> token (the C++2a three-way comparison operator).
  • Support for default member initializers for bit-fields.
  • Lambda capture of *this.
  • Pointer-to-member calls using const &-qualified pointers on temporary objects.

A warning has been added for a <= token followed immediately by a > character. Code containing such constructs will change meaning in C++2a due to the addition of the <=> operator.

Clang implements the “destroying operator delete” feature described in C++ committee paper P0722R1 <>, which is targeting inclusion in C++2a but has not yet been voted into the C++ working draft. Support for this feature is enabled by the presence of the standard library type std::destroying_delete_t.


Results summary: C++ Foundation Developer Survey “Lite”, 2018-02

From last Monday through this Monday, we ran our first global C++ developer survey.

Thank you to the over 3,200 of you who responded. As promised, here is a public summary of the results:

Results summary: C++ Developer Survey "Lite": 2018-02

This summary has now been forwarded to the C++ standards committee, along with the full text of your write-in answers (over 300 pages!). Your feedback will be very helpful, and has already started to be referred to by standards participants as we prepare for next week's ISO meeting in Jacksonville, FL, USA.

Thank you again for your participation. It is very helpful, and based on the success of this survey we plan to run it again in the future from time to time. When we do, it will be announced here on


Note: Due to a SurveyMonkey bug, the word clouds showing popular keywords for the five open-ended questions cover about half the responses, which fortunately is still a large sample. They're working on a fix to include all the responses in the word clouds.

Selective argument application—Krzysztof Ostrowski

Presentation of a technique that enables transparent interception of the selected arguments passed to any function by means of a user-provided predicate metafunction.

Selective argument application

by Krzysztof Ostrowski

From the article:

Presentation of a design of an interceptor abstraction built over C++17 utilities that records values of the selected arguments passed to any action transparently, then applies that action to the captured arguments, and eventually passes the result value to the next action.