2个问题:
1.我真的需要通过成员传递参数来修改/ modify_key吗?
2.为什么我有这个编译错误
要查看包含错误的整个代码,您可以查看http://coliru.stacked-crooked.com/a/d6241361318e1925
错误是
MultiIndex4.h: In member function 'uint32_t CrMultiParameterMultiIndex::ModifyKeyBy(SearchingKey&, ModifyKeyType&) [with SearchingTagType = IMEI_tag, ModifyingTagType = IMEI_tag, SearchingKey = uint32_t, ModifyKeyType = uint32_t]':
MultiIndex4.h:183: instantiated from here
MultiIndex4.h:119: error: no matching function for call to 'boost::multi_index::multi_index_container<UsersKey, UsersKey_indices, std::allocator<UsersKey> >::modify_key(boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<UsersKey, std::allocator<UsersKey> > > >&, boost::function<void ()(uint32_t&)>&)'
*** Errors occurred during this build ***
我有一个CrMultiParameterMultiIndex类,它包含一个包含2个索引的多索引。
我尝试创建一个模板函数,只根据密钥的一部分进行搜索,并仅修改密钥的一部分。
这个类有一个辅助函数
template <typename TagType,typename SearchingKey>
typename GlobalHash::index<TagType>::type::iterator GetIteratorBy(SearchingKey & key){
return m_pGlobalHash->get<TagType>().find(key) ;
}
并修改使用它的功能
template <typename SearchingTagType,typename ModifyingTagType,typename SearchingKey,typename ModifyKeyType> uint32_t ModifyKeyBy(SearchingKey & key,ModifyKeyType & pi_Modifykey)
{
uint32_t hRes = 1;
//search for entry by TagType
typedef typename GlobalHash::index<SearchingTagType>::type IndexType;
typename IndexType::iterator it = GetIteratorBy<SearchingTagType>(key);
//entry found
if( it != m_pGlobalHash->get<SearchingTagType>().end() )
{
//Set parameter to modify
hRes = SetParameterKeys<ModifyingTagType>(pi_Modifykey);
if(hRes == 1)
{
//get iteraror to modify
typedef typename GlobalHash::index<ModifyingTagType>::type ModifyIndexType;
typename ModifyIndexType::iterator itToModify = m_pGlobalHash->get<ModifyingTagType>().iterator_to(*it);
boost::function<void( ModifyKeyType &)> f = boost::bind(&CrMultiParameterMultiIndex::ModifyKey<ModifyingTagType, ModifyKeyType >, this, _1);
//modify key failed
if(m_pGlobalHash->modify_key(itToModify , f)==false)
hRes = 0;
}
}
//entry not found
else
hRes = 0;
return hRes;
}
这个编译
uint64_t nFromImsi = 1;
uint64_t nToImsi = 1;
m_multiParam.ModifyKeyBy<IMSI_tag,IMSI_tag>( nFromImsi,nToImsi)
但不是这个
uint32_t nFromImsi = 1;
uint32_t nToImsi = 1;
m_multiParam.ModifyKeyBy<IMEI_tag,IMEI_tag>( nFromImsi,nToImsi)
为什么呢?以及如何编译
以下是修饰符
template <> inline void CrMultiParameterMultiIndex::ModifyKey<IMEI_tag>( uint32_t & po_Key){po_Key = m_ParameterKeys.IMEI;}
template <> inline void CrMultiParameterMultiIndex::ModifyKey<IMSI_tag>(uint64_t & po_Key){po_Key = m_ParameterKeys.IMSI;}
答案 0 :(得分:2)
大卫,
的问题
if(m_pGlobalHash->modify_key(itToModify , f)==false)
在于m_pGlobalHash
是索引#0(order_by_IMSI
)的视图,并且不接受迭代器来查看#1(order_by_IMEI
)。您可以project iterators或选择适当的索引:
if(m_pGlobalHash->get<ModifyingTagType>().modify_key(itToModify , f)==false)