std::inplace_vector<T,N>::rbegin, std::inplace_vector<T,N>::crbegin
來自 cppreference.com
< cpp | 容器 | inplace_vector
constexpr reverse_iterator rbegin() noexcept; |
(1) | (C++26 起) |
constexpr const_reverse_iterator rbegin() const noexcept; |
(2) | (C++26 起) |
constexpr const_reverse_iterator crbegin() const noexcept; |
(3) | (C++26 起) |
返回一個反向迭代器,指向反轉後的 inplace_vector
的第一個元素。它對應於未反轉的 inplace_vector
的最後一個元素。如果 inplace_vector
為空,則返回的迭代器等於 rend()。
目錄 |
[編輯] 返回值
指向第一個元素的逆向迭代器。
[編輯] 複雜度
常數時間。
[編輯] 注意
返回的反向迭代器的底層迭代器是end 迭代器。因此,如果 end 迭代器失效,則返回的迭代器也會失效。
[編輯] 示例
執行此程式碼
#include <algorithm> #include <inplace_vector> #include <iostream> #include <string> #include <string_view> void print(const std::string_view s) { std::cout << s << ' '; } int main() { const std::inplace_vector<std::string_view, 8> data { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }; std::inplace_vector<std::string, 8> arr(8); 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): █ ▇ ▆ ▅ ▄ ▃ ▂ ▁
[編輯] 參閱
返回指向末尾的逆向迭代器 (public member function) | |
(C++14) |
返回指向容器或陣列開頭的反向迭代器 (function template) |