I have my own key for std::map :
struct Foo { Foo(int _uid, int _priority) : unique_id(_uid), priority(_priority) {} bool operator<(const Foo& other) const { return priority < other.priority; } int unique_id; int priority; };
I am creating a map using this code:
std::map <Foo, int> bla;
And this is how I insert the elements:
bla.insert(std::pair<Foo, int> (Foo(1,2), 3) )
This works great, and sorting works too. But my problem is, how can I find an element with only unique_id ? The find function requires Foo , and it requires priority , which I don’t have when I request it.
I would like to store priority in value more (not as a key), but I don't know how I can sort by value then. Is std::map correct class / template for this?
Edit: I have no way to use boost, also the priorities are not unique.
source share