Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::rend

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
      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 */
      constexprstd::sentinel_for<

          decltype(ranges::rbegin(std::declval<T>()))>auto rend( T&& t);
      (since C++20)

      Returns a sentinel indicating the end of a reversed range.

      range-rbegin-rend.svg

      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:

      1. decay-copy(t.rend())(until C++23)auto(t.rend())(since C++23), if that expression is valid and its type modelsstd::sentinel_for<decltype(ranges::rbegin(std::declval<T>()))>.
      2. Otherwise,decay-copy(rend(t))(until C++23)auto(rend(t))(since C++23), ifT 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.
      3. Otherwise,std::make_reverse_iterator(ranges::begin(t)) if bothranges::begin(t) andranges::end(t) are valid expressions, have the same type, and that type modelsstd::bidirectional_iterator.

      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

      Customization point objects

      The nameranges::rend denotes acustomization point object, which is a constfunction object of aliteralsemiregular class type. SeeCustomizationPointObject for details.

      [edit]Notes

      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.

      [edit]Example

      Run this code
      #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!

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      P2602R2C++20there's machinery to prohibit certain non-memberrend found byADLremoved such machinery

      [edit]See also

      returns a reverse end iterator to a read-only range
      (customization point object)[edit]
      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]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/rend&oldid=158243"

      [8]ページ先頭

      ©2009-2025 Movatter.jp