[multi_index] nested struct question
Hi. I'm trying to create a multi_index and I was wondering if its possible to use a member of a member struct as index. struct nested_element_t { int i; }; struct element_t { nested_element_t ne; }; I'm not sure if there's a way to use member key extractor or should I write my own typedef multi_index_container< element_t, indexed_by< ordered_non_unique<tag<h>, member<nested_element_t ? , int, &nested_element_t> > >
set_t;
Regards. -- Pedro Larroy Tovar, pedro at larroy dot com | http://pedro.larroy.com/ * Las patentes de programación son nocivas para la innovación * http://proinnova.hispalinux.es/
boost@larroy.com ha escrito:
Hi.
I'm trying to create a multi_index and I was wondering if its possible to use a member of a member struct as index.
struct nested_element_t { int i; }; struct element_t { nested_element_t ne; };
I'm not sure if there's a way to use member key extractor or should I write my own
typedef multi_index_container< element_t, indexed_by< ordered_non_unique<tag<h>, member<nested_element_t ? , int, &nested_element_t> > >
set_t;
AFAICS you can't use member<> to do that: a member of a member of x is not a member of x. You'll have to resort to a custom key extractor like this: struct element_t_i_extractor { typedef int result_type; int operator()(const element_t& x)const{return x.ne.i;} int& operator()(element_t& x)const{return x.ne.i;} }; Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (2)
-
boost@larroy.com
-
Joaquín Mª López Muñoz