Namespaces
Variants

std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>:: rbegin, std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>:: crbegin

From cppreference.net

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

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

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

range-rbegin-rend.svg

目录

返回值

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

复杂度

常量。

注释

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

示例

#include <iomanip>
#include <iostream>
#include <string_view>
#include <flat_map>
int main()
{
    const std::flat_map<int, std::string_view> coins
    {
        {10, "dime"},
        {100, "dollar"},
        {50, "half dollar"},
        {5, "nickel"},
        {1, "penny"},
        {25, "quarter"}
    }; // 按名称字母顺序的初始化器条目
    std::cout << "流通中的美国硬币,按面额从大到小排列:\n";
    for (auto it = coins.crbegin(); it != coins.crend(); ++it)
        std::cout << std::setw(11) << it->second << " = ¢" << it->first << '\n';
}

输出:

流通中的美国硬币,按面额从大到小排列:
     dollar = ¢100
half dollar = ¢50
    quarter = ¢25
       dime = ¢10
     nickel = ¢5
      penny = ¢1

参见

返回指向末尾的反向迭代器
(公开成员函数)
返回指向容器或数组起始位置的反向迭代器
(函数模板)