29 Jul
2006
29 Jul
'06
4:50 a.m.
"Eric Lemings"
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