命名空间
变体
操作

std::array<T,N>::rend, std::array<T,N>::crend

来自 cppreference.cn
< cpp‎ | container‎ | array
 
 
 
 
reverse_iterator rend() noexcept;
(1) (since C++11)
(constexpr since C++17)
const_reverse_iterator rend() const noexcept;
(2) (since C++11)
(constexpr since C++17)
const_reverse_iterator crend() const noexcept;
(3) (since C++11)
(constexpr since C++17)

返回一个反向迭代器,指向反向 array 的最后一个元素之后的元素。它对应于非反向 array 的第一个元素之前的元素。此元素充当占位符,尝试访问它会导致未定义的行为。

range-rbegin-rend.svg

目录

[edit] 返回值

指向最后一个元素之后元素的反向迭代器。

[edit] 复杂度

常数。

[edit] 示例

#include <algorithm>
#include <iostream>
#include <array>
 
int main()
{
    std::array<int, 11> a{1, 11, 11, 35, 0, 12, 79, 76, 76, 69, 40};
 
    // Print elements of container in reverse order using const_reverse_iterator's.
    std::for_each(a.crbegin(), a.crend(), [](int e){ std::cout << e << ' '; });
    std::cout << '\n';
 
    // Modify each element of container using non-const reverse_iterator's.
    std::for_each(a.rbegin(), a.rend(), [](int& e){ e += 32; });
 
    // Print elements as chars in reverse order using const_reverse_iterator's.
    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++!

[edit] 参见

返回指向开头的反向迭代器
(公共成员函数) [edit]
(C++14)
为容器或数组返回反向结束迭代器
(函数模板) [edit]