Boost logo

Boost Users :

From: Boris (boriss_at_[hidden])
Date: 2007-02-23 08:05:59


On Fri, 23 Feb 2007 11:24:35 +0200, Joaquín Mª López Muñoz
<joaquin_at_[hidden]> wrote:

> [...]Yep, it is correct, though possibly a little overkill; you could
> use a simpler
> key
> extractor for the task at hand, like this:
>
> struct employee_case_insensitive_name_extractor
> {
> typedef std::string result_type;
>
> std::string operator()(const employee& x) const
> {
> return boost::algorithm::to_lower_copy(x.name);
> }
> };

If the existing key extractors had a fourth template parameter to accept
an unary function object I think it would be a bit easier to create
user-defined key extractors? Imagine a (simplified) member defintion like
this:

template<class Class,typename Type,Type Class::*PtrToMember,typename
Functor>
struct member
{
   typedef Type result_type;

   Type& operator()(const Class& x)const
   {
     return Functor(x.*PtrToMember);
   }
};

Now I could create my multi_index_container like this:

typedef multi_index_container<
   employee,
   indexed_by<
     hashed_unique<member<employee, std::string, &employee::name,
boost::algorithm::to_lower_copy> >
>
> mi2;

Do I miss anything? If not please regard this as a proposal to improve
Boost.Multi-index. :)

Boris


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