Boost logo

Boost Users :

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


Boris ha escrito:
[...]

> 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?

Alas, yes. You can't provide boost::algorithm::to_lower_copy as the
fourth parameter of member<> since it is a function template and
member<> expects a type --you'd have to wrap the function up into
a user-defined functor class.

> If not please regard this as a proposal to improve
> Boost.Multi-index. :)

Your suggestion is appealing at first sight, but I'm not inclined to
implement it. I could go and try to provide some facilities to cascade
key extractors, but in the end one reaches a point where the possible
benefits are outweighed by the clumsy syntax, only to avoid defining
very simple custom key extractors. And no framework can conver
all the cases, as you have experienced in your previous example.

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