Question

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!!!

Was it helpful?

Solution 2

Try the standard STL trick instead of your code:

MapTable().swap(theMap);

OTHER TIPS

Also, you could consider

theMap.get<by_index>().clear();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top