Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-07-29 00:50:38


"Eric Lemings" <lemings_at_[hidden]> writes:

> Greetings,
>
> I'm trying to come up with an algorithm that will "collapse" a sequence
> of integer constants by adding like elements together. For example,
>
> typedef vector_c< int, 1,1,1,3,5,5,7,10,10 > input;
>
> would become:
>
> typedef vector_c< int, 3, 3, 10, 7, 20 > result;
>
> You can assume the sequence is already sorted. Would appreciate any
> tips.

You could use mpl::fold with a "state" that consists of a pair
containing the (partial) new sequence and the last element of the
input sequence processed so far.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net