Boost logo

Boost Users :

From: Matias Capeletto (matias.capeletto_at_[hidden])
Date: 2007-12-25 20:58:19


On Dec 25, 2007 1:16 PM, <damny_at_[hidden]> wrote:
> merry xmas everyone,
>
> and maybe santa claus or anyone of you have a helping surprise for me :o)
>
> after became acquainted with boost and boost.python i have to learn boost.multi_index now.
> the goal is to build a 'map' with two individual keys (a name and an identifier) per value
> (object of user class); nme1-idf1-valu1, nme2-idf2-valu2, nme3-idf3-valu3, ...
> any value should be 'directly' accessible by name or by identifier; valu1:=map[nme1], valu1:=map[idf1].
> although i don't understand the documentation perfectly and i'm not familiar with templates i recognise
> that boost.multi_index is the perfect way :o)
> and i did the following:

<snip> Code And Problem </snip>

> how to encapsulate this special multi_index into a class, that fits the above description of the needed 'map'.
> are there possibilities to avoid the 'std::string' for the 'name' key?
> where are the more easier examples for C++-templates/boost newbies like me :o) ?

You can definitely use Boost.MultiIndex to solve your problem. The
thing is that a bidirectional map (a map where you can search in both
ends) is a very common data structure, so a new library called
Boost.Bimap was build on top of Boost.MultiIndex to give you a nicer
interface that plays nicely with standard maps.

In the most simple form you will use it like:

#include <boost/bimap.hpp>
using namespace boost::bimaps;

typedef bimap<std::string, int> bm_type;

int main()
{
    bm_type locMsg;
    locMsg.insert( bm_type::value_type("name1", 123) );
    locMsg.insert( bm_type::value_type("name2", 456) );
    bm_type::left_iterator itrNme = locMsg.left.find("name1");
    bm_type::right_iterator itrIdf = locMsg.right.find(456);
    // ...
}

This library will be included (If everything goes well) in the next
release of Boost (1.35).
For now, you can download it from Boost SVN Head.

Online docs can be found here:
http://tinyurl.com/22sja5

Best regards
Matias


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net