Hossein Haeri
Dear all,
I have an application where something we call a "categorised container" with colleagues comes very hand. We do currently have a working version and I am looking to see whether it's possible to do some refactoring on that using Multi-Index. Here is an exemplified explanation of what constitutes a decision-making point for me. I would be pleased if anyone here could tell me whether this facility is available under Multi-Index:
multi_index_container < T hashed_non_unique<...>, ordered_non_unique<...>
my_container;
Now, is there anyway I can get all elements of my_container which have a certain hash and sorted according to the second index?
Short answer: no, not in an efficient manner. If you use
equal_range on some particular key for the first index, elements
retrieved won't be ordered accoording to the second index. You
need, for instance, to sort the retrieved range externally.
Longer answer: if you replace the first index with an ordered
index with a composite key you can get the behavior you're after:
multi_index_conainer<
T,
ordered_non_unique<
composite_key<
T,
member
my_container;
Now, if you do an equal_range on a category elements will indeed be sorted by the second member. Whether this solution is OK for your problem (having replaced hashing by sorting) is for you to decide, of course. More in on composite keys on http://www.boost.org/libs/multi_index/doc/tutorial/key_extraction.html#compo... Hope this helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo