std::array<T,N>:: rbegin, std::array<T,N>:: crbegin
From cppreference.net
|
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) |
返回指向反转后 * this 首元素的反向迭代器。该元素对应于未反转 * this 的最后一个元素。
如果 * this 为空,返回的迭代器等于 rend() 。
目录 |
返回值
指向第一个元素的反向迭代器。
复杂度
常量。
注释
返回的反向迭代器的 底层迭代器 是 end 迭代器 。因此当 end 迭代器失效时,返回的迭代器也会随之失效。
示例
运行此代码
#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)
|
返回指向容器或数组起始位置的反向迭代器
(函数模板) |