std::multimap<Key,T,Compare,Allocator>::rbegin, std::multimap<Key,T,Compare,Allocator>::crbegin
來自 cppreference.com
reverse_iterator rbegin(); |
(1) | (C++11 起無異常丟擲) |
const_reverse_iterator rbegin() const; |
(2) | (C++11 起無異常丟擲) |
const_reverse_iterator crbegin() const noexcept; |
(3) | (C++11 起) |
返回指向反向 multimap
中首元素的逆向迭代器。它對應於非反向 multimap
中的末元素。若 multimap
為空,則返回的迭代器等於 rend()。
目錄 |
[編輯] 返回值
指向第一個元素的逆向迭代器。
[編輯] 複雜度
常數時間。
[編輯] 注意
返回的逆向迭代器的底層迭代器是尾後迭代器。因此,如果尾後迭代器失效,返回的迭代器也會失效。
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 << "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++11 起) |
返回指向末尾的逆向迭代器 (public 成員函式) |
(C++14) |
返回指向容器或陣列開頭的反向迭代器 (函式模板) |