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
c ++ iterator containers template-meta-programming


source to share


No one has answered this question yet

Check out similar questions:

8499
What is the "->" operator in C ++?
4247
The definitive C ++ guide and book list
3382
How is Docker different from a virtual machine?
3076
What are the differences between a pointer variable and a reference variable in C ++?
2873
How do I iterate over the words of a string?
1783
C ++ 11 introduced a standardized memory model. What does it mean? And how will this affect C ++ programming?
1709
How can I profile C ++ code running on Linux?
1675
Why is reading lines from stdin much slower in C ++ than Python?
1643
Why templates can only be implemented in a header file?
750
How can I scroll two lists in parallel?



All Articles
Loading...
X
Show
Funny
Dev
Pics