One day I had to do a little refactoring that consisted in renaming a method called getSize() into size(), because I needed to pass its class to generic code that expected a method size(). And what made this refactoring a little special is that this class was used very widely across a pretty large codebase. This is not something […]
The STL lets you do plenty of things on collections, and one of them is to reorder the elements inside of the collection. Or, said another way, to perform a permutation on the collection. Inded, moving elements around a collection typically takes a fair amount of complex code to write, involving for loops and iterators. And it […]
As we can read in the opening chapter of Effective C++, C++ is a federation of 4 languages: the procedural part coming from C, the object-oriented part, the STL part (following a functional programming paradigm), the generic part with templates. And what’s more, all of those 4 sub-languages are part of one whole: the C++ […]
We’ve seen various ways to achieve complex operations on ranges with STL algorithms along the posts of the STL Learning Resource. Let’s now see how to just move collections around. A much simpler topic… …or is it? Heaving ranges around There are essentially 3 STL algorithms that allow to move several elements of a collection in […]
While advising on how to make code more expressive on the SFME project, I came across an interesting case of choosing the right data structure, which I’ll share with you with the permission of the authors of the projects. We had to associate a key with several values, and perform various operations. Should we use […]
I’m often asked the question: with C++11 introducing range-based for loops, is std::for_each now useless? And the short answer is: No. Let’s give a quick recap on for_each and range-based for loops, and then a heuristic for choosing between the two. for_each and range-for loops for_each std::for_each is an STL algorithm that takes a collection of elements (in the form of a begin and […]
Heaps are implementations of priority queues. But what’s the point of having multiple STL algorithms that manipulate heaps in the form of a range, if you can directly use a priority queue structure? What heaps allow you to do that priority queues don’t? This is the question we tackle in this week’s video. The series […]
Heaps, that we saw how to manipulate with the STL, are in a close relationship with queues and priority queues. Let’s what those structures are, how to manipulate them in C++ and what the link between all this is. This is Part 3 in our series about heaps and priority queues: Part 1: Heaps Basics […]
Now that you’re familiar with what heaps are and how they work, let’s see how the STL lets us manipulate them in C++. This is Part 2 in our series about heaps and priority queues: Part 1: Heaps Basics Part 2: Building, Unbuilding and Sorting Heaps (video) Part 3: Queues, Priority Queues and Heaps Part […]
One of our 7 good resolutions for the new year was to learn our data structures. Indeed, using the right data structure simplifies the code, and knowing them lets you understand the code that uses them. Let’s see two related data structures, heaps and priority queues. This is a deep topic that we are going to […]