Boost logo

Boost Users :

From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2006-07-26 06:25:31


Charitha Herath ha escrito:

> Hi All,
>
> I'm new to this mailing list. I have been using the boost multi index
> container
> for a while. I now have requirement where I need to create multiple
> composite keys.
>
> The example 7 (composite keys example) in the multi index container
> documentation shows that it is possible to define multiple composite
> keys. But
> how do we use a specific composite key when searching the data. Does
> the
> container differentiate the composite keys using the key data types?
>
> Thanks,
>
> Charitha
>

Hello Charitha,

I'm not getting whether your problem is related with composite keys or
with *multiple* composite keys, i.e. having several indices each with
its
own composite key. Allow me to assume your problem is related with
the usage of one composite key, please correct me otherwise.

The usage of composite keys is explained in

http://boost.org/libs/multi_index/doc/advanced_topics.html#composite_keys

Basically, when looking up an index that uses a composite key, you must
pass
the different key arguments inside a boost::tuple, like shown in the
phonebook
example in the docs:

// search for Dorothea White's number
phonebook::iterator it=pb.find(
  boost::make_tuple(std::string("White"),std::string("Dorothea")));

Additionally, with ordered indices you can also specifiy just the first
N
arguments and leave the rest undefined:

// look for all Whites
std::pair<phonebook::iterator,phonebook::iterator> p=
  pb.equal_range(boost::make_tuple(std::string("White")));

Is there anything about this that is not sufficiently clear to you? I've
got
the hunch I haven't addressed your question, so it'd be great if you can

elaborate a little more.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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