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.
Consider a std::map<K,V> . I want to re-order the map by value profiting by
Share
Seems simple enough.
Unless you meant C is supposed to be another map:
http://ideone.com/bBoXq
This requires the previous map to remain in scope longer than
dest, and have no pairs removed untildestis destructed. Otherwisesrcwill need to have been holding smart pointers of some sort.