mercredi 25 mars 2015

Summing together same-key items from a multimap?

I'm aware this has been asked on here before:


stl::multimap - how do i get groups of data?


but the answer:



pair<Iter, Iter> range = my_multimap.equal_range("Group1");
int total = accumulate(range.first, range.second, 0);


does not compile for me, when I do:



pair<multimap<int32_t, float>::iterator, multimap<int32_t, float>::iterator>> range = multimap.equal_range(an_int);
float total = accumulate(range.first, range.second, 0);


This was on GCC 4.8


Could anyone confirm whether they can compile this/offer the correct answer?


Aucun commentaire:

Enregistrer un commentaire