We’ve been over a various set of smart output iterators over the past few weeks. Today we explore how to combine them and create expressive code. If you’re just joining our series on smart output iterators, you might want to check out this introductory post on smart output iterators. So far, we’ve been combining smart […]
If you’ve been reading Fluent C++ over the past few weeks, then you’ve noticed that we spent some time on smart output iterators. Those little components allow to write expressive code when it comes to applying operations on collections, and in particular when there are multiple outputs to those operations. When I was at the […]
std::is_permutation is an STL algorithm that checks if two collections contain the same values, but not necessarily in the same order. We have encountered is_permutation in the STL algorithms on permutations, and we’ve seen how it was implemented. If you’d like a refresher on std::permutation, check out those two articles to get warmed up. Today we’re focusing […]
Knowing your STL algorithms is a good thing. And knowing what’s inside of them is a great way to go further in their study. In that spirit, let’s dig into the implementation of std::is_permutation. It’s a nice algorithm to study, as it can be implemented by using other STL algorithms and it has some interesting […]
A couple of months ago, I made a talk at the ACCU conference about learning every algorithm there is in the STL. Amongst them, we covered std::copy_backward, that makes a copy of a source range to a destination range, starting from its end and working its way back to the beginning. In the questions session at […]
Filling out a collection with random numbers is C++ is an easy thing to conceive, but it isn’t that easy to guess how to implement. In this article you will find the following: how to generate a random number in modern C++ (it’s not with rand() any more), how to override the contents of an existing […]
After seeing how to send individual objects to a curried object, let’s see how we can haul a whole collection into one of those curried creatures. One use case for this is to intersperse a collection of strings with commas. If you’re jumping in the topic of curried objects just now, a curried object is […]
Ranges, STL algorithms and smart output iterators are three libraries that perform operations on collections and make code more expressive. Even if they have some specificities, like zip for ranges and unzip for smart output iterators for example, as we saw when combining ranges with output iterators, they also share features in common, such as transform and filter. […]
In a previous post, we explored the partition output iterator, that routes data into two directions according to a predicate: the elements that satisfy the predicate to one side, and those that don’t to another side: auto const isEvenPartition = partition([](int n){ return n % 2 == 0; }); std::copy(begin(input), end(input), isEvenPartition(back_inserter(evenNumbers), back_inserter(oddNumbers))); The above code […]
A couple of months (or years?) back, we saw that partitioning in the STL meant tidying up data according to a predicate: all that satisfy the predicate in one group, and all that don’t satisfy the predicate in another group: This is what the STL algorithms std::partition (or std::stable_partition to keep the relative order of elements) do: auto […]