|
Range primitives | |||||||
|
Range concepts | |||||||||||||||||||
|
Range factories | |||||||||
|
Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Helper items | |||||||||||||||||
|
Defined in header <ranges> | ||
Defined in header <iterator> | ||
inlinenamespace/* unspecified */{ inlineconstexpr/* unspecified */ rend=/* unspecified */; | (since C++20) (customization point object) | |
Call signature | ||
template<class T> requires/* see below */ | (since C++20) | |
Returns a sentinel indicating the end of a reversed range.
IfT
is an array type andstd::remove_all_extents_t<std::remove_reference_t<T>> is incomplete, then the call toranges::rend
is ill-formed, no diagnostic required.
If the argument is an lvalue orranges::enable_borrowed_range<std::remove_cv_t<T>> istrue, then a call toranges::rend
isexpression-equivalent to:
T
is a class or enumeration type, that expression is valid and its type modelsstd::sentinel_for<decltype(ranges::rbegin(std::declval<T>()))>, where the meaning ofrend
is established as if by performingargument-dependent lookup only.In all other cases, a call toranges::rend
is ill-formed, which can result insubstitution failure whenranges::rend(t) appears in the immediate context of a template instantiation.
Contents |
The nameranges::rend
denotes acustomization point object, which is a constfunction object of aliteralsemiregular
class type. SeeCustomizationPointObject for details.
If the argument is an rvalue (i.e.T
is an object type) andranges::enable_borrowed_range<std::remove_cv_t<T>> isfalse, or if it is of an array type of unknown bound, the call toranges::rend
is ill-formed, which also results in substitution failure.
Ifranges::rend(std::forward<T>(t)) is valid, thendecltype(ranges::rend(std::forward<T>(t))) anddecltype(ranges::begin(std::forward<T>(t))) modelstd::sentinel_for in all cases, whileT
modelsstd::ranges::range.
The C++20 standard requires that if the underlyingrend
function call returns a prvalue, the return value is move-constructed from the materialized temporary object. All implementations directly return the prvalue instead. The requirement is corrected by the post-C++20 proposalP0849R8 to match the implementations.
#include <algorithm>#include <iostream>#include <ranges>#include <vector> int main(){std::vector<int> v={3,1,4};namespace ranges= std::ranges;if(ranges::find(ranges::rbegin(v), ranges::rend(v),5)!= ranges::rend(v))std::cout<<"found a 5 in vector v!\n"; int a[]={5,10,15};if(ranges::find(ranges::rbegin(a), ranges::rend(a),5)!= ranges::rend(a))std::cout<<"found a 5 in array a!\n";}
Output:
found a 5 in array a!
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
P2602R2 | C++20 | there's machinery to prohibit certain non-memberrend found byADL | removed such machinery |
(C++20) | returns a reverse end iterator to a read-only range (customization point object)[edit] |
(C++20) | returns a reverse iterator to a range (customization point object)[edit] |
(C++14) | returns a reverse end iterator for a container or array (function template)[edit] |