命名空间
变体
操作

std::unordered_multiset<Key,Hash,KeyEqual,Allocator>::begin, std::unordered_multiset<Key,Hash,KeyEqual,Allocator>::cbegin

来自 cppreference.cn
 
 
 
 
iterator begin() noexcept;
(1) (since C++11)
const_iterator begin() const noexcept;
(2) (since C++11)
const_iterator cbegin() const noexcept;
(3) (since C++11)

返回指向 unordered_multiset 首元素的迭代器。

如果 unordered_multiset 为空,则返回的迭代器将等于 end()

range-begin-end.svg

目录

[编辑] 返回值

指向首元素的迭代器。

[编辑] 复杂度

常数。

注释

因为 iteratorconst_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); // all count elements have equivalent keys
    }
}

可能的输出

some:   1
words:  2
to:     1
count:  2
these:  1

[编辑] 参见

返回指向末尾的迭代器
(公共成员函数) [编辑]
(C++11)(C++14)
返回指向容器或数组开头的迭代器
(函数模板) [编辑]