Boost logo

Boost Users :

From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2007-10-03 05:31:14


boost_at_[hidden] 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


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