std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::rbegin, std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::crbegin
來自 cppreference.com
< cpp | 容器 | flat_multimap
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_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 };
[編輯] 參閱
返回指向末尾的逆向迭代器 (公共成員函式) | |
(C++14) |
返回指向容器或陣列開頭的反向迭代器 (函式模板) |