How to implement a public iterator in C ++

My class hash_table

looks 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 = ???;
}

      

Since this is a hash table, I don't want this user to be able to change the key, but inside the map, I want to remove_const from key_type and value_type in order to include data move

.

How can I implement iterator

both const_iterator

in (for example, std::unordered_map::iterator

reference and the element denoted by map_iterator

.

I'm sorry for my bad english.

+3


source to share





All Articles