Carefully loop over size_type instead of iterator_difference in reduce's
loops to avoid overflowing narrow iterator_difference.