Boost logo

Boost Users :

From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2006-12-20 07:27:15


Hello Charles,

Charles Tolman ha escrito:

> Hi, Boost newbie question regarding indexing of multi_index_containers.
>
> First a great big thank you to Joaquín M López Muñoz for sorting
> this library out. Lovely job.

Thank you! I hope you're enjoy the lib :)

> OK I have a question about indexing. Probably one for Joaquin.
>
> I have a structure that can be indexed on the following keys:
> 0: identity -- unique - this is fine.
> 1: int position; -- non_unique - this is fine.
> 2: int priority; -- non_unique - this is also fine.
> 3: vector<MyStringType> -- non_unique - but NOT fine.
>
> So number 3 is the problem. Am I right in thinking that the
> multi_index_container does not handle this case? i.e. where you would want a
> given SINGLE element to be indexed on a variable (unknown) number of keys,
> in this case as many strings as are in the vector.
>
> Although strictly they are not actually separate keys, there is just one non-unique
> key, but a given element can have multiple instances for this one key.
>
> Of course I can workaround this by having another structure to handle this or
> alternatively wrap up the element a multiple number of times, as many as
> required by the length of the vector of strings. But I was wondering if there
> are any ways of handling this in the basic library.

So, if I'm following you, you are trying to get a data structure such that

  c.find(str)

finds an element if *any* of the strings in its vector<MyStringType> member
is equal to str. Is that right? If so, Boost.MultiIndex does not handle directly
such an scenario. As you point out, you'd have to resort to an adhoc
structure holding some sort of references to the elements, as many
references to the same element as entries held by its vector member.

Best regards,

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