Is end() required to be constant in an STL map/set?

前端 未结 10 528
别跟我提以往
别跟我提以往 2021-02-01 15:00

§23.1.2.8 in the standard states that insertion/deletion operations on a set/map will not invalidate any iterators to those objects (except iterators pointing to a deleted eleme

10条回答
  •  猫巷女王i
    2021-02-01 15:11

    Well, there's nothing preventing particular collection implementation from having end() depend on the instance of collection and time of day, as long as comparisons and such work. Which means, that, perhaps, end() value may change, but old_end == end() comparison should still yield true. (edit: although after reading the comment from j_random_hacker, I doubt this paragraph itself evaluates to true ;-), not universally — see the discussion below )

    I also doubt you can use std::map::iterator in the Node class due to the type being incomplete, yet (not sure, though).

    Also, since your nodes are uniquely numbered, you can use int for keying them and reserve some value for invalid.

提交回复
热议问题