Boost logo

Boost Users :

Subject: [Boost-users] Question on boost multi-index container erase method
From: Ramesh (rramesh1_at_[hidden])
Date: 2008-09-30 21:49:50


Hello Joaquin,

I am trying to erase a record in the container based on keys - in my
case both the keys are ordered
and unique and I need to have ways to delete records based on either
of the keys.

I tried to erase an element based on key2 & I got the following error:

"error: no matching function for call to 'boost::multi_index
....<Error runs for more than a page>

:erase(boost::multi_index::detail::index_iterator
<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail
::index_node_base<MyMap> > >&)'

The compiler is perhaps complaining that I havent provided a prototype
for erase in the map? In my case I wish to erase the record pointed by
the iterator (In another class I had a single index and I didnt have
the need to provide a prototype, is it because I have two 'unsigned
long' keys that the compiler expects a prototype? )- Kindly help me
fix this error.
My code is posted as below:

Thanks
/R

---
//fwd decl
class A;
struct MyMap
{
	unsigned long key1;
	unsigned long key2;
  	A	      *pObj;
	MyMap(unsigned long param_key1, unsigned long param_key2, A *param_pObj):
		key1(param_key1), key2(param_key2), pObj(param_pObj){}
	~LCMap(){
		key1 = 0;
		key2 = 0;
		pObj = 0;
	}
};
struct key1{};
struct key2{};
typedef multi_index_container<
MyMap,
	indexed_by<
		ordered_unique<
			tag <key1>, BOOST_MULTI_INDEX_MEMBER(MyMap, unsigned long, key1)>,
		ordered_unique<
			tag <key2>, BOOST_MULTI_INDEX_MEMBER(MyMap, unsigned long, key2)>
	>
>tMapDef;
class MyWrap {
private:	
	MyMap	MyContainer;
        ..
public:
	
	insert(UINT32, UINT32, A *);
	erasebykey2(unsigned long);
};
bool MyWrap::erasebykey2(unsigned long param_key2) {
	bool ret = FALSE;
	typedef tMapDef::index<key2>::type tKey2Type;
	tKey2Type& key2_index = MyContainer.get<key2>();
	
	tMapDef::index_iterator<key2>::type it =
				key2_index.find(param_key2);
	if (it == key2_index.end()) {
		cout << "No matching Recs with key2" <<endl<<;
		return FALSE;
	}
	tMapDef::size_type status = MyContainer.erase(it);
}

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