How can I order a map by value efficiently?
问题 Consider a std::map<K,V> . I want to re-order the map by value profiting by an appropriate container std::C<V*> or std::C<V&> , in a way that no copies of values are done to store the elements in C. Furthermore, elements in C must be sorted according to the result of int f(V&) applied to each element. Despite my efforts I could not find an appropriate C and an enough efficient way to build it. Do you have any solution? A small example would be much appreciated. 回答1: Seems simple enough. std: