Question: I have a `map<int int>`. I need to get a vector of the first int (the keys), but sorted in the second int's order (the value). What would be the fastest method to do this?

Answer: 
You could create a second map in which you swap the `<key,value>` pairs to `<value,key>`. However, you will run into trouble if you have duplicate values.

What you might actually want is a bidirectional map. E.g., see <http://www.boost.org/doc/libs/1_47_0/libs/bimap/doc/html/index.html> .
You could put it into a `std::vector<std::pair<int, int> >` and then write a predicate to sort on the second value. Then access the keys via the first value in the pair:

```
std::map<int, int>         the_map;
typedef std::pair<int,int> pair_type;

the_map[1] = 2;
the_map[2] = 1;
the_map[3] = 8;
the_map[4] = 8;
the_map[5] = 3;

struct Pred {
    bool operator()(pair_type const& a, pair_type const& b) const {
        return (a.second < b.second);
    }   
};  
struct Tran {
    int operator()(pair_type const& a) const {
        return a.first;
    }   
};  

std::vector<pair_type>     vec(the_map.begin(), the_map.end());
std::sort(vec.begin(), vec.end(), Pred());

std::vector<int>           result;
transform(vec.begin(), vec.end(),  std::back_inserter(result), Tran());

BOOST_FOREACH(int const& r, result) {
    cout << r << endl;
}   

```