std::array<T,N>::rend, std::array<T,N>::crend
来自 zh.cppreference.net
reverse_iterator rend() noexcept;
|
(1) | (C++11 起) (constexpr 自 C++17 起) |
const_reverse_iterator rend() const noexcept;
|
(2) | (C++11 起) (constexpr 自 C++17 起) |
const_reverse_iterator crend() const noexcept;
|
(3) | (C++11 起) (constexpr 自 C++17 起) |
返回指向逆序容器最后一个元素之后元素的逆向迭代器 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}; // 使用常量反向迭代器以逆序打印容器元素 std::for_each(a.crbegin(), a.crend(), [](int e){ std::cout << e << ' '; }); std::cout << '\n'; // 使用非常量反向迭代器修改容器的每个元素 std::for_each(a.rbegin(), a.rend(), [](int& e){ e += 32; }); // 使用常量反向迭代器以字符形式逆序打印元素 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)
|
返回容器或数组的反向末尾迭代器
(函数模板) |