如何在C ++中实现公共迭代器

时间:2017-07-15 06:49:36

标签: c++ iterator containers template-meta-programming

我的课程hash_table看起来像这样:

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

因为这是一个哈希表,我不希望该用户可以修改密钥,但是在地图内部,我想删除key_type和value_type的remove_const以启用move数据

如何实施iteratorconst_iterator(如std::unordered_map::iterator引用map_iterator指向的项目。

我很抱歉我的英语不好。

0 个答案:

没有答案