cases.

The C++20 standard requires that if the underlying ` begin ` 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/begin&action=edit&section=2
"Edit section: Example") ]  Example

Run this code

    
    
    #include <cassert>
    #include <ranges>
    #include <vector>
     
    int main() 
    {
        [std::vector](http://en.cppreference.com/w/cpp/container/vector) v{3, 1, 4};
        auto vi = std::[ranges::begin](http://en.cppreference.com/w/cpp/ranges-ranges-placeholder/begin)(v);
        auto vci = std::[ranges::cbegin](http://en.cppreference.com/w/cpp/ranges-ranges-placeholder/cbegin)(v);
        [assert](http://en.cppreference.com/w/cpp/error/assert)(*vi == 3 and *vi == *vci);
        ++vi;
        ++vci; // OK: vci is modifiable object
        *vi = 42; // OK: vi points to mutable element
        // *vci = 13; // Error: vci points to immutable element
     
        int a[]{-5, 10, 15};
        auto ai = std::[ranges::begin](http://en.cppreference.com/w/cpp/ranges-ranges-placeholder/begin)(a); // works with C-arrays as well
        [assert](http://en.cppreference.com/w/cpp/error/assert)(*ai == -5);
        *ai = 42; // OK
    }

###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/begin&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 ` begin ` found by [ ADL ](/w/cpp/language/adl "cpp/language/adl") |  removed such machinery   
  
###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/begin&action=edit&section=4
"Edit section: See also") ]  See also

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

#####  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/ranges/begin "A list of all wiki pages that link here \[j\]")
  * [ Related changes ](/w/Special:RecentChangesLinked/cpp/ranges/begin "Recent changes in pages linked from this page \[k\]")
  * [ Upload file ](http://upload.cppreference.com/w/Special:Upload "Upload files \[u\]")
  * [ Special pages ](/w/Special:SpecialPages "A list of all special pages \[q\]")
  * [ Printable version ](/mwiki/index.php?title=cpp/ranges/begin&printable=yes "Printable version of this page \[p\]")
  * [ Permanent link ](/mwiki/index.php?title=cpp/ranges/begin&oldid=158238 "Permanent link to this revision of the page")
  * [ Page information ](/mwiki/index.php?title=cpp/ranges/begin&action=info)

  * In other languages 

  * [ Deutsch ](http://de.cppreference.com/w/cpp/ranges/begin "cpp/ranges/begin")
  * [ Español ](http://es.cppreference.