命名空间
变体
操作

std::multiset<Key,Compare,Allocator>::rbegin, std::multiset<Key,Compare,Allocator>::crbegin

来自 cppreference.cn
< cpp‎ | 容器‎ | multiset
 
 
 
 
reverse_iterator rbegin();
(1) (C++11 起无异常抛出)
const_reverse_iterator rbegin() const;
(2) (C++11 起无异常抛出)
const_reverse_iterator crbegin() const noexcept;
(3) (C++11 起)

返回指向倒序 multiset 首元素的逆向迭代器。它对应非倒序 multiset 的末元素。若 multiset 为空,则返回的迭代器等于 rend()

range-rbegin-rend.svg

目录

[编辑] 返回值

指向第一个元素的逆向迭代器。

[编辑] 复杂度

常数时间。

[编辑] 注意

由于 iteratorconst_iterator 都是常量迭代器(实际上可能是同一类型),因此无法通过这些成员函数返回的迭代器修改容器的元素。

返回的逆向迭代器的底层迭代器尾迭代器。因此,当尾迭代器失效时,返回的迭代器也会失效。

libc++ 将 `crbegin()` 向后移植到 C++98 模式。

[编辑] 示例

#include <iostream>
#include <set>
 
int main()
{
    std::multiset<unsigned> rep{1, 2, 3, 4, 1, 2, 3, 4};
 
    for (auto it = rep.crbegin(); it != rep.crend(); ++it)
    {
        for (auto n = *it; n > 0; --n)
            std::cout << "⏼" << ' ';
        std::cout << '\n';
    }
}

输出

⏼ ⏼ ⏼ ⏼
⏼ ⏼ ⏼ ⏼
⏼ ⏼ ⏼
⏼ ⏼ ⏼
⏼ ⏼
⏼ ⏼
⏼
⏼

[编辑] 参阅

(C++11)
返回指向末尾的逆向迭代器
(public member function) [编辑]
返回指向容器或数组开头的反向迭代器
(function template) [编辑]