c++ - Iterator invalidation rules -


what iterator invalidation rules c++ containers?

preferably in summary list format.

(note: meant entry stack overflow's c++ faq. if want critique idea of providing faq in form, the posting on meta started this place that. answers question monitored in c++ chatroom, faq idea started out in first place, answer read came idea.)

c++03 (source: iterator invalidation rules (c++03))


insertion

sequence containers

  • vector: iterators , references before point of insertion unaffected, unless new container size greater previous capacity (in case iterators , references invalidated) [23.2.4.3/1]
  • deque: iterators , references invalidated, unless inserted member @ end (front or back) of deque (in case iterators invalidated, references elements unaffected) [23.2.1.3/1]
  • list: iterators , references unaffected [23.2.2.3/1]

associative containers

  • [multi]{set,map}: iterators , references unaffected [23.1.2/8]

container adaptors

  • stack: inherited underlying container
  • queue: inherited underlying container
  • priority_queue: inherited underlying container

erasure

sequence containers

  • vector: every iterator , reference after point of erase invalidated [23.2.4.3/3]
  • deque: iterators , references invalidated, unless erased members @ end (front or back) of deque (in case iterators , references erased members invalidated) [23.2.1.3/4]
  • list: iterators , references erased element invalidated [23.2.2.3/3]

associative containers

  • [multi]{set,map}: iterators , references erased elements invalidated [23.1.2/8]

container adaptors

  • stack: inherited underlying container
  • queue: inherited underlying container
  • priority_queue: inherited underlying container

resizing

  • vector: per insert/erase [23.2.4.2/6]
  • deque: per insert/erase [23.2.1.2/1]
  • list: per insert/erase [23.2.2.2/1]

note 1

unless otherwise specified (either explicitly or defining function in terms of other functions), invoking container member function or passing container argument a library function shall not invalidate iterators to, or change values of, objects within container. [23.1/11]

note 2

it's not clear in c++2003 whether "end" iterators subject above rules; should assume, anyway, (as case in practice).

note 3

the rules invalidation of pointers sames rules invalidation of references.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -