May 2018

Transform-reduce is a pattern in which a set of data is first modified by applying a transformation on each of the elements and then it is reduced to a single value. In C++, this can be implemented straightforwardly with std::transform and std::accumulate. In C++17, an alternative for std::accumulate is available; std::reduce sums a range of elements just like std::accumulate, except that it does so out of order. That means you cannot use it with operators that are not communicative or associative (including overloads of operator+ that don’t exhibit these properties). On the other hand, there is yet another algorithm called std::transform_reduce that applies a functor to all the elements of a range and then reduces them, all in an out of order manner. And then, there are also parallel versions of these algorithms. In this post, I will try to compare the performance of these possible alternatives for implementing transform-reduce.

Read More Transform and reduce alternatives

The title might be a little bit misleading because, on one hand, you might not find these things funny if you are stumbling upon them and not understanding what is going on, and, on the other hand, they are not really strange when you pay attention to what is going on. However, here is a list of five (randomly picked) C++ features that would probably get you giving a second thought to what’s going on.

Read More C++ fun strange facts