When using the STL, there is a use case that pops up every now and then and that often causes more trouble than necessary: if we have a collection of pairs, like an std::vector of pairs, or simply a std::map, how can we retrieve the collection of the first elements of each item in the […]
Transferring a std::unique_ptr to another std::unique_ptr is an easy thing to do: std::unique_ptr<int> p1 = std::make_unique<int>(42); std::unique_ptr<int> p2; p2 = std::move(p1); // the contents of p1 have been transferred to p2 Easy peasy, lemon squeezy. Now what if those unique_ptrs are living inside of two sets? It should be just as easy to transfer those in the […]
Counting words in code, what an exciting topic! Ok, if you don’t see what exactly is exciting in counting words in code, maybe a little context will help. Word counts can reveal useful information about a piece of code, and with the right tooling, it takes very little time to perform. Reading code is one […]
For the third episode in our series about removing things from C++ containers, let’s tackle the tricky topic of removing duplicates from associative containers! The articles of the series are: How to Remove Elements from a Sequence Container (vector, string, deque, list) How to Remove Pointers from a Vector in C++ (co-written with Gaurav Sehgal) How […]
Welcome back for our second part in our series on removing elements from C++ containers! How to Remove Elements from a Sequence Container (vector, string, deque, list) How to Remove Pointers from a Vector in C++ (co-written with Gaurav Sehgal) How to Remove Elements from an Associative Container (maps and sets) How to Remove Duplicates from […]
Today we have a post co-written with Gaurav Sehgal, a software engineer who works with C and C++. Gaurav can be found on his Stack Overflow profile as well as on LinkedIn. Interested in writing on Fluent C++ too? Check out our guest posting area! As we saw in the article about removing elements from […]
As part of the STL Learning Resource, we’re tackling today the STL algorithms that remove elements from a collection. Removing an element from a C++ collection can’t be that complicated, can it? Well, how can I put it… It has a rich complexity, let’s say. Ok, maybe it’s a little complicated. We will cover this […]
Everyone knows that it’s a good thing to know the STL algorithms. But do know each and every one of them? To learn all there is in the STL algorithms library, I’ve presented a talk at several conferences this year, that was titled 105 STL Algorithms in Less Than an Hour. The point of this […]
We all know that we should know our STL algorithms, because they help make our code more expressive and more robust (sometimes in spectacular ways!). But do you know all your STL algorithms? There are 105 of them if we include those of C++17, and every one of them has a chance to be useful […]
C++17 has deprecated a few components that had been in C++ since its beginning, and std::iterator is one of them. If you don’t have C++17 in production, you’re like most people today. But one day or the other, your will have it, most likely. And when that day comes, you’ll be glad you anticipated the […]