m/w/cpp/concepts/invocable) < const  __counted_fn  & , Args...  > .   

Otherwise, no function call operator of ` ___counted_fn_ ` participates in
overload resolution.

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

` views::counted ` does not check if the range is long enough to provide all
count  elements: use  [ views::  take
](http://en.cppreference.com/w/cpp/ranges/take_view) if that check is
necessary.

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

Run this code

    
    
    #include <iostream>
    #include <ranges>
     
    int main()
    {
        const int a[]{1, 2, 3, 4, 5, 6, 7};
        for (int i : std::[views::counted](http://en.cppreference.com/w/cpp/ranges/counted_view)(a, 3))
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << i << ' ';
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
     
        const auto il = {1, 2, 3, 4, 5};
        for (int i : std::[views::counted](http://en.cppreference.com/w/cpp/ranges/counted_view)(il.begin() + 1, 3))
            [std::cout](http://en.cppreference.com/w/cpp/io/cout) << i << ' ';
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
    }

Output:

    
    
    1 2 3
    2 3 4

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/view_counted&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   
---|---|---|---  
[ P2393R1 ](https://wg21.link/P2393R1) |  C++20  |  implicit conversion from an integer-class type to  [ std::  size_t  ](http://en.cppreference.com/w/cpp/types/size_t) might be invalid  |  made explicit   
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/view_counted&action=edit&section=4 "Edit
section: See also") ]  See also

[ ranges::take_view  views::take  ](/w/cpp/ranges/take_view "cpp/ranges/take view") (C++20)  |  a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") consisting of the first N elements of another [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view")   
(class template)  (range adaptor object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_take_view&action=edit)  
---|---  
[ ranges::subrange  ](/w/cpp/ranges/subrange "cpp/ranges/subrange") (C++20)  |  combines an iterator-sentinel pair into a [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view")   
(class template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_subrange&action=edit)  
[ counted_iterator  ](/w/cpp/iterator/counted_iterator "cpp/iterator/counted iterator") (C++20)  |  iterator adaptor that tracks the distance to the end of the range   
(class template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/iterator/dsc_counted_iterator&action=edit)  
[ ranges::count  ranges::count_if  ](/w/cpp/algorithm/ranges/count "cpp/algorithm/ranges/count") (C++20)  (C++20)  |  returns the number of elements satisfying specific criteria   
(niebloid)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/ranges/dsc_count&action=edit)  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/view_counted&oldid=160989
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/view_counted&oldid=160989)
"

#####  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/view_counted "A list of all wiki pages that link here \[j\]")
  * [ Related changes ](/w/Special:RecentChan