Simple and sweet.
by Jonathan Boccara
From the article:
Merging identical consecutive elements in a collection is a recurring need, in C++ or elsewhere in programming.
For example, we could want to aggregate a collection of hourly results into a collection of daily results: all the results of each day get aggregated into one for that day. In this case, being “identical” means being on the same day, and “aggregating” means taking two results with a common date, and creating a result at this date and with the sum of their amounts...