This is guest post written by a guest author Benjamin Bourdin. If you’re also interested to share your ideas on Fluent C++, check out our guest posting area. With the advent of smart pointers in Modern C++, we see less and less of the low-level concerns of memory management in our business code. And for […]
To write expressive code in C++, mastering smart pointers is a necessity! Without them, our code becomes littered with memory management, news and delete, and unclear semantics about who owns what resources. If you’re part of my mailing list (which you can join at the bottom of this post), you will get as a Christmas gift […]
The pimpl, standing for “pointer to implementation” is a widespread technique to cut compilation dependencies. There are a lot of resources about how to implement it correctly in C++, and in particular a whole section in Herb Sutter’s Exceptional C++ (items 26 to 30) that gets into great details. There is one thing that I’ve found […]
Today we’re going to take a big step back on the specific problem of the clone interface we’ve dealt with on the last post. For this Raoul Borges is taking over on this topic to show you a solution to the general problem of smart pointers and covariance in C++. Raoul is a C++ developer […]
How to copy an object that is accessible only by an interface that it implements? This question has been around for a very long time, and is associated with a classical solution described by Scott Meyers in Item 25 of More Effective C++. This solution still works, but can benefit from modern C++ features that weren’t in the […]
A previous episode in the Smart developers use Smart pointers series showed how (and why) to use custom deleters in std::unique_ptr. Now let’s see the methods that change the custom deleter during the life of the unique_ptr and, also, those that don’t. This aspect of smart pointers has been pointed out to me by Mathieu Ropert and Raoul Borges. Thanks guys. The […]
Most of the times where we use std::unique_ptr, we’re fine without using a custom deleter. But sometimes, a custom deleter offers a way out of a tricky situation. Now that we’ve seen how to use custom deleters and when they can be useful, I would like to share with you a technique to make their usage […]
The previous episodes of the series explained what smart pointers are, and which ones to use in your code. Here I show a technique that allows to encapsulate complex memory management into std::unique_ptr, to relieve your code from low-level memory manegement. The series Smart developers use smart pointers contains: Smart pointer basics unique_ptr, shared_ptr, weak_ptr, scoped_ptr, […]
This is episode 2 in y series Smart Developers Use Smart Pointers. The series contains: Smart pointer basics unique_ptr, shared_ptr, weak_ptr, scoped_ptr, raw pointers: clearly stating your intentions by knowing your smart pointers Custom deleters and How to make them more expressive Changing deleters during the life of a unique_ptr How to implement the pimpl idiom […]
One thing that can rapidly clutter your C++ code and hinder its readability is memory management. Done badly, this can turn a simple logic into an inexpressive slalom of mess management, and make the code lose control over memory safety. The programming task of ensuring that all objects are correctly deleted is very low in terms […]