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: 
Anyone who tells you they have the "fastest" way is a liar, since they don't know what hardware/C++ implementation etc you're using.

Here's one way:

```
typedef pair<int,int> item;

vector<item> mytmp(mymap.begin(), mymap.end());
sort(mytmp.begin(), mytmp.end(), [](item lhs, item rhs) { return lhs.second < rhs.second; });

vector<int> myvec;
myvec.reserve(mytmp.size());
transform(
    mytmp.begin(), mytmp.end(),
    back_inserter(myvec);
    [](item i) { return i.first; }
);

```
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> .