std::array<T,N>::rbegin, std::array<T,N>::crbegin

来自cppreference.com
< cpp‎ | container‎ | array
reverse_iterator rbegin()noexcept;
(1) (C++11 起)
(C++17 起为 constexpr)
const_reverse_iterator rbegin()constnoexcept;
(2) (C++11 起)
(C++17 起为 constexpr)
const_reverse_iterator crbegin()constnoexcept;
(3) (C++11 起)
(C++17 起为 constexpr)

返回指向逆向的 *this 的首元素的逆向迭代器。它对应非逆向 *this 的末元素。

如果 *this 为空,那么返回的迭代器等于 rend()

range-rbegin-rend.svg

目录

[编辑]返回值

指向首元素的逆向迭代器。

[编辑]复杂度

常数。

[编辑]注解

返回的逆向迭代器的底层迭代器尾迭代器。因此在尾迭代器失效时,返回的迭代器也会失效。

[编辑]示例

#include <algorithm>#include <array>#include <iostream>#include <string>#include <string_view>   void print(conststd::string_view s){std::cout<< s <<' ';}   int main(){conststd::array<std::string_view, 8> data {"▁","▂","▃","▄","▅","▆","▇","█"}std::array<std::string, 8> arr;   std::copy(data.cbegin(), data.cend(), arr.begin());   print("用 [cbegin, cend) 以正序打印 “arr”:\t");std::for_each(arr.cbegin(), arr.cend(), print);   print("\n\n用 [crbegin, crend) 以逆序打印 “arr”:\t");std::for_each(arr.crbegin(), arr.crend(), print);}

输出:

用 [cbegin, cend) 以正序打印 “arr”: ▁ ▂ ▃ ▄ ▅ ▆ ▇ █   用 [crbegin, crend) 以逆序打印 “arr”: █ ▇ ▆ ▅ ▄ ▃ ▂ ▁

[编辑]参阅

返回指向末尾的逆向迭代器
(公开成员函数)[编辑]
返回指向一个容器或数组的逆向迭代器
(函数模板)[编辑]
close