std::multiset<Key,Compare,Allocator>::end, std::multiset<Key,Compare,Allocator>::cend

< cpp‎ | container‎ | multiset

iterator end();
(C++11 前)
iterator end() noexcept;
(C++11 起)
const_iterator end() const;
(C++11 前)
const_iterator end() const noexcept;
(C++11 起)
const_iterator cend() const noexcept;
(C++11 起)

返回指向 multiset 末元素后一元素的迭代器。

此元素表现为占位符;试图访问它导致未定义行为。

range-begin-end.svg

参数

(无)

返回值

指向后随最后元素的迭代器。

复杂度

常数。

注意

因为 iteratorconst_iterator 都是常迭代器(而且实际上可以是同一类型),故不可能通过任何这些成员函数返回的迭代器修改容器元素。

示例

#include <iostream>
#include <iterator>
#include <set>
#include <string>
 
int main()
{
    const std::multiset<std::string> words = {
        "some", "not", "sorted", "words",
        "will", "come", "out", "sorted",
    };
 
    for (auto it = words.begin(); it != words.end(); ) {
        auto cnt = words.count(*it);
        std::cout << *it << ":\t" << cnt << '\n';
        std::advance(it, cnt); // 所有元素均拥有等价的键
    }
}

输出:

come:	1
not:	1
out:	1
some:	1
sorted:	2
will:	1
words:	1

参阅

返回指向起始的迭代器
(公开成员函数)