std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::rbegin, std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::crbegin
来自 cppreference.cn
< cpp | container | flat multimap
reverse_iterator rbegin() noexcept; |
(1) | (since C++23) |
const_reverse_iterator rbegin() const noexcept; |
(2) | (since C++23) |
const_reverse_iterator crbegin() const noexcept; |
(3) | (since C++23) |
返回指向反向 flat_multimap
的首个元素的逆向迭代器。它对应于非反向 flat_multimap
的最后一个元素。如果 flat_multimap
为空,则返回的迭代器等于 rend()。
内容 |
[编辑] 返回值
指向首个元素的逆向迭代器。
[编辑] 复杂度
常数复杂度。
[编辑] 注释
返回的逆向迭代器的底层迭代器是end 迭代器。因此,如果 end 迭代器失效,则返回的迭代器也会失效。
[编辑] 示例
运行此代码
#include <algorithm> #include <iostream> #include <string> #include <flat_map> int main() { std::flat_multimap<std::string, int> map { {"█", 1}, {"▒", 5}, {"░", 3}, {"▓", 7}, {"▓", 8}, {"░", 4}, {"▒", 6}, {"█", 2} }; std::cout << "Print out in reverse order using const reverse iterators:\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; // OK: non-const value is modifiable // map.crbegin()->second = 42; // Error: cannot modify the const value }
可能的输出
Print out in reverse order using const reverse iterators: { "▓", 8 }; { "▓", 7 }; { "▒", 6 }; { "▒", 5 }; { "░", 4 }; { "░", 3 }; { "█", 2 }; { "█", 1 };
[编辑] 参见
返回指向末尾的逆向迭代器 (public member function) | |
(C++14) |
返回指向容器或数组开头的逆向迭代器 (function template) |