What is the most powerful algorithm in the STL? In the world? There are many cases to be made. But this talk explores what I think is a pretty good candidate, which C++ calls
std::accumulate(). Tucked away in
<numeric>, perhaps relatively unregarded when compared with workhorses like
std::find_if() and
std::partition(); nevertheless,
std::accumulate() is in some sense the ur-algorithm on sequences.
Let’s explore the result of looking at code through an accumulate-shaped lens, how tweaking the algorithm for better composability can unlock many more uses, and how it can be further genericized with applications to parallelism, tree structures, and heterogeneous sequences.
std::accumulate(): it’s not just for adding things up!