Non Static Data Members Initialization

With modern C++ and with each revision of the standard we get more comfortable way to initialise fields of a class: both static and non-static: there’s non-static data member initialisation (from C++11) and also inline variables (for static members since C++17). In this blog post, you’ll learn how to use the syntax and how it changed over the years from C++11, through C++14, C++17 until C++20.

READ MORE...

IIFE for Complex Initialization

What do you do when the code for a variable initialization is complicated? Do you move it to another method or write inside the current scope? In this blog post, I’d like to present a trick that allows computing a value for a variable, even a const variable, with a compact notation.

READ MORE...

Moved or Not Moved - That Is the Question!

C++11 brought Move Semantics. Since then we have extra capabilities to write faster code, support movable-only types, but also more headaches :). At least I have, especially when trying to understand the rules related to that concept. What’s more, we also have copy elision, which is a very common optimisation (and even mandatory in several cases in C++17).

READ MORE...

Lambdas: From C++11 to C++20, Part 1

Lambda expressions are one of the most powerful additions to C++11, and they continue to evolve with each new C++ language standard. In this article, we’ll go through history and see the evolution of this crucial part of modern C++. The second part is available: Lambdas: From C++11 to C++20, Part 2

READ MORE...

The Pimpl Pattern - what you should know

Have you ever used the pimpl idiom in your code? No matter what’s your answer read on :) In this article I’d like to gather all the essential information regarding this dependency breaking technique. We’ll discuss the implementation (const issue, back pointer, fast impl), pros and cons, alternatives and also show examples where is it used.

READ MORE...

C++17 in details: Code Simplification

With each C++ standard, we aim for simpler, cleaner and more expressive code. C++17 offers several “big” language features that should make our code nicer. Let’s have a look. Intro You might say that most of the new language features (not to mention The Standard Library improvements) are there to write simpler/cleaner code.

READ MORE...

C++17 in details: Attributes

“C++ Attributes… what?” There were almost 40% votes like that in my recent Twitter survey. Maybe It would be good to introduce that little-known feature? There’s even a good occasion, as in C++17 we’ll get even more useful stuff connected with attributes. Interested? Intro Have you ever used __declspec, __attribute or #pragma directives in your code?

READ MORE...