3

Is there standard structure or library in C++ (or C++11) that is something like like a set, but that could have more than one key.

i.e. a set of std::pair that can be looked up fast by either a or b.

So you could do something like this:

std::string a = "hello";
std::string b = "world";

x.insert(a, b);

x.get<1>("hello") => std::pair("hello", "world"); // (fast lookup)
x.get<2>("world") => std::pair("hello", "world"); // (fast lookup)

Basically like a database table with two indexes.

I'd rather not re-invent the wheel if something already exists.

A simple way to combine existing containers to make something with this functionality would be good also.

Clinton
  • 22,361
  • 15
  • 67
  • 163
  • 1
    Take a look at this example: http://stackoverflow.com/questions/4450095/maintaining-a-unique-set-of-elements-on-different-criteria-c-stl/4450256#4450256 – Khaled Alshaya Oct 11 '11 at 00:59

1 Answers1

11

I'm not sure what your definition of "standard C++" is, but Boost.MultiIndex works with any standard C++ compiler.

Travis Gockel
  • 26,877
  • 14
  • 89
  • 116