std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::rbegin, std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::crbegin
來自 cppreference.com
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"} }; // initializer entries in name alphabetical order std::cout << "US coins in circulation, largest to smallest denomination:\n"; for (auto it = coins.crbegin(); it != coins.crend(); ++it) std::cout << std::setw(11) << it->second << " = ¢" << it->first << '\n'; }
輸出
US coins in circulation, largest to smallest denomination: dollar = ¢100 half dollar = ¢50 quarter = ¢25 dime = ¢10 nickel = ¢5 penny = ¢1
[編輯] 參閱
返回指向末尾的逆向迭代器 (公共成員函式) | |
(C++14) |
返回指向容器或陣列開頭的反向迭代器 (函式模板) |