How a weak_ptr might prevent full memory cleanup of managed object
When I was working on the Smart Pointer Reference Card I run into a quite interesting issue. It appears that in some cases memory allocated for the object controlled by smart_ptr might not be released...
View ArticleC++ Status at the end of 2017
In Poland, it’s only a few hours until the end of the year, so it’s an excellent chance to make a summary of things that happened to C++! As you might guess the whole year was dominated by the...
View ArticleThe 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....
View Articlepimpl Abstract Interface - a practical tutorial
Let’s see pimpl and its alternatives in a real application! I’ve implemented a small utility app - for file compression - where we can experiment with various designs.Is it better to use pimpl or maybe...
View ArticleHow to propagate const on a member pointer?
Inside const methods all member pointers become constant pointers. However sometimes it would be more practical to have constant pointers to constant objects.So how can we propagate such constness?The...
View ArticleFactory With Self-Registering Types
Writing a factory method might be simple:unique_ptr<IType> create(name){if(name =="Abc")return make_unique<AbcType>();if(name =="Xyz")return...
View ArticleStatic Variables Initialization in a Static Library, Example
This post is motivated by one important comment from my last article about factories and self-registering types:(me) So the compiler won’t optimize such variable.Yet, unfortunately, the linker will...
View ArticleWhat happens to your static variables at the start of the program?
Saying that C++ has simple rules for variables initialization is probably quite risky :) For example, you can read Initialization in C++ is Bonkers : r/cpp to see a vibrant discussion about this...
View ArticleSimplify code with 'if constexpr' in C++17
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,...
View ArticleThe C++ Standard Library book - overview & giveaway
Let’s have a quick overview of another book related to Modern C++ and The Standard Library. This time I picked Rainer Grimm’s book the author of the modernescpp blog.Read more if you’d like to win C++...
View ArticleDeprecating Raw Pointers in C++20
The C++ Standard moves at a fast pace. Probably, not all developers caught up with C++11/14 yet and recently we got C++17. Now it’ time to prepare C++20! A few weeks ago The C++ Committee had an...
View ArticleProductive C++ Developer, my recent talk
A few weeks ago I gave another talk at my local C++ user group. We discussed recent “goodies” from C++ and tools that can increase productivity. IntroRecent C++ UpdatesToolsThe SlidesSummaryIntroIn my...
View ArticleRefactoring with C++17 std::optional
There are many situations where you need to express that something is “optional” - an object that might contain a value or not. You have several options to implement such case, but with C++17 there’s...
View ArticleUsing C++17 std::optional
Let’s take a pair of two types <YourType, bool> - what can you do with such composition?In this article, I’ll describe std:optional - a new helper type added in C++17. It’s a wrapper for your...
View ArticleC++ Templates - The Complete Guide 2nd Book Review
A few months ago I received a quite massive mail package with something that was looking like a brand new C++ book :)My initial plan was to review it quickly, maybe in one month. But I failed, as...
View ArticleError Handling and std::optional
In my last two posts in the C++17 STL series, I covered how to use std::optional. This wrapper type (also called “vocabulary type”) is handy when you’d like to express that something is ‘nullable’ and...
View ArticleShow me your code: std::optional
Show me your code!I’d like to run a little experiment. Let’s build a wall of examples of std::optional! IntroThe rulesThe giftThe SeriesIntroIn the last three articles of my C++17 STL series I’ve been...
View ArticleEverything You Need to Know About std::variant from C++17
Around the time C++17 was being standardized I saw magical terms like “discriminated union”, “type-safe union” or “sum type” floating around. Later it appeared to mean the same type: “variant”.Let’s...
View ArticleA Wall of Your std::optional Examples
Two weeks ago I asked you for help: I wanted to build a wall of examples of std::optional. I’m very grateful that a lot of you responded and I could move forward with the plan!You’re amazing!Let’s dive...
View ArticleEverything You Need to Know About std::any from C++17
With std::optional you can represent some Type or nothing. With std::variant you can wrap several variants into one entity. And C++17 gives us one more wrapper type: std::any that can hold anything in...
View Article