The difference of map::erase function in different versions of STL
1. c++98 and C++11 standards
http://www.cplusplus.com/reference/map/map/erase/
PJ STL (Windows)
map::erase function (C++11 standard) returns a map::iterator:
iterator Map::erase(const_iterator _where); iterator Map::erase(const_iteratorconst_iterator _last); size_type Map::erase(constkey_type& _keyval);
3. SGI STL (Linux)
The Linux implementation version of the Map::erase function (c++98 standard) returns a void:
void Map::erase(iterator __position); void Map::erase(iteratoriterator __last); Size_type Map::erase(constkey_type& __x);
How to use the Map::erase function correctly
How to use the Map::erase function correctly:
typedef STD::Map<int,int> Kg_testmap; typedef std::map <int,int>::iterator kg_testmapiter; std::map <int,int>maptest; for(Kg_testmapiteriter = Maptest.begin(); Iter! =Maptest. End ();) {maptest. Erase (ITER++);}
This approach leverages the features of the Post + +, and executes the maptest.erase (iter++) statement into two processes:
• The Post + + operation will save a copy of TMP for the current ITER, then increment the current ITER to point to the next element, and finally return the copy TMP
• Call the Map::erase function, the element that TMP points to.
//code in PJ STL_myiter operator++(int){ //postincrement _myiter_tmp = * This; ++* This; return(_tmp);}
Code in SGI STL
_self operator+ + (int)
{
_self __tmp = *this;
_m_increment ();
return __tmp;
}
C++.stl Map::erase Traps