std::unordered_multiset<Key,Hash,KeyEqual,Allocator>::begin, std::unordered_multiset<Key,Hash,KeyEqual,Allocator>::cbegin
来自cppreference.com
<tbody>
</tbody>
iterator begin() noexcept; |
(1) | (C++11 起) |
const_iterator begin() const noexcept; |
(2) | (C++11 起) |
const_iterator cbegin() const noexcept; |
(3) | (C++11 起) |
返回指向 unordered_multiset 首元素的迭代器。
如果 unordered_multiset 为空,那么返回的迭代器等于 end()。
返回值
指向首元素的迭代器。
复杂度
常数。
注解
因为 iterator 和 const_iterator 都是常迭代器(而且实际上可以是同一类型),故不可能通过任何这些成员函数返回的迭代器修改容器元素。
示例
运行此代码
#include <iostream>
#include <iterator>
#include <string>
#include <unordered_set>
int main()
{
const std::unordered_multiset<std::string> words =
{
"some", "words", "to", "count",
"count", "these", "words"
};
for (auto it = words.begin(); it != words.end(); )
{
auto count = words.count(*it);
std::cout << *it << ":\t" << count << '\n';
std::advance(it, count); // 所有元素均拥有等价的键
}
}
可能的输出:
some: 1
words: 2
to: 1
count: 2
these: 1
参阅
| 返回指向末尾的迭代器 (公开成员函数) | |
(C++11)(C++14) |
返回指向容器或数组起始的迭代器 (函数模板) |