composite_key with array member
I am looking for a container where I have to use 5-10 keys to get the value. I am trying to write something like below.. Can some one help to solve this? struct entry { int a[10]; int id; }; using boost::multi_index_container; using namespace boost::multi_index; typedef multi_index_container< entry, indexed_by< ordered_non_unique< composite_key< entry, member<entry,unsigned int,&entry::a> ???? > >, ordered_unique< member<entry,unsigned int,&entry::id> > >
book;
Regards, UJ
Uthpal Urubail <uthpal.urubail <at> altair.com> writes:
I am looking for a container where I have to use 5-10 keys to get the value. I am trying to write something like below.. Can some one help to solve this?
struct entry { int a[10]; int id; };
[...]
typedef multi_index_container< entry, indexed_by< ordered_non_unique< composite_key< entry, member<entry,unsigned int,&entry::a> [...]
Not sure if this is what you're looking for, but you can define a global template function extracting the N-th component of entry::a: template<int N> int get_a(const entry& e){return e.a[N];} and then define composite_key on the ten elements of the array as follows: composite_key< entry, global_fun<const entry&,int,get_a<0>>, global_fun<const entry&,int,get_a<1>>, global_fun<const entry&,int,get_a<2>>, global_fun<const entry&,int,get_a<3>>, global_fun<const entry&,int,get_a<4>>, global_fun<const entry&,int,get_a<5>>, global_fun<const entry&,int,get_a<6>>, global_fun<const entry&,int,get_a<7>>, global_fun<const entry&,int,get_a<8>>, global_fun<const entry&,int,get_a<9>>
Is there any particular reason why you're packing the ten keys in an array 'a' rather than naming them like this? int a0,a1,a2,a3,a4,a5,a6,a7,a8,a9; It'd make thing easier wrt to declaring the composite_key. Joaquín M López Muñoz Telefónica
participants (2)
-
Joaquin M Lopez Munoz
-
Uthpal Urubail