Documentation Home >> Headers >> <jss/concurrent_map.hpp> Header >> jss::concurrent_map >> jss::concurrent_map<>::iterator class

Concurrent map iterators meet the Forward Iterator requirements. Multiple threads can iterate through a given jss::concurrent_map instance concurrently with other modifications and accesses without external synchronization. New elements are added to the jss::concurrent_map during iteration may be skipped.

If the element referred to by an instance of jss::concurrent_map::iterator is removed from the jss::concurrent_map then the iterator remains valid, and the referenced element is not destroyed until the iterator is incremented, assigned or destroyed.

If an element referred to by an instance of jss::concurrent_map::iterator is removed from the jss::concurrent_map then that iterator is no longer reachable by incrementing any other iterator that references the same jss::concurrent_map instance. Comparison of two iterators that refer to different elements will thus throw a jss::concurrent_modification exception if either or both of the iterators refer to deleted elements.

In order to avoid this problem, an iterator used for the end of an iteration range can be converted to an anchor by calling jss::concurrent_map::iterator::anchor(). An anchor can always be safely compared for equality against any other iterator. An anchor is always reachable by iteration from any iterator such that the original anchored iterator was reachable from that iterator. An anchor can therefore be safely used as the end of an iteration range. e.g.

jss::concurrent_map<unsigned,unsigned> cm;

for(unsigned i=0;i<20;++i)

auto it=cm.begin();
auto range_end=cm.find(5);
std::for_each(it,range_end,[](unsigned x){std::cout<<x<<" ";});
Class Definition
class iterator
    typedef typename concurrent_map::value_type value_type;
    typedef value_type& reference;
    typedef value_type* pointer;
    typedef ptrdiff_t difference_type;
    typedef std::forward_iterator_tag iterator_category;

    iterator(iterator const& other);
    iterator(iterator && other);
    iterator& operator=(iterator const& other);
    void swap(iterator& other);
    friend bool operator==(iterator const& lhs,iterator const& rhs);
    friend bool operator!=(iterator const& lhs,iterator const& rhs);
    reference operator*();
    pointer operator->();
    iterator& operator++();
    iterator operator++(int);
    void anchor();
    bool is_deleted_node() const;

#include <jss/concurrent_map.hpp>

See Also