/cpp/ranges/borrowed_range) < View  > ;  |  |  (since C++23)   
---|---|---  
|  |   
  
This specialization of [ ` std::ranges::enable_borrowed_range `
](/w/cpp/ranges/borrowed_range "cpp/ranges/borrowed range") makes `
enumerate_view ` satisfy [ ` borrowed_range ` ](/w/cpp/ranges/borrowed_range
"cpp/ranges/borrowed range") when the underlying view satisfies it.

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

[ Feature-test ](/w/cpp/utility/feature_test "cpp/utility/feature test") macro  |  Value  |  Std  |  Feature   
---|---|---|---  
[ ` __cpp_lib_ranges_enumerate ` ](/w/cpp/feature_test#cpp_lib_ranges_enumerate "cpp/feature test") |  202302L  |  (C++23)  |  ` std::ranges::enumerate_view `  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/enumerate_view&action=edit&section=7 "Edit
section: Example") ]  Example

Run this code

    
    
    #include <iostream>
    #include <map>
    #include <ranges>
    #include <vector>
     
    int main()
    {
        constexpr static auto v = {'A', 'B', 'C', 'D'};
     
        for (auto const [index, letter] : std::views::enumerate(v))
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '(' << index << ':' << letter << ") ";
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
     
    #if __cpp_lib_ranges_to_container
        // create a map using the position of each element as key
        auto m = v | std::views::enumerate | std::[ranges::to](http://en.cppreference.com/w/cpp/ranges/to)<[std::map](http://en.cppreference.com/w/cpp/container/map)>();
     
        for (auto const [key, value] : m)
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '[' << key << "]:" << value << ' ';
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
    #endif
     
        [std::vector](http://en.cppreference.com/w/cpp/container/vector)<int> numbers{1, 3, 5, 7};
     
        // num is mutable even with const, which does not propagate to reference
        // to make it const, use `std::views::enumerate(numbers) | std::views::as_const`
        // or `std::views::enumerate(std::as_const(numbers))`
        for (auto const [index, num] : std::views::enumerate(numbers))
        {
            ++num; // the type is int&
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << numbers[index] << ' ';
        }
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
    }

Possible output:

    
    
    (0:A) (1:B) (2:C) (3:D)
    [0]:A [1]:B [2]:C [3]:D
    2 4 6 8

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

  * C++23 standard (ISO/IEC 14882:2023): 

    

  * 26.7.23 Enumerate view [range.enumerate] 

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

[ ranges::iota_view  views::iota  ](/w/cpp/ranges/iota_view "cpp/ranges/iota view") (C++20)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") consisting of a sequence generated by repeatedly incrementing an initial value   
(class template)  (customization point object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_iota_view&action=edit)  
---|---  
[ ranges::zip_view  views::zip  ](/w/cpp/ranges/zip_view "cpp/ranges/zip view") (C++23)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") consisting of tuples of references to corresponding elements of the adapted views   
(class template)  (customization point object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_zip_view&action=edit)  
[ ranges::elements_view  views::elements  ](/w/cpp/ranges/elements_view "cpp/ranges/elements view") (C++20)  |  takes a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") consisting of [ ` _tuple-like_ ` ](/w/cpp/utility/tuple/tuple-like "cpp/utility/tup