A pitfall with std::partial_sum()

Consider a situation: you get a buffer with some network packets and their
sizes: void Packetize(std::vector<uint8_t> &buffer, std::vector<uint16_t>
&sizes). Now to send the packets out, you need to calculate packet offsets.
What could be easier with STL:

The code is simple, elegant, builds and works well while your buffer is less
than 64K. But then you discover that for the bigger buffers, the offsets aren’t
monotonic. Right, the function
partial_sum
accumulates into a variable of type of the input iterator!

So either you should ensure that the sizes are stored as a sufficiently
large integers (for instance, uint32_t) or use Boost’s transform_iterator: