All I need to do is know if something exists and how many times it exists. I will go over the existing things and ask how many of them exist.
My implementation still uses multiset , I do the following:
std::multiset<thing> a; auto previous = a.end(); for( auto each = a.begin(); each != a.end(); ++each ) { if( previous == a.end() || *previous != *each ) { a.count(*each); } previous = each; }
Explanation
I have a thing s vector. But sometimes they repeat the meaning, I want to iterate over a unique thing and do something for each unique one. This "something" should know the amount of time this thing appears on the vector.
The code I wrote above is how I solve my problem right now, this is not the most elegant way to do what I want.
I just follow the recommendations of Stackoverflow: I tell you what my problem is, and I tell my (tried) solution.
If a sentence with a question mark is really necessary, you go: is there a way to iterate over unique elements over multiset ?
André puel
source share