All posts in "Smart pointers"

The Pitfalls of Aliasing Pointers in Modern C++

Published January 22, 2019 - 0 Comments

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 […]

A Free Ebook on C++ Smart Pointers

Published December 25, 2018 - 2 Comments
C++ smart pointers free ebook

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 […]

How to implement the pimpl idiom by using unique_ptr

Published September 22, 2017 - 16 Comments

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 […]

How to Return a Smart Pointer AND Use Covariance

Published September 12, 2017 - 11 Comments

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 […]

Polymorphic clones in modern C++

Published September 8, 2017 - 3 Comments

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 […]

Changing deleters during the life of a unique_ptr (4/7)

Published September 5, 2017 - 2 Comments

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 […]

How to Make Custom Deleters More Expressive

Published September 1, 2017 - 3 Comments

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 […]

Smart developers use smart pointers (3/7) – Custom deleters

Published August 29, 2017 - 14 Comments

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, […]

unique_ptr, shared_ptr, weak_ptr, scoped_ptr, raw pointers – Knowing your smart pointers (2/7)

Published August 25, 2017 - 7 Comments

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 […]