1

Topic: std:: map

Hi, All! Questions at me, on implementation std:: map. 1) There is, let us assume, some map and the iterator specifying in one of elements in it. Whether it is guaranteed, what the iterator remains  if in map one more element is interposed? And whether the iterator will specify in the same element? 2) the case is more difficult. There is, for example, a code of type such: for (map:: const_iterator i=MyMap.begin (); i! =MyMap.end (); i ++) {...} whether the code It will be correct to work, if simultaneously from other flow there is an insertion of elements in MyMap (removal/updating are eliminated)?

2

Re: std:: map

S> 1) There is, let us assume, some map and the iterator specifying in one of elements in it. Whether it is guaranteed, what the iterator remains  if in map one more element is interposed? And whether the iterator will specify in the same element? Yes S> for (map:: const_iterator i=MyMap.begin (); i! =MyMap.end (); i ++) whether S> [/code] S> the code It will be correct to work, if simultaneously from other flow there is an insertion of elements in MyMap (removal/updating are eliminated)? No

3

Re: std:: map

Hello, sz36, you wrote: S> Hi, All! S> Questions at me, on implementation std:: map. S> 1) There is, let us assume, some map and the iterator specifying in one of elements in it. Whether it is guaranteed, what the iterator remains  if in map one more element is interposed? And whether the iterator will specify in the same element? On both questions - yes. Look here insert and all remaining  (insert_or_assign, emplace, emplace_hint, try_emplace a little, operator []), All of them are marked by statement No iterators or references are invalidated In 17 standard it changed, but as a whole the warranty is left. S> 2) the case is more difficult. There is, for example, a code of type such: S> S> for (map:: const_iterator i=MyMap.begin (); i! =MyMap.end (); i ++) S> {S>... S>} whether S> S> the code It will be correct to work, if simultaneously from other flow there is an insertion of elements in MyMap (removal/updating are eliminated)? No, look here the link, Thread safety, point 2 - an insertion/removal of elements - , point 3 - modification of elements - it is possible