开发者

Modifying items of boost multi index container

开发者 https://www.devze.com 2022-12-18 15:39 出处:网络
struct tagEnumdef{}; struct tagName{}; struct tagWidget{}; template< class type > class ParamT开发者_如何学Pythonags;
struct tagEnumdef{}; struct tagName{}; struct tagWidget{};
template< class type > class ParamT开发者_如何学Pythonags;
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?


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_), ...);
0

精彩评论

暂无评论...
验证码 换一张
取 消