Boost logo

Boost Users :

From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2007-01-23 02:31:20


Markus Werle ha escrito:

> Hi!
>
> I read from the docs that we can define key extractors to be one of
> - identity
> - member
> - mem_fun
> - composite_key
>
> Is it possible to use a free function as key extractor in the same way
> as the ones listed above and can you give an example of this?

Hello Markus,

There is no *predefined* key extractor designed for use with free
functions, but you can easily write your own, as sketched in the
following:

struct element{...};

// free function to be used for key extraction
int get_value(const element& x);

// associated key extractor
struct get_value_extractor
{
  typedef int result_type;

  result_type operator()(const element& x)const
  {
    return get_value(x);
  }
};

typedef multi_index_container<
  element,
  indexed_by<
    ordered_unique<get_value_extractor>,
    ...
>
> multi_t;

User-defined key extractors are explained at http://tinyurl.com/l3g6u . On

the other hand, it might be a good idea to provide an additional
predefined
key extractor for use with free functions so as to supplement the existing

ones working with member functions, I'll add this to my to consider list.

Hope this helps,

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