All posts in "STL"

The Interesting Evolution of std::equal_range

Published January 10, 2022 - 0 Comments

The good old std::equal_range STL algorithm, which has been in the STL since C++98, has evolved along with the versions of C++. Starting from a poor interface and now a much better one, its story is an interesting example of how to improve the abstraction of an interface. (Good?) old C++98 equal_range The first version of […]

Find with Custom Returns

Published May 7, 2021 - 0 Comments

Some STL algorithms have a default behaviour and also accept a custom value in order to have a custom behaviour. For example, std::sort orders the elements of a collection based on comparisons with operator< by default, but it also accepts a custom function to perform comparisons: std::sort(begin(v), end(v), std::greater{}); // sorts v in descending order This is the […]

A Map with Two Types of Keys in C++

Published November 27, 2020 - 0 Comments

The need to associate keys to values is pretty common in computer programming. (That is a very general sentence, isn’t it?) In C++, the standard tools to achieve that are std::map and std::multimap that use comparisons on keys and std::unordered_map and std::unordered_multimap that use hashing. Boost adds flat_map, that offers a different performance trade-off and bimap to look […]

Adapting STL Algorithms on Sets

Published October 9, 2020 - 0 Comments

This article is NWH, standing for Not Written Here. NWH is inspired from the NIH (Not Invented Here) syndrome which consists in refraining from using existing code from outside the company and reinventing the wheel every time. Just like it is good practice to look out for solutions developed elsewhere, we’re going to look at […]

Algorithms on Sets That Return a Boolean: Implementing the Generic Algorithm

Published August 14, 2020 - 0 Comments

In the last post in our series on sets, we’ve uncovered 8 algorithms on sets that return a boolean, providing various sorts of comparisons between those two sets: std::includes share_element is_prefix_of is_one_prefix_of_other equivalent disjoint is_before is_after We also saw that each of those algorithm corresponds to a combination of 4 customisation points in a generic […]

If you see cut-paste, it is rotate

Published August 7, 2020 - 0 Comments

Today we’re taking a small break in our summer series on sets to take a refreshing dip into STL algorithms, with this guest post by Abhinav Badola. Abhinav is an open-source enthusiast who loves using C++ for learning and teaching programming concepts. You can find him on Twitter @AbhinavBadola. Thanks to Sarfaraz Nawaz and Nitul […]

Algorithms on Sets That Return a Boolean: Exploring the algorithms

Published July 31, 2020 - 0 Comments

In a previous article on sets we’ve designed share_element, an algorithm on sets (sorted collections) that returns a boolean indicating whether they have a element in common, and that operates in linear time. On the other hand, the STL also offers an algorithm on sets that return a boolean: std::includes. std::includes takes two sets and returns a […]

1 2 3 12