All posts in "STL"

Make Your Containers Follow the Conventions of the STL

Published April 24, 2018 - 8 Comments
conventions STL

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

How to Reorder A Collection With the STL

Published April 20, 2018 - 5 Comments
permutations STL rotate

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

How to Pass a Polymorphic Object to an STL Algorithm

Published April 17, 2018 - 3 Comments
polymorphic object stl C++

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

Moving Ranges Around with STL Algorithms

Published April 13, 2018 - 5 Comments
Moving ranges

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

Which One Is Better: Map of Vectors, or Multimap?

Published April 10, 2018 - 11 Comments
map vector multimaps C++

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

Is std::for_each obsolete?

Published March 30, 2018 - 13 Comments
C++ for_each

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

What Heaps Can Do That Priority Queues Don’t

Published March 23, 2018 - 4 Comments

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

1 6 7 8 9 10 12