#2: Your comparator "fun" should be comparing std::pairs, not std::maps. Not that it matters, because...
#3: You can't apply std::sort to std::map iterators. The reason why is simple: std::maps are already sorted by their keys, and they don't allow you to mix up their internal ordering because that would break them in some pretty fundamental ways.