I am having below composite container. I am looking to sort the container by member<CA,std::string,&CA::card> at the end. Can some one help me to achieve this? typedef multi_index_container< CA, indexed_by< ordered_unique< composite_key< CA, member<CA,std::string,&CA::name>, member<CA,std::string,&CA::displayName>, member<CA,std::string,&CA::card> > >
duplicateBook;
Regards, UJ
Uthpal Urubail <uthpal.urubail <at> altair.com> writes:
I am having below composite container. I am looking to sort the container by member<CA,std::string,&CA::card> at the end. Can some one help me to achieve this?
Hi Uthpal, Please use [multi_index] (or whatever the lib your post is about) in your subject line, as suggested in http://www.boost.org/community/policy.html Thank you! As for your question, to have the elements in your duplicateBook sorted by card, you have sceral options: 1. Add an additional index based on card: ordered_non_unique<member<CA,std::string,&CA::card>> 2. Create a std::vector<CA*>, populate it with pointers to the elements of duplicateBook and std::sort by card. 3. Add a sequenced or random_access index and sort by card. 1 is the simplest. You want to choose 2 rather than 1 if the operation is unfrequent (having an additional index imposes a penalty on memory and overall container performance.) 3 is a sort of compromise between 1 and 2: there's a memory penalty but you only pay for sorting when you need it. Best, Joaquín M López Muñoz Telefónica Digital
On 1/20/2014 4:58 AM, Uthpal Urubail wrote:
I am having below composite container. I am looking to sort the container by member<CA,std::string,&CA::card> at the end. Can some one help me to achieve this?
If you are just using your existing index for looking up matching values, and don't care that they are sorted by CA::name, then you can just change the order of your subkeys and put CA::card first.
typedef multi_index_container< CA, indexed_by< ordered_unique< composite_key< CA, member<CA,std::string,&CA::name>, member<CA,std::string,&CA::displayName>, member<CA,std::string,&CA::card> > >
duplicateBook;
participants (3)
-
Joaquin M Lopez Munoz
-
John M. Dlugosz
-
Uthpal Urubail