Checking whether an iterator is still valid

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

  1. Lindley

    Lindley New Member

    Joined:
    Sep 9, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice