From cppreference.com
Defined in header
Defined in header
Defined in header
(since C++23)
Defined in header
(since C++23)
Defined in header
Defined in header
(since C++26)
Defined in header
(since C++26)
Defined in header
Defined in header
Defined in header
Defined in header
(since C++26)
Defined in header
Defined in header
Defined in header
(since C++20)
Defined in header
(since C++23)
Defined in header
Defined in header
(since C++17)
Defined in header
Defined in header
Defined in header
Defined in header
template<classC>autorend(C&c)noexcept(noexcept(c.rend()))->decltype(c.rend()); (1)(since C++14)
(constexpr since C++17)template<classC>autorend(constC&c)noexcept(noexcept(c.rend()))->decltype(c.rend()); (2)(since C++14)
(constexpr since C++17)template<classT,std::size_tN>std::reverse_iterator<T*>rend(T(&array)[N])noexcept; (3)(since C++14)
(constexpr since C++17)template<classT>std::reverse_iterator<constT*>rend(std::initializer_list<T>il)noexcept; (4)(since C++14)
(constexpr since C++17)template<classC>autocrend(constC&c)noexcept(noexcept(std::rend(c)))->decltype(std::rend(c)); (5)(since C++14)
(constexpr since C++17)Returns an iterator to the reverse-end of the given range.
1,2) Returns c.rend(), which is typically an iterator one past the reverse-end of the sequence represented by c.
1) If C is a standard
, returns a C::reverse_iterator object.
2) If C is a standard
, returns a C::const_reverse_iterator object.
3) Returns an std::reverse_iterator<T*> object to the reverse-end of array.
4) Returns an std::reverse_iterator<constT*> object to the reverse-end of il.
5) Returns std::end(c), with c always treated as const-qualified.
If C is a standard
, returns a C::const_reverse_iterator object.
Parameters
c - a container or view with a rend member function array - an array of arbitrary type il - an std::initializer_listReturn value
1,2)c.rend()
3)std::reverse_iterator<T*>(array)
4)std::reverse_iterator<constT*>(il.begin())
5)std::rend(c)
Exceptions
1,2) What and when underlying c.rend() call throws.
5) What and when underlying std::rend(c) call throws.
Overloads
Custom overloads of rend may be provided for classes and enumerations that do not expose a suitable rend() member function, yet can be iterated.
Notes
The overload for
is necessary because it does not have a member function rend.
Example
Run this code
#include<algorithm>#include<iostream>#include<iterator>#include<vector>intmain(){inta[]{4,6,-3,9,10};std::cout<<"C-style array `a` backwards: ";std::copy(std::rbegin(a),std::rend(a),std::ostream_iterator<int>(std::cout," "));autoil={3,1,4};std::cout<<"\nstd::initializer_list `il` backwards: ";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` backwards: ";std::copy(std::rbegin(v),std::rend(v),std::ostream_iterator<int>(std::cout," "));std::cout<<'\n';}Output:
C-style array `a` backwards: 10 9 -3 6 4 std::initializer_list `il` backwards: 4 1 3 std::vector `v` backwards: 10 9 -3 6 4 Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++14 std::rend and std::crend were not required to propagate exception specification required See also
(C++11)(C++14)
returns an iterator to the end of a container or array
(function template)
(C++14)
returns a reverse iterator to the beginning of a container or array
(function template)
(C++11)(C++14)
returns an iterator to the beginning of a container or array
(function template)
(C++20)
returns a reverse end iterator to a range
(customization point object)
(C++20)
returns a reverse end iterator to a read-only range
(customization point object)