Q:

C++ map destruction

I want to clear a map inside the destructor, but I do not know whether it is empty or not. Is it okay if I clear it as follows.  
for(std::map<int, int *>::iterator it = m_map.begin(); it != m_map.end(); ++it)
{ 
   delete it->second;
}
m_map.clear();    

or should I also put an if condition around the above operation like if(!m_map.empty()){} in order to check whether it is empty or not. 

A:

If the map is empty, m_map.begin() will be the same as m_map.end(), so the loop won't do anything. m_map.clear() (or rather ~std::map will happen, but that will do clear() or the equivalent) will happen automatically by the destructor the compiler supplies as part of your destructor, so not needed.

