2

I have a map called:

std::unordered_map < std::string, struct > g_users

but I would like to enter a second key, so that I could work with:

std::unordered_map < std::pair < std::string, int> struct> g_users

Is there any way of using the find function just to look for one of the keys? If not, is there any way to filter my map according to two keys?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
paulzaba
  • 91
  • 6
  • 2
    You might find the [Boost Multi-index Containers Library](http://www.boost.org/doc/libs/release/libs/multi_index/doc/index.html) useful. – jotik Apr 24 '16 at 21:13
  • There's no generally-useful way to have a pair of keys in an `unordered_map`: the hashing sprays them across buckets and there's no way to find values of both key types other than brute-force O(n) iteration over the entire container, or brute-force probing for all possible values of at least one of the keys (if you restrict hash/equality processing to the other key). jotik's suggestion's better than rolling your own 2+ container solution, though it may be a little more work getting familiar with the library. – Tony Delroy Apr 25 '16 at 10:28

0 Answers0