Boost multiindex: Usage of erase
Hello Joaquin, I am trying to erase members of a container selectively, I get a compile error (no matching function found) at the point where I use erase (highlighted line) below: Could you please point out whats wrong with the usage? Thanks /Ramesh Here is the code: ------------- struct MyMap { Adapter *pAdapter; unsigned long timestamp; MyMap(Adapter * param_Adp, unsigned long param_timestamp ): pAdapter(param_Adp), timestamp(param_timestamp) {} ~MyMap(){ pAdapter = 0; timestamp = 0; } }; struct pAdapter{}; struct timestamp{}; typedef multi_index_container< MyMap, indexed_by < ordered_unique< tag <pAdapter>, BOOST_MULTI_INDEX_MEMBER(MyMap, Adapter *, pAdapter) >, ordered_unique< tag <timestamp>,BOOST_MULTI_INDEX_MEMBER(MyMap, unsigned long, timestamp) > >
tMap;
class ACtr { private: tMap AContainer; public: // Constructor ACtr(); //Destructor ~ACtr(); //Remove stale bool pruneBad(); }; bool ACtr::pruneBad { for ( tMap::index_iterator<timestamp>::type it = AContainer.get<timestamp>().begin(), it_end = AContainer.get<timestamp>().end();it != it_end; count++) { it = AContainer.erase(it); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } } ----
bool ACtr::pruneBad {
for ( tMap::index_iterator<timestamp>::type it = AContainer.get<timestamp>().begin(), it_end = AContainer.get<timestamp>().end();it != it_end; count++) { it = AContainer.erase(it); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } }
You apply erase() to AContainer, i.e. to its 1st index, but you pass an iterator of the 2nd index. I guess you could write something like this: AContainer.get<timestamp>().erase(it);
participants (2)
-
Igor R
-
Ramesh