template class tsl::detail_robin_hash::robin_hash::robin_iterator

Overview

The ‘ operator*() ‘ and ‘ operator->() ‘ methods return a const reference and const pointer respectively to the stored value type.

In case of a map, to get a mutable reference to the value associated to a key (the ‘.second’ in the stored pair), you have to call ‘ value() ‘.

The main reason for this is that if we returned a std::pair<Key, T>& instead of a const std::pair<Key, T>&, the user may modify the key which will put the map in a undefined state.

#include <robin_hash.h>

template <bool IsConst>
class robin_iterator
{
public:
    // typedefs

    typedef std::forward_iterator_tag iterator_category;
    typedef const typename robin_hash::value_type value_type;
    typedef std::ptrdiff_t difference_type;
    typedef value_type& reference;
    typedef value_type* pointer;

    // construction

    robin_iterator();

    template <bool TIsConst = IsConst, typename std::enable_if<TIsConst>::type* = nullptr>
    robin_iterator(const robin_iterator<!TIsConst>& other);

    robin_iterator(const robin_iterator& other);
    robin_iterator(robin_iterator&& other);

    // methods

    robin_iterator& operator = (const robin_iterator& other);
    robin_iterator& operator = (robin_iterator&& other);
    const robin_hash::key_type& key() const;

    template <
        class U = ValueSelect,
        typename std::enable_if<has_mapped_type<U>::value&&IsConst>::type* = nullptr
        >
    const U::value_type& value() const;

    template <
        class U = ValueSelect,
        typename std::enable_if<has_mapped_type<U>::value&&!IsConst>::type* = nullptr
        >
    U::value_type& value() const;

    reference operator * () const;
    pointer operator -> () const;
    robin_iterator& operator ++ ();
    robin_iterator operator ++ (int);
};