std::rbegin, std::crbegin
来自cppreference.com
在标头
<array>
定义
|
||
在标头
<deque>
定义
|
||
在标头
<forward_list>
定义
|
||
在标头
<iterator>
定义
|
||
在标头
<list>
定义
|
||
在标头
<map>
定义
|
||
在标头
<regex>
定义
|
||
在标头
<set>
定义
|
||
在标头
<span>
定义
|
(C++20 起)
|
|
在标头
<string>
定义
|
||
在标头
<string_view>
定义
|
(C++17 起)
|
|
在标头
<unordered_map>
定义
|
||
在标头
<unordered_set>
定义
|
||
在标头
<vector>
定义
|
||
(1) | ||
template< class C >
auto rbegin( C& c ) -> decltype(c.rbegin()); |
(C++14 起) (C++17 前) |
|
template< class C >
constexpr auto rbegin( C& c ) -> decltype(c.rbegin()); |
(C++17 起) | |
(1) | ||
template< class C >
auto rbegin( const C& c ) -> decltype(c.rbegin()); |
(C++14 起) (C++17 前) |
|
template< class C >
constexpr auto rbegin( const C& c ) -> decltype(c.rbegin()); |
(C++17 起) | |
(2) | ||
template< class T, std::size_t N >
std::reverse_iterator<T*> rbegin( T (&array)[N] ); |
(C++14 起) (C++17 前) |
|
template< class T, std::size_t N >
constexpr std::reverse_iterator<T*> rbegin( T (&array)[N] ); |
(C++17 起) | |
(3) | ||
template< class T >
std::reverse_iterator<const T*> rbegin( std::initializer_list<T> il ); |
(C++14 起) (C++17 前) |
|
template< class T >
constexpr std::reverse_iterator<const T*> rbegin(std::initializer_list<T> il); |
(C++17 起) | |
(4) | ||
template< class C >
auto crbegin( const C& c ) -> decltype(std::rbegin(c)); |
(C++14 起) (C++17 前) |
|
template< class C >
constexpr auto crbegin( const C& c ) -> decltype(std::rbegin(c)); |
(C++17 起) | |
返回指向给定范围逆向起始的迭代器。
1) 返回指向可能有 const 限定的容器或视图
c
逆向起始的迭代器。
3) 返回指向 const 限定的容器或视图
c
逆向起始的迭代器。
参数
c | - | 拥有 rbegin 方法的容器
|
array | - | 任意类型的数组 |
il | - | initializer_list
|
返回值
1) c.rbegin()
2) std::reverse_iterator<T*>(array + N)
3) std::reverse_iterator<const T*>(il.end())
4) c.rbegin()
异常
可能会抛出由实现定义的异常。
重载
可以为未暴露适合的 rbegin()
成员函数的类或枚举提供 rbegin
的自定义重载,使之亦能迭代。
实参依赖查找所找到的
|
(C++20 起) |
注解
需要对 std::initializer_list 的重载,因为它无成员函数
rbegin
。
示例
运行此代码
#include <iostream> #include <vector> #include <iterator> int main() { std::vector<int> v = { 3, 1, 4 }; auto vi = std::rbegin(v); std::cout << *vi << '\n'; int a[] = { -5, 10, 15 }; auto ai = std::rbegin(a); std::cout << *ai << '\n'; auto il = { 3, 1, 4 }; for (auto it = std::rbegin(il); it != std::rend(il); ++it) std::cout << *it << ' '; }
输出:
4 15 4 1 3
参阅
(C++11)(C++14)
|
返回指向容器或数组起始的迭代器 (函数模板) |
(C++11)(C++14)
|
返回指向容器或数组结尾的迭代器 (函数模板) |
(C++14)
|
返回容器或数组的逆向尾迭代器 (函数模板) |
(C++20)
|
返回指向范围的逆向迭代器 (定制点对象) |
(C++20)
|
返回指向只读范围的逆向迭代器 (定制点对象) |