[boost.multiindex] Recommended way of having a list of keys to a multi-index container
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. 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. Apologies if I have missed something and it is in an FAQ somewhere, although I have done an initial search. TIA Charles Tolman
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
Joaquín Mª López Muñoz
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?
Correct.
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.
Yep. Thats what I thought. In retrospect I am going to have a look at the use cases for it as the problem could be handled slightly differently. But thanks for the replay and confirming my thoughts. All the best Charles
participants (2)
-
Charles Tolman
-
Joaquín Mª López Muñoz