std::multimap<Key,T,Compare,Allocator>:: rbegin, std::multimap<Key,T,Compare,Allocator>:: crbegin
From cppreference.net
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::multimap
| Member functions | |||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
| Deduction guides (C++17) | |||||||||||||||||||||||||||
|
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() 。
目录 |
返回值
指向首个元素的逆向迭代器。
复杂度
常量。
注释
返回的反向迭代器的 底层迭代器 是 end迭代器 。因此当end迭代器失效时,返回的迭代器也会同时失效。
libc++ 向后移植
crbegin()
至 C++98 模式。
示例
运行此代码
#include <algorithm> #include <iostream> #include <string> #include <map> int main() { std::multimap<std::string, int> map { {"█", 1}, {"▒", 5}, {"░", 3}, {"▓", 7}, {"▓", 8}, {"░", 4}, {"▒", 6}, {"█", 2} }; std::cout << "使用常量反向迭代器按逆序输出:\n"; std::for_each(map.crbegin(), map.crend(), [](std::pair<const std::string, int> const& e) { std::cout << "{ \"" << e.first << "\", " << e.second << " };\n"; }); map.rbegin()->second = 42; // 正确:非常量值可修改 // map.crbegin()->second = 42; // 错误:无法修改常量值 }
可能的输出:
使用常量反向迭代器按逆序输出:
{ "▓", 8 };
{ "▓", 7 };
{ "▒", 6 };
{ "▒", 5 };
{ "░", 4 };
{ "░", 3 };
{ "█", 2 };
{ "█", 1 };
参见
|
(C++11)
|
返回指向末尾的反向迭代器
(公开成员函数) |
|
(C++14)
|
返回指向容器或数组起始位置的反向迭代器
(函数模板) |