std::array<T,N>::rend, std::array<T,N>::crend
来自cppreference.com
<tbody>
</tbody>
reverse_iterator rend() noexcept; |
(1) | (C++11 起) (C++17 起为 constexpr) |
const_reverse_iterator rend() const noexcept; |
(2) | (C++11 起) (C++17 起为 constexpr) |
const_reverse_iterator crend() const noexcept; |
(3) | (C++11 起) (C++17 起为 constexpr) |
返回指向逆向的 array 末元素后一元素的逆向迭代器。它对应非逆向 array 首元素的前一元素。此元素表现为占位符,试图访问它导致未定义行为。
返回值
指向末元素后一元素的逆向迭代器。
复杂度
常数。
示例
运行此代码
#include <algorithm>
#include <iostream>
#include <array>
int main()
{
std::array<int, 11> a{1, 11, 11, 35, 0, 12, 79, 76, 76, 69, 40};
// 使用 const_reverse_iterator 以逆序打印容器的元素
std::for_each(a.crbegin(), a.crend(), [](int e){ std::cout << e << ' '; });
std::cout << '\n';
// 使用非 const 的 reverse_iterator 修改容器的各个元素
std::for_each(a.rbegin(), a.rend(), [](int& e){ e += 32; });
// 使用 const_reverse_iterator 以逆序将各个元素作为 char 打印
std::for_each(a.crbegin(), a.crend(), [](char e){ std::cout << e; });
std::cout << '\n';
}
输出:
40 69 76 76 79 12 0 35 11 11 1
Hello, C++!
参阅
| 返回指向起始的逆向迭代器 (公开成员函数) | |
(C++14) |
返回容器或数组的逆向尾迭代器 (函数模板) |