Is there a Boost.Bimap alternative in c++11?

前端 未结 2 1062
野性不改
野性不改 2020-12-18 18:01

Is there a usable alternative to Boost\'s bimap in C++0x?

I would like to avoid Boost, but fully embrace C++11. If necessary, a slimmed down version of Boost\'s bima

相关标签:
2条回答
  • 2020-12-18 18:20

    My feeling is a lot of the work that goes into Boost libraries is making them work with other libraries/STL.

    If you don't need that capability, you could just use a class with a std::map<X*, Y*> and std::map<Y*, X*>. Then have methods like the following: add(X,Y), remove(X,Y), get_left(X) and get_right(Y).

    If you want to store copies, add(X,Y) could allocate memory, and remove(X,Y) can de-allocate. Also, you can then define a destructor that calls remove(X,Y) on the remainder of the elements.

    0 讨论(0)
  • 2020-12-18 18:36

    Short answer: no.

    Long answer: nope.


    It should be noted that C++14's support for transparent comparators eliminates the need for Boost.Bimap 90% of the time*: when you need to key off of any given property of an object (stored or computed), often a simple, bitwise-comparable unique identifier inherent to/present in the object anyway. With transparent comparators, you can compare an object to any possible value, discriminated only by type, as long as said value can be obtained/computed from an object without mutating it.

    * a guesstimate, not a statistic

    0 讨论(0)
提交回复
热议问题