$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2004-04-26 16:12:57
----- Mensaje original -----
De: Rob Stewart <stewart_at_[hidden]>
Fecha: Lunes, Abril 26, 2004 10:16 pm
Asunto: Re: [boost] [multi_index] composite keys: request for advice
> From: Joaquin M Lopez Munoz <joaquin_at_[hidden]>
> > 
> > Composite keys can be specified by a new construct
> > called composite_key in the following manner:
> > 
> > struct record
> > {
> >   int first;
> >   int second
> >   int third;
> > };
> > 
> > multi_index_container<
> >   record,
> >   indexed_by<
> >     composite_key<
> >       record, //base value
> >       member<record,int,&record::first>, // first key
> 
> Would that you could make this work to avoid the duplication and
> chance for errors:
> 
>        member< &record::first >
> 
> I know a function template can deduce the other types, but I
> can't think of how to make it work here.
> 
I'd be the happiest man on the block if I could have that,
but AFAIK it is not possible. The fact that member<> is
here specified in the context of composite_key does
not help, either. This has been previously brought into
discussion several times.
If you have a typeof() utility and don't object to some macro
hackery, this is an approximation:
template<typename Class,typename Member>
Class base_from_ptr_to_member(Member Class::*);
template<typename Class,typename Member>
Member member_from_ptr_to_member(Member Class::*);
#define BOOST_MULTI_INDEX_SMART_MEMBER(PtrToMember) \
member< \
  typeof(base_from_ptr_to_member(PtrToMember)),\
  typeof(member_from_ptr_to_member(PtrToMember)),\
  PtrToMember\
>
...
multi_index_container<
  record,
  indexed_by<
    ordered_unique<
      BOOST_MULTI_INDEX_SMART_MEMBER(&record::x)
    >
  >
>
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo