1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Checking whether an iterator is still valid

Discussion in 'C++' started by Lindley, Sep 9, 2010.

  1. Lindley

    Lindley New Member

    Sep 9, 2010
    Likes Received:
    Trophy Points:
    I have a problem wherein I'd like to remove some elements from a map. However, iterators to the map will be stored elsewhere, and I'd like to ensure that iterators to removed entries are not followed. They can either be deleted at the same time, or later.

    One option I thought of was to make the value type of the map a shared_ptr, and store equivalent weak_ptrs rather than iterators. However, that strikes me as a bit clumsy. Another option is to go hunt down all the iterators to elements that will be removed before removing them, but that's inelegant.

    I was wondering if anyone had an idea on how this task could be most gracefully accomplished.

Share This Page