_rbegin_fn_ ` participates in
overload resolution.

###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/rbegin&action=edit&section=1
"Edit section: Notes") ]  Notes

If the argument is an rvalue (i.e. ` T ` is an object type) and  [ ranges::
enable_borrowed_range
](http://en.cppreference.com/w/cpp/ranges/borrowed_range) < [ std::
remove_cv_t  ](http://en.cppreference.com/w/cpp/types/remove_cv) < T  >> is
false  , the call to ` ranges::rbegin ` is ill-formed, which also results in
substitution failure.

The return type models  [ std::input_or_output_iterator
](/w/cpp/iterator/input_or_output_iterator "cpp/iterator/input or output
iterator") in all cases.

The C++20 standard requires that if the underlying ` rbegin ` 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 proposal [ P0849R8
](https://wg21.link/P0849R8) to match the implementations.

###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/rbegin&action=edit&section=2
"Edit section: Example") ]  Example

Run this code

    
    
    #include <iostream>
    #include <ranges>
    #include <span>
    #include <vector>
     
    int main()
    {
        [std::vector](http://en.cppreference.com/w/cpp/container/vector)<int> v = {3, 1, 4};
        auto vi = std::ranges::rbegin(v);
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << *vi << '\n';
        *vi = 42; // OK
     
        int a[] = {-5, 10, 15};
        auto ai = std::ranges::rbegin(a);
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << *ai << '\n';
        *ai = 42; // OK
     
        // auto x_x = std::ranges::rbegin(std::vector{6, 6, 6});
        // ill-formed: the argument is an rvalue (see Notes ↑)
     
        auto si = std::ranges::rbegin([std::span](http://en.cppreference.com/w/cpp/container/span){a}); // OK
        static_assert(std::[ranges::enable_borrowed_range](http://en.cppreference.com/w/cpp/ranges/borrowed_range)<
            [std::remove_cv_t](http://en.cppreference.com/w/cpp/types/remove_cv)<decltype([std::span](http://en.cppreference.com/w/cpp/container/span){a})>>);
        *si = 42; // OK
    }

Output:

    
    
    4
    15

###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/rbegin&action=edit&section=3
"Edit section: Defect reports") ]  Defect reports

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

DR  |  Applied to  |  Behavior as published  |  Correct behavior   
---|---|---|---  
[ P2602R2 ](https://wg21.link/P2602R2) |  C++20  |  there's machinery to prohibit certain non-member ` rbegin ` found by [ ADL ](/w/cpp/language/adl "cpp/language/adl") |  removed such machinery   
  
###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/rbegin&action=edit&section=4
"Edit section: See also") ]  See also

[ ranges::crbegin  ](/w/cpp/ranges/crbegin "cpp/ranges/crbegin") (C++20)  |  returns a reverse iterator to a read-only range   
(customization point object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_crbegin&action=edit)  
---|---  
[ rbegin  crbegin  ](/w/cpp/iterator/rbegin "cpp/iterator/rbegin") (C++14)  |  returns a reverse iterator to the beginning of a container or array   
(function template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/iterator/dsc_rbegin&action=edit)  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/rbegin&oldid=158242
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/rbegin&oldid=158242)
"

#####  Navigation

  * [ Support us ](http://www.cppreference.com/support)
  * [ Recent changes ](/w/Special:RecentChanges "A list of recent changes in the wiki \[r\]")
  * [ FAQ ](/w/Cppreference:FAQ)
  * [ Offline version ](/w/Cppreference:Archives)

#####  Toolbox

  * [ What links here ](/w/Special:WhatLinksHere/cpp/ran