0

I would like to use something which can create a dictionary like,

Multi-Keys

Key1                     which will map to              SomeObject
Key2
Key3
Key4
etc

I would like to look up based on any key. I have weird issues with boost::multi_index and am looking for alternatives.

My compiler is Visual Studio 2005 and I use boost and DONT USE C++11. Any boost(other than multi_index) stuff is most welcome.

codeworks
  • 149
  • 1
  • 15

1 Answers1

2

Of course you should get your weird issues fixed, but here's a technique that works nicely:

std::vector<X> v; // elements of X in some order
std::vector<std::reference_wrapper<X const> > index1(v.begin(), v.end());
std::vector<std::reference_wrapper<X const> > index2(v.begin(), v.end());

// sort the indexes
std::sort(index1.begin(), index1.end(), by_property1);
std::sort(index2.begin(), index2.end(), by_property2);

Of course, keeping things in synch under mutation and controlling the runtime cost of sorting the indexes becomes a slightly more tricky task, which is why - most of the time - you'd want multi_index_container

Also, note that to be more carefree, you'd need to replace vector with list there to enjoy iterator/reference stability.

sehe
  • 374,641
  • 47
  • 450
  • 633