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) |
Returns an iterator to the reverse-end of the given container c
or array array
.
c
.c
.c | - | a container with a rend method |
array | - | an array of arbitrary type |
An iterator to the reverse-end of c
or array
.
In addition to being included in <iterator>
, std::rend
and std::crend
are guaranteed to become available if any of the following headers are included: <array>
, <deque>
, <forward_list>
, <list>
, <map>
, <regex>
, <set>
, <string>
, <string_view> (since C++17), <unordered_map>
, <unordered_set>
, and <vector>
.
Custom overloads of rbegin
may be provided for classes that do not expose a suitable rbegin()
member function, yet can be iterated. The following overload is already provided by the standard library:
(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, " ")); }
Output:
Array backwards: 10 9 -3 6 4 Vector backwards: 10 9 -3 6 4
(C++11)(C++14) | returns an iterator to the end of a container or array (function) |
(C++14) | returns a reverse iterator to a container or array (function) |
(C++11)(C++14) | returns an iterator to the beginning of a container or array (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/iterator/rend