unordered_map< K,V> :: iterator来自哪里? [英] Where does unordered_map<K, V>::iterator come from?

查看:56
本文介绍了unordered_map< K,V> :: iterator来自哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 std :: unordered_map< K,V> 时,我知道每个键值对的迭代器的类型都是 std :: unordered_map< K,V> :: iterator .我也知道迭代器本身指向 pair< const K,V> .但是,我知道迭代器指向一对的唯一原因是查看示例代码.在哪里定义此行为?

When I'm using a std::unordered_map<K, V> I know that the iterator to each key-value pair is of type std::unordered_map<K, V>::iterator. I also know that the iterator itself points to a pair<const K, V>. However, the only reason I know the iterator points to a pair is from looking at example code. Where is this behavior defined?

例如,如果我访问 cppreference.com上的文档,我看不到此行为的解释.它只说成员 iterator 被定义为 ForwardIterator .

For example, if I go to the documentation at cppreference.com, I don't see where this behavior is explained. It only says that the member iterator is defined as a ForwardIterator.

所以,我的问题是,聪明的开发人员如何知道 std :: unordered_map< K,V> :: iterator 实际代表什么?我确定我缺少一些合乎逻辑的飞跃.

So, my question is, how would a smart developer know what a std::unordered_map<K, V>::iterator actually represents? I'm sure there is some logical leap I'm missing.

推荐答案

用于STL容器

个对象将返回类型为 reference 的对象,该对象是对类型为 value_type 的对象的引用.

objects of type iterator when de-referenced return an object of type reference, which is a reference to an object of type value_type.

这些都是在容器内部定义的.

These are all defined inside the container.

请注意,将std :: map定义为容器.此信息是本文档的一部分.

Note the std::map is defined as a container. This information is part of this documentation.

https://en.cppreference.com/w/cpp/named_req/Container

这篇关于unordered_map&lt; K,V&gt; :: iterator来自哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆