I have defined a map like this
typedef std::vector< int > aVector;
typedef std::map< int, aVector > aMap;
aMap theMap;
Assume that the map finally contains some elements like this
10 [0 3 7] size=3
12 [40 2 30 3 10] size=5
20 [5 10] size=2
25 [6] size=1
I want to sort on the size of the vector (e.g theMap->second.size()). So the result will be
5 3 2 1
What is the fastest way to do that? The basic idea is to push the sizes on another vector and then call sort(), like this
aVector v, sorted;
aMap::iterator it = theMap.begin();
for (; it != theMap.end(); ++it) {
v.push_back(it->second.size());
}
// using std sort!!
Is there any better option?