K
Kevin W.
How do I sort a map by the value, rather than the key? (either
automatically or with the sort function.)
automatically or with the sort function.)
Kevin said:How do I sort a map by the value, rather than the key? (either
automatically or with the sort function.)
How do I sort a map by the value, rather than the key? (either
automatically or with the sort function.)
Kevin W. said:How do I sort a map by the value, rather than the key? (either
automatically or with the sort function.)
You can't - std::map has an invariant that it is sorted by key. You'll
have to copy into a vector or similar first, or perhaps maintain two
parallel maps (key->value and value->key).
Kevin said:How do I sort a map by the value, rather than the key? (either
automatically or with the sort function.)
You can't sort maps. They are always automatically sorted by key.
Kevin said:Yes, but I should be able to define the "less than" predicate in the
constructor
or I should be able to pass a custom predicate into the sort
function (as I understand it, you *can* sort a map because it is only
automatically sorted when pairs are added or removed).
Kevin W. said:Yes, but I should be able to define the "less than" predicate in the
constructor,
or I should be able to pass a custom predicate into the sort function
(as I understand it, you *can* sort a map because it is only
automatically sorted when pairs are added or removed).
What I'm really asking is:
What are the arguments to this functor (values, pointers or
references),
The arguments _are_ the values (or references to them.)and
How do I access the value from these arguments?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.