test") macro  |  Value  |  Std  |  Feature   
---|---|---|---  
[ ` __cpp_lib_ranges_as_const ` ](/w/cpp/feature_test#cpp_lib_ranges_as_const "cpp/feature test") |  202207L  |  (C++23)  |  ` std::ranges::as_const_view ` ,  std::const_iterator   
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/as_const_view&action=edit&section=7 "Edit
section: Example") ]  Example

Run this code

    
    
    #include <cassert>
    #include <ranges>
     
    int main()
    {
        int x[]{1, 2, 3, 4, 5};
     
        auto v1 = x | std::[views::drop](http://en.cppreference.com/w/cpp/ranges/drop_view)(2);
        [assert](http://en.cppreference.com/w/cpp/error/assert)(v1.back() == 5);
        v1[0]++; // OK, can modify non-const element
     
        auto v2 = x | std::[views::drop](http://en.cppreference.com/w/cpp/ranges/drop_view)(2) | std::views::as_const;
        [assert](http://en.cppreference.com/w/cpp/error/assert)(v2.back() == 5);
        // v2[0]++; // Compile-time error, cannot modify read-only element
    }

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/as_const_view&action=edit&section=8 "Edit
section: See also") ]  See also

[ ranges::as_rvalue_view  views::as_rvalue  ](/w/cpp/ranges/as_rvalue_view "cpp/ranges/as rvalue view") (C++23)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") of a sequence that casts each element to an rvalue   
(class template)  (range adaptor object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_as_rvalue_view&action=edit)  
---|---  
[ 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)  
[ ranges::cend  ](/w/cpp/ranges/cend "cpp/ranges/cend") (C++20)  |  returns a sentinel indicating the end of a read-only range   
(customization point object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_cend&action=edit)  
[ as_const  ](/w/cpp/utility/as_const "cpp/utility/as const") (C++17)  |  obtains a reference to  const  to its argument   
(function template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/utility/dsc_as_const&action=edit)  
[ basic_const_iterator  ](/w/cpp/iterator/basic_const_iterator "cpp/iterator/basic const iterator") (C++23)  |  iterator adaptor that converts an iterator into a constant iterator   
(class template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/iterator/dsc_basic_const_iterator&action=edit)  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/as_const_view&oldid=159814
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/as_const_view&oldid=159814)
"

#####  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/as_const_view "A list of all wiki pages that link here \[j\]")
  * [ Related changes ](/w/Special:RecentChangesLinked/cpp/ranges/as_const_view "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/as_const_view&printable=yes "Printable version of this page \[p\]")
  * [ Permanent link ](/mwiki/index.php?title=cpp/ranges/as_const_view&oldid=159814 "Permanent link to this revision of the page")
  * [ Page information ](/mwiki/index.php?title=cpp/ranges/as_const_view&action=info)

  * In other languages 

  * [ Deutsch ](http://de.cppreference.com/w/cpp/ranges/as_const_vie