tags:

views:

243

answers:

1
struct tagEnumdef{}; struct tagName{}; struct tagWidget{};
template< class type > class ParamTags;
template<> class ParamTags<int>     { public: typedef tagEnumdef tag; };
template<> class ParamTags<QString> { public: typedef tagName    tag; };
template<> class ParamTags<QWidget*>{ public: typedef tagWidget  tag; };

typedef boost::multi_index::multi_index_container
<
  ParamRegistrationEntry,
  boost::multi_index::indexed_by
  <
    boost::multi_index::ordered_unique< boost::multi_index::tag<tagEnumdef>, BOOST_MULTI_INDEX_CONST_MEM_FUN( ParamRegistrationEntry, int,      enumdef ) >,
    boost::multi_index::ordered_unique< boost::multi_index::tag<tagName>,    BOOST_MULTI_INDEX_CONST_MEM_FUN( ParamRegistrationEntry, QString,  name    ) >,
    boost::multi_index::ordered_unique< boost::multi_index::tag<tagWidget>,  BOOST_MULTI_INDEX_CONST_MEM_FUN( ParamRegistrationEntry, QWidget*, widget  ) >
    >
  >
> ParamRegisterIndexContainer;

T t_; // int, QString or QWidget*
ParamRegisterIndexContainer* const register_;
register_->modify( register_->get<ParamTags<T>::tag>().find( t_ ), ... ); // C2664


error C2664: 'bool boost::multi_index::detail::ordered_index<KeyFromValue,Compare,SuperMeta,TagList,Category>::modify<boost::lambda::lambda_functor<T>>(boost::multi_index::detail::bidir_node_iterator<Node>,Modifier)' :
cannot convert parameter 1 
from 'boost::multi_index::detail::bidir_node_iterator<Node>' 
to   'boost::multi_index::detail::bidir_node_iterator<Node>'

With
Node=ordered_index_node<index_node_base<...>>
Node=ordered_index_node<ordered_index_node<ordered_index_node<index_node_base<...>>

I've stripped down parts which shouldn't matter. Are the 3 ordered_index_node's related to the 3 keys I've defined in the container? I get an iterator from 1 index with get(), but modify() seems to require some sort of combination?

A: 

It is my understanding that modify() should be called on an index, not on a container. So what you want to write is probably more like:

typedef typename ParamTags<T>::tag TagType;

// Get the proper index
ParamRegisterIndexContainer::index<TagType>::type& index = register_->get<TagType>();

// Modify a value found in this index
index.modify(index.find(t_), ...);
Éric Malenfant