[英]why does unordered_map not have rbegin() or rend(), but only begin() and end()
It seems weird to iterate through an unordered_map
, with begin(), end() and a forward iterator. 使用begin(),end()和forward迭代器遍历
unordered_map
似乎很奇怪。
If so, why does it not have rbegin(), rend() and bi-direction iterators too? 如果是这样,为什么它也没有rbegin(),rend()和双向迭代器呢? is there any technical reason?
有什么技术原因吗?
它是无序的,因此迭代发生的顺序是(或应该)不重要。
Cite from The C++ Standard Library
引用
The C++ Standard Library
Reverse iterators let algorithms operate backward by switching the call of an increment operator internally into a call of the decrement operator, and vice versa.
反向迭代器允许算法通过将增量运算符的调用内部切换到减量运算符的调用来反向操作,反之亦然。 All containers with bidirectional iterators or random-access iterators (all sequence containers except forward_list and all associative containers) can create reverse iterators via their member functions rbegin() and rend().
具有双向迭代器或随机访问迭代器(除forward_list和所有关联容器之外的所有序列容器)的所有容器都可以通过其成员函数rbegin()和rend()创建反向迭代器。 Since C++11, the corresponding member functions returning read-only iterators, crbegin() and crend(), are also provided.
从C ++ 11开始,还提供了返回只读迭代器,crbegin()和crend()的相应成员函数。
For forward_lists and unordered containers, no backward-iteration interface (rbegin(), rend(), etc.) is provided.
对于forward_lists和无序容器,不提供反向迭代接口(rbegin(),rend()等)。 The reason is that the implementation requires only singly linked lists to go through the elements.
原因是实现只需要单个链表来遍历元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.