
Patel Priyank-PPATEL1
Hi all,
I have following kind of class and having some identifier and group id associated with particular procedure. I want to know if I have to get the procedures relating particular
group for ex. (groupId == 1). How do I do using multiindex container? Can somebody please give me some hint or code if they have done something similar to what I want to do?
Hello Priyank, I'm not sure I've understood what you're after,
but let me try anyway:
As you'll search for group, you'll need an additional index
(the one you've set up is based on process ID). The following
has not been compiled, beware typos:
struct id {};
struct group {};
typedef
multi_index_container<
Procedure*,
indexed_by<
hashed_unique<
tag<id>,
const_mem_fun
Procedure_Hashed_Pool; typedef Procedure_Hashed_Pool:: index<id>::type Procedure_By_Id; typedef Procedure_Hashed_Pool:: index<group>::type Procedure_By_Group; (I've decided to make the new index hashed non-unique, you could also have it ordered non-unique if you need the elements to be sorted by group ID --hashing only guarantees fast retrieval.) And now you can simply use equal_range() on this index to do what you want: int gr=...; const Procedure_By_Group& procedure_bg= procedure_pool.get<group>(); std::pair< Procedure_By_Group::iterator, Procedure_By_Group::iterator
p=procedure_bg.equal_range(gr);
p will hold the range of elements with group ID == gr. Is this what you were after? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo