I have a std::map<std::string, myStruct>. It’s safe to return address of a myStruct entry ?
I am sure that my entry will not be removed, but other entries can be added.
Type::iterator it = m_map.find(key);
if (it != m_map.end())
{
return &(it->second);
}
It is safe.
In case of
std::maponly iterators/references/pointers to removed elements are invalidated.Reference:
C++03 Standard 23.1.2/8: