简体   繁体   中英

Alternatives for boost::multi_index

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM