Search code examples
c++boostmulti-indexboost-multi-index

Unable to remove element from boost multi_index_container++


Building on CentOS 7, g++ 4.8.5-28. Language standard: C++03

Working sample: https://godbolt.org/z/ijSFrK

In the method RemoveMapping, the call to mapDb.erase(clientIter); is failing (see sample code in link for the actual code and the compile error). I am wondering if it is because of the multiple ordered indexes which are both using composite keys and key extractor methods?


Solution

  • Rather than

    mapDb.erase(clientIter);
    

    you have to write

    clientView.erase(clientIter);
    

    Remember that each index (view) has its own iterator type, and you can't freely interchange them. As a convenience, the container itself (mapDb here) behaves like its first (#0) index, so mapDb.erase can only accept an iterator for serverView.