Boost logo

Boost Users :

Subject: Re: [Boost-users] [multi_index] Sort boost composite container
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2014-01-20 08:14:53


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


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