std::array<T,N>::rbegin, std::array<T,N>::crbegin
來自 cppreference.com
reverse_iterator rbegin() noexcept; |
(1) | (C++11 起) (自 C++17 起為 constexpr) |
const_reverse_iterator rbegin() const noexcept; |
(2) | (C++11 起) (自 C++17 起為 constexpr) |
const_reverse_iterator crbegin() const noexcept; |
(3) | (C++11 起) (自 C++17 起為 constexpr) |
返回一個指向逆序 array
的第一個元素的逆序迭代器。它對應於非逆序 array
的最後一個元素。如果 array
為空,則返回的迭代器等於 rend()。
目錄 |
[編輯] 返回值
指向第一個元素的逆向迭代器。
[編輯] 複雜度
常數時間。
[編輯] 注意
返回的逆序迭代器的底層迭代器是尾部迭代器。因此,如果尾部迭代器失效,則返回的迭代器也會失效。
[編輯] 示例
執行此程式碼
#include <algorithm> #include <array> #include <iostream> #include <string> #include <string_view> void print(const std::string_view s) { std::cout << s << ' '; } int main() { const std::array<std::string_view, 8> data { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }; std::array<std::string, 8> arr; std::copy(data.cbegin(), data.cend(), arr.begin()); print("Print 'arr' in direct order using [cbegin, cend):\t"); std::for_each(arr.cbegin(), arr.cend(), print); print("\n\nPrint 'arr' in reverse order using [crbegin, crend):\t"); std::for_each(arr.crbegin(), arr.crend(), print); }
輸出
Print 'arr' in direct order using [cbegin, cend): ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ Print 'arr' in reverse order using [crbegin, crend): █ ▇ ▆ ▅ ▄ ▃ ▂ ▁
[編輯] 參閱
返回指向末尾的逆向迭代器 (公共成員函式) | |
(C++14) |
返回指向容器或陣列開頭的反向迭代器 (函式模板) |