How to implement public iterator in C++

Viewed 164

I have class hash_table look like this:

template <typename Key, typename Value, typename Alloc>
class hash_table {
public:
    using key_type = Key;
    using mapped_type = Value;
    using allocator_type = Alloc;
    using value_type = std::pair<const key_type, mapped_type>;

private:
    template<typename Map, typename IterVal, typename Allocator>
    class map_iterator;
    using internal_value_t = std::pair<std::remove_const_t<key_type>, std::remove_const_t<mapped_type>>;
    using internal_iterator = map_iterator<hash_table, internal_value_t, allocator_type>;
    using const_internal_iterator = map_iterator<const hash_table, const_internal_value_t, allocator_type>;

 public:
    using iterator = ???;
    using const_iterator = ???;
}

Because this is a hash table, I don't want that user can modified the key, but in inside the map, I want to remove_const of key_type and value_type to enable move data.

How can I implement iterator, and const_iterator in (like std::unordered_map::iterator refer to and item that pointed by a map_iterator.

I'm sorry for my bad English.

0 Answers
Related