std::map, pointer to map key value, is this possible?

后端 未结 4 1420
悲&欢浪女
悲&欢浪女 2020-12-01 06:14
std::map myMap;

std::map::iterator i = m_myMap.find(some_key_string);
if(i == m_imagesMap.end())
            


        
4条回答
  •  [愿得一人]
    2020-12-01 07:20

    Section 23.1.2#8 (associative container requirements):

    The insert members shall not affect the validity of iterators and references to the container, and the erase members shall invalidate only iterators and references to the erased elements.

    So yes storing pointers to data members of a map element is guaranteed to be valid, unless you remove that element.

提交回复
热议问题