std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::rbegin, std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::crbegin
来自cppreference.com
<tbody>
</tbody>
reverse_iterator rbegin() noexcept; |
(1) | (C++23 起) |
const_reverse_iterator rbegin() const noexcept; |
(2) | (C++23 起) |
const_reverse_iterator crbegin() const noexcept; |
(3) | (C++23 起) |
返回指向逆向的 flat_map 的首元素的逆向迭代器。它对应非逆向 flat_map 的末元素。如果 flat_map 为空,那么返回的迭代器等于 rend()。
返回值
指向首元素的逆向迭代器。
复杂度
常数。
注解
返回的逆向迭代器的底层迭代器是尾迭代器。因此在尾迭代器失效时,返回的迭代器也会失效。
示例
运行此代码
#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
参阅
| 返回指向末尾的逆向迭代器 (公开成员函数) | |
(C++14) |
返回指向一个容器或数组的逆向迭代器 (函数模板) |