Try the standard STL trick instead of your code:
MapTable().swap(theMap);
Pregunta
There is a class in my code (not my code) which uses boost multi_index_container
template <class T_key, class T_val>
class foo_map {
typedef MapEntry_T<T_key, T_val> MapEntry;
typedef multi_index_container
< MapEntry
, indexed_by
< sequenced< tag<by_LRU> >
, ordered_unique
< tag<by_index>
, member<MapEntry, T_key, &MapEntry::first>
>
>
> MapTable;
typedef typename MapTable::template index<by_index>::type::iterator IndexIter;
MapTable theMap;
public:
typedef IndexIter iterator;
void erase(iterator iter) {
theMap.get<by_index>().erase(iter);
}
};
Assume all variables and types are defined properly. I don't want to mess the snippet. The code actually works. What I want to do is to add a clear
function to erase ALL elements.
void erase(iterator iter) {
for (iter = theMap.begin(); iter != theMap.end(); iter++ )
theMap.get<by_index>().erase(iter);
}
Can someone help? I get a 100 lines error regarding this!!!
Solución 2
Try the standard STL trick instead of your code:
MapTable().swap(theMap);
Otros consejos
Also, you could consider
theMap.get<by_index>().clear();