std::rend
Defined in header <iterator> | | |
|---|---|---|
| (1) | |
template< class C > auto rend( C& c ) -> decltype(c.rend()); | (since C++14) (until C++17) | |
template< class C > constexpr auto rend( C& c ) -> decltype(c.rend()); | (since C++17) | |
| (1) | |
template< class C > auto rend( const C& c ) -> decltype(c.rend()); | (since C++14) (until C++17) | |
template< class C > constexpr auto rend( const C& c ) -> decltype(c.rend()); | (since C++17) | |
| (2) | |
template< class T, size_t N > reverse_iterator<T*> rend( T (&array)N ); | (since C++14) (until C++17) | |
template< class T, size_t N > constexpr reverse_iterator<T*> rend( T (&array)N ); | (since C++17) | |
| (3) | |
template< class C > auto crend( const C& c ) -> decltype(std::rend(c)); | (since C++14) (until C++17) | |
template< class C > constexpr auto crend( const C& c ) -> decltype(std::rend(c)); | (since C++17) |
将迭代器返回到给定容器的反向端。c或阵列array...
1%29将可能的const限定迭代器返回到容器的反向端。c...
2%29std::reverse_iterator<T*>到数组的相反端。array...
3%29向容器的相反端返回一个const限定迭代器。c...
参数
c | - | a container with a rend method |
|---|---|---|
array | - | an array of arbitrary type |
返回值
的反向结束的迭代器。c或array...
注记
除了被纳入<iterator>,,,std::rend和std::crend如果包括下列任何一个标头,则保证可用:<array>,,,<deque>,,,<forward_list>,,,<list>,,,<map>,,,<regex>,,,<set>,,,<string>,<字符串[医]自C++17%29以来,视图>%28,<unordered_map>,,,<unordered_set>,和<vector>...
过载
自定义超载rbegin可以为不公开合适的类提供rbegin()成员函数,但可以迭代。标准库已经提供了以下重载:
rend(std::initializer_list) (C++14) | specializes std::rend (function) |
|---|
例
二次
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
int main()
{
int a[] = {4, 6, -3, 9, 10};
std::cout << "Array backwards: ";
std::copy(std::rbegin(a), std::rend(a), std::ostream_iterator<int>(std::cout, " "));
std::cout << "\nVector backwards: ";
std::vector<int> v = {4, 6, -3, 9, 10};
std::copy(std::rbegin(v), std::rend(v), std::ostream_iterator<int>(std::cout, " "));
}二次
产出:
二次
Array backwards: 10 9 -3 6 4
Vector backwards: 10 9 -3 6 4二次
另见
endcend (C++11)(C++14) | returns an iterator to the end of a container or array (function) |
|---|---|
rbegincrbegin (C++14) | returns a reverse iterator to a container or array (function) |
begincbegin (C++11)(C++14) | returns an iterator to the beginning of a container or array (function) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

