Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2005-02-27 14:15:57


----- Mensaje original -----
De: Loïc Joly <loic.actarus.joly_at_[hidden]>
Fecha: Domingo, Febrero 27, 2005 7:04 pm
Asunto: [boost] boost::multi_index::key_extractors status

> Hello everybody,
>
> I'm discovering boost::multi_index, and something strikes me: I've
> been
> dreaming of something like boost::multi_index key extractors (and
> especially member) for most of my std::set or std::sort uses.
>
> I therefore think that this part of boost::multi_index does not
> belong
> in this library, but is more general purpose, and deserves a
> library of
> its own, along with a way to get a suitable less predicate from
> the
> result of those. All the arguments that make such a framework
> usefull
> for boost::multi_index can equally be applied to STL containers
> and
> algorithms.
>
> I wonder if such a proposal has already been made (maybe it even
> already
> exists, boost has so many parts that I may be unaware of this),
> and in
> the positive case what were the arguments in favor or in
> opposition of it.
>

This issue was considered during the review, and those who
gave an opinion about it thought it was better to leave like
it is now. Anyway, there's nothing preventing you from using
the key extraction sublib for your own purposes, as it is
headerwise separate from the rest. You'll only need some
compose classes to plug key extractors into comparison
predicates, something like this:

template<typename KeyFromValue>
struct key_less
{
  typedef result_type bool;

  template <typename Arg>
  bool operator()(const Arg& x,const Arg& y)
  {
    return key(x)<key(y);
  }

private:
  KeyFromValue key;
};

...

typedef std::set<
  employee,
  key_less<member<employee,std::string,&employee::name> >
> employee_set;

HTH

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk