std::rend, std::crend
来自cppreference.com
在标头 <array> 定义
|
||
在标头 <deque> 定义
|
||
在标头 <flat_map> 定义
|
||
在标头 <flat_set> 定义
|
||
在标头 <forward_list> 定义
|
||
在标头 <inplace_vector> 定义
|
||
在标头 <iterator> 定义
|
||
在标头 <list> 定义
|
||
在标头 <map> 定义
|
||
在标头 <regex> 定义
|
||
在标头 <set> 定义
|
||
在标头 <span> 定义
|
||
在标头 <string> 定义
|
||
在标头 <string_view> 定义
|
||
在标头 <unordered_map> 定义
|
||
在标头 <unordered_set> 定义
|
||
在标头 <vector> 定义
|
||
template< class C > auto rend( C& c ) -> decltype(c.rend()); |
(1) | (C++14 起) (C++17 起为 constexpr ) |
template< class C > auto rend( const C& c ) -> decltype(c.rend()); |
(2) | (C++14 起) (C++17 起为 constexpr ) |
template< class T, std::size_t N > std::reverse_iterator<T*> rend( T (&array)[N] ); |
(3) | (C++14 起) (C++17 起为 constexpr ) |
template< class T > std::reverse_iterator<const T*> rend( std::initializer_list<T> il ); |
(4) | (C++14 起) (C++17 起为 constexpr ) |
template< class C > auto crend( const C& c ) -> decltype(std::rend(c)); |
(5) | (C++14 起) (C++17 起为 constexpr ) |
返回值向给定范围的逆向结尾的迭代器。
1,2) 返回 c.rend(),通常是指向 c 所代表的逆序序列末尾后一位置的迭代器。
5) 返回 std::rend(c),这里 c 始终当做 const 限定。
目录 |
[编辑] 参数
c | - | 拥有 rend 成员函数的容器或视图
|
array | - | 任意类型的数组 |
il | - | std::initializer_list |
[编辑] 返回值
1,2) c.rend()
3) std::reverse_iterator<T*>(array)
4) std::reverse_iterator<const T*>(il.begin())
5) c.rend()
[编辑] 异常
可能会抛出由实现定义的异常。
[编辑] 重载
可对未暴露适合的 rend()
成员函数的类或枚举提供 rend
的定制重载,从而能迭代它们。
实参依赖查找找到的 |
(C++20 起) |
[编辑] 注解
需要针对 std::initializer_list 的重载,因为它没有成员函数 rend
。
[编辑] 示例
运行此代码
#include <algorithm> #include <iostream> #include <iterator> #include <vector> int main() { int a[]{4, 6, -3, 9, 10}; std::cout << "C 风格数组 `a` 逆序:"; std::copy(std::rbegin(a), std::rend(a), std::ostream_iterator<int>(std::cout, " ")); auto il = {3, 1, 4}; std::cout << "\nstd::initializer_list `il` 逆序:"; std::copy(std::rbegin(il), std::rend(il), std::ostream_iterator<int>(std::cout, " ")); std::vector<int> v{4, 6, -3, 9, 10}; std::cout << "\nstd::vector `v` 逆序:"; std::copy(std::rbegin(v), std::rend(v), std::ostream_iterator<int>(std::cout, " ")); std::cout << '\n'; }
输出:
C 风格数组 `a` 逆序:10 9 -3 6 4 std::initializer_list `il` 逆序:4 1 3 std::vector `v` 逆序:10 9 -3 6 4
[编辑] 参阅
(C++11)(C++14) |
返回指向容器或数组结尾的迭代器 (函数模板) |
(C++14) |
返回指向一个容器或数组的逆向迭代器 (函数模板) |
(C++11)(C++14) |
返回指向容器或数组起始的迭代器 (函数模板) |
(C++20) |
返回指向范围的逆向尾迭代器 (定制点对象) |
(C++20) |
返回指向只读范围的逆向尾迭代器 (定制点对象) |