Namespaces
Variants

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

From cppreference.net

reverse_iterator rbegin ( ) ;
(1) (自 C++11 起为 noexcept)
(自 C++26 起为 constexpr)
const_reverse_iterator rbegin ( ) const ;
(2) (自 C++11 起为 noexcept)
(自 C++26 起为 constexpr)
const_reverse_iterator crbegin ( ) const noexcept ;
(3) (自 C++11 起)
(自 C++26 起为 constexpr)

返回指向反转后 * this 首元素的反向迭代器。该元素对应于未反转 * this 的末元素。

如果 * this 为空,返回的迭代器等于 rend()

range-rbegin-rend.svg

目录

返回值

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

复杂度

常量。

注释

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

返回的反向迭代器的 底层迭代器 end 迭代器 。因此当 end 迭代器失效时,返回的迭代器也会同时失效。

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)
返回指向末尾的反向迭代器
(公开成员函数)
返回指向容器或数组起始位置的反向迭代器
(函数模板)